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
signature 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...@@ -1017,7 +1017,6 @@ fn tokenizeAndPrint(docgen_tokenizer: *Tokenizer, out: anytype, source_token: To
1017}1017}
10181018
1019fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: anytype, zig_exe: []const u8, do_code_tests: bool) !void {1019fn 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;
1021 var progress = Progress{};1020 var progress = Progress{};
1022 const root_node = try progress.start("Generating docgen examples", toc.nodes.len);1021 const root_node = try progress.start("Generating docgen examples", toc.nodes.len);
1023 defer root_node.end();1022 defer root_node.end();
...@@ -1090,7 +1089,6 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any...@@ -1090,7 +1089,6 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
10901089
1091 switch (code.id) {1090 switch (code.id) {
1092 Code.Id.Exe => |expected_outcome| code_block: {1091 Code.Id.Exe => |expected_outcome| code_block: {
1093 const name_plus_bin_ext = try std.fmt.allocPrint(allocator, "{s}{s}", .{ code.name, exe_ext });
1094 var build_args = std.ArrayList([]const u8).init(allocator);1092 var build_args = std.ArrayList([]const u8).init(allocator);
1095 defer build_args.deinit();1093 defer build_args.deinit();
1096 try build_args.appendSlice(&[_][]const u8{1094 try build_args.appendSlice(&[_][]const u8{
...@@ -1361,19 +1359,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any...@@ -1361,19 +1359,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
1361 },1359 },
1362 Code.Id.Obj => |maybe_error_match| {1360 Code.Id.Obj => |maybe_error_match| {
1363 const name_plus_obj_ext = try std.fmt.allocPrint(allocator, "{s}{s}", .{ code.name, obj_ext });1361 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 );
1368 var build_args = std.ArrayList([]const u8).init(allocator);1362 var build_args = std.ArrayList([]const u8).init(allocator);
1369 defer build_args.deinit();1363 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
1377 try build_args.appendSlice(&[_][]const u8{1365 try build_args.appendSlice(&[_][]const u8{
1378 zig_exe,1366 zig_exe,
1379 "build-obj",1367 "build-obj",
lib/std/Progress.zig+1-1
...@@ -295,7 +295,7 @@ fn refreshWithHeldLock(self: *Progress) void {...@@ -295,7 +295,7 @@ fn refreshWithHeldLock(self: *Progress) void {
295 end += 1;295 end += 1;
296 }296 }
297297
298 _ = file.write(self.output_buffer[0..end]) catch |e| {298 _ = file.write(self.output_buffer[0..end]) catch {
299 // Stop trying to write to this file once it errors.299 // Stop trying to write to this file once it errors.
300 self.terminal = null;300 self.terminal = null;
301 };301 };
lib/std/SemanticVersion.zig+2-1
...@@ -162,6 +162,7 @@ pub fn format(...@@ -162,6 +162,7 @@ pub fn format(
162 options: std.fmt.FormatOptions,162 options: std.fmt.FormatOptions,
163 out_stream: anytype,163 out_stream: anytype,
164) !void {164) !void {
165 _ = options;
165 if (fmt.len != 0) @compileError("Unknown format string: '" ++ fmt ++ "'");166 if (fmt.len != 0) @compileError("Unknown format string: '" ++ fmt ++ "'");
166 try std.fmt.format(out_stream, "{d}.{d}.{d}", .{ self.major, self.minor, self.patch });167 try std.fmt.format(out_stream, "{d}.{d}.{d}", .{ self.major, self.minor, self.patch });
167 if (self.pre) |pre| try std.fmt.format(out_stream, "-{s}", .{pre});168 if (self.pre) |pre| try std.fmt.format(out_stream, "-{s}", .{pre});
...@@ -259,7 +260,7 @@ test "SemanticVersion format" {...@@ -259,7 +260,7 @@ test "SemanticVersion format" {
259260
260 // Invalid version string that may overflow.261 // Invalid version string that may overflow.
261 const big_invalid = "99999999999999999999999.999999999999999999.99999999999999999----RC-SNAPSHOT.12.09.1--------------------------------..12";262 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 |_| {}
263}264}
264265
265test "SemanticVersion precedence" {266test "SemanticVersion precedence" {
lib/std/Thread.zig+2-2
...@@ -518,8 +518,8 @@ pub fn cpuCount() CpuCountError!usize {...@@ -518,8 +518,8 @@ pub fn cpuCount() CpuCountError!usize {
518 },518 },
519 .haiku => {519 .haiku => {
520 var count: u32 = undefined;520 var count: u32 = undefined;
521 var system_info: os.system_info = undefined;521 // var system_info: os.system_info = undefined;
522 const rc = os.system.get_system_info(&system_info);522 // const rc = os.system.get_system_info(&system_info);
523 count = system_info.cpu_count;523 count = system_info.cpu_count;
524 return @intCast(usize, count);524 return @intCast(usize, count);
525 },525 },
lib/std/Thread/Condition.zig+8-2
...@@ -40,12 +40,18 @@ else...@@ -40,12 +40,18 @@ else
4040
41pub const SingleThreadedCondition = struct {41pub const SingleThreadedCondition = struct {
42 pub fn wait(cond: *SingleThreadedCondition, mutex: *Mutex) void {42 pub fn wait(cond: *SingleThreadedCondition, mutex: *Mutex) void {
43 _ = cond;
44 _ = mutex;
43 unreachable; // deadlock detected45 unreachable; // deadlock detected
44 }46 }
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 }
49};55};
5056
51pub const WindowsCondition = struct {57pub const WindowsCondition = struct {
lib/std/Thread/StaticResetEvent.zig+6-1
...@@ -105,6 +105,7 @@ pub const DebugEvent = struct {...@@ -105,6 +105,7 @@ pub const DebugEvent = struct {
105 }105 }
106106
107 pub fn timedWait(ev: *DebugEvent, timeout: u64) TimedWaitResult {107 pub fn timedWait(ev: *DebugEvent, timeout: u64) TimedWaitResult {
108 _ = timeout;
108 switch (ev.state) {109 switch (ev.state) {
109 .unset => return .timed_out,110 .unset => return .timed_out,
110 .set => return .event_set,111 .set => return .event_set,
...@@ -174,7 +175,10 @@ pub const AtomicEvent = struct {...@@ -174,7 +175,10 @@ pub const AtomicEvent = struct {
174 };175 };
175176
176 pub const SpinFutex = struct {177 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
179 fn wait(waiters: *u32, timeout: ?u64) !void {183 fn wait(waiters: *u32, timeout: ?u64) !void {
180 var timer: time.Timer = undefined;184 var timer: time.Timer = undefined;
...@@ -193,6 +197,7 @@ pub const AtomicEvent = struct {...@@ -193,6 +197,7 @@ pub const AtomicEvent = struct {
193197
194 pub const LinuxFutex = struct {198 pub const LinuxFutex = struct {
195 fn wake(waiters: *u32, wake_count: u32) void {199 fn wake(waiters: *u32, wake_count: u32) void {
200 _ = wake_count;
196 const waiting = std.math.maxInt(i32); // wake_count201 const waiting = std.math.maxInt(i32); // wake_count
197 const ptr = @ptrCast(*const i32, waiters);202 const ptr = @ptrCast(*const i32, waiters);
198 const rc = linux.futex_wake(ptr, linux.FUTEX_WAKE | linux.FUTEX_PRIVATE_FLAG, waiting);203 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 {...@@ -40,9 +40,11 @@ pub fn StringArrayHashMapUnmanaged(comptime V: type) type {
4040
41pub const StringContext = struct {41pub const StringContext = struct {
42 pub fn hash(self: @This(), s: []const u8) u32 {42 pub fn hash(self: @This(), s: []const u8) u32 {
43 _ = self;
43 return hashString(s);44 return hashString(s);
44 }45 }
45 pub fn eql(self: @This(), a: []const u8, b: []const u8) bool {46 pub fn eql(self: @This(), a: []const u8, b: []const u8) bool {
47 _ = self;
46 return eqlString(a, b);48 return eqlString(a, b);
47 }49 }
48};50};
...@@ -1324,17 +1326,17 @@ pub fn ArrayHashMapUnmanaged(...@@ -1324,17 +1326,17 @@ pub fn ArrayHashMapUnmanaged(
1324 }1326 }
1325 fn removeFromIndexByIndexGeneric(self: *Self, entry_index: usize, ctx: ByIndexContext, header: *IndexHeader, comptime I: type, indexes: []Index(I)) void {1327 fn removeFromIndexByIndexGeneric(self: *Self, entry_index: usize, ctx: ByIndexContext, header: *IndexHeader, comptime I: type, indexes: []Index(I)) void {
1326 const slot = self.getSlotByIndex(entry_index, ctx, header, I, indexes);1328 const slot = self.getSlotByIndex(entry_index, ctx, header, I, indexes);
1327 self.removeSlot(slot, header, I, indexes);1329 removeSlot(slot, header, I, indexes);
1328 }1330 }
13291331
1330 fn removeFromIndexByKey(self: *Self, key: anytype, ctx: anytype, header: *IndexHeader, comptime I: type, indexes: []Index(I)) ?usize {1332 fn removeFromIndexByKey(self: *Self, key: anytype, ctx: anytype, header: *IndexHeader, comptime I: type, indexes: []Index(I)) ?usize {
1331 const slot = self.getSlotByKey(key, ctx, header, I, indexes) orelse return null;1333 const slot = self.getSlotByKey(key, ctx, header, I, indexes) orelse return null;
1332 const removed_entry_index = indexes[slot].entry_index;1334 const removed_entry_index = indexes[slot].entry_index;
1333 self.removeSlot(slot, header, I, indexes);1335 removeSlot(slot, header, I, indexes);
1334 return removed_entry_index;1336 return removed_entry_index;
1335 }1337 }
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 {
1338 const start_index = removed_slot +% 1;1340 const start_index = removed_slot +% 1;
1339 const end_index = start_index +% indexes.len;1341 const end_index = start_index +% indexes.len;
13401342
...@@ -1619,13 +1621,13 @@ pub fn ArrayHashMapUnmanaged(...@@ -1619,13 +1621,13 @@ pub fn ArrayHashMapUnmanaged(
1619 if (self.index_header) |header| {1621 if (self.index_header) |header| {
1620 p("\n", .{});1622 p("\n", .{});
1621 switch (header.capacityIndexType()) {1623 switch (header.capacityIndexType()) {
1622 .u8 => self.dumpIndex(header, u8),1624 .u8 => dumpIndex(header, u8),
1623 .u16 => self.dumpIndex(header, u16),1625 .u16 => dumpIndex(header, u16),
1624 .u32 => self.dumpIndex(header, u32),1626 .u32 => dumpIndex(header, u32),
1625 }1627 }
1626 }1628 }
1627 }1629 }
1628 fn dumpIndex(self: Self, header: *IndexHeader, comptime I: type) void {1630 fn dumpIndex(header: *IndexHeader, comptime I: type) void {
1629 const p = std.debug.print;1631 const p = std.debug.print;
1630 p(" index len=0x{x} type={}\n", .{ header.length(), header.capacityIndexType() });1632 p(" index len=0x{x} type={}\n", .{ header.length(), header.capacityIndexType() });
1631 const indexes = header.indexes(I);1633 const indexes = header.indexes(I);
...@@ -1918,7 +1920,7 @@ test "iterator hash map" {...@@ -1918,7 +1920,7 @@ test "iterator hash map" {
1918 try testing.expect(count == 3);1920 try testing.expect(count == 3);
1919 try testing.expect(it.next() == null);1921 try testing.expect(it.next() == null);
19201922
1921 for (buffer) |v, i| {1923 for (buffer) |_, i| {
1922 try testing.expect(buffer[@intCast(usize, keys[i])] == values[i]);1924 try testing.expect(buffer[@intCast(usize, keys[i])] == values[i]);
1923 }1925 }
19241926
...@@ -1930,7 +1932,7 @@ test "iterator hash map" {...@@ -1930,7 +1932,7 @@ test "iterator hash map" {
1930 if (count >= 2) break;1932 if (count >= 2) break;
1931 }1933 }
19321934
1933 for (buffer[0..2]) |v, i| {1935 for (buffer[0..2]) |_, i| {
1934 try testing.expect(buffer[@intCast(usize, keys[i])] == values[i]);1936 try testing.expect(buffer[@intCast(usize, keys[i])] == values[i]);
1935 }1937 }
19361938
...@@ -2154,6 +2156,7 @@ test "compile everything" {...@@ -2154,6 +2156,7 @@ test "compile everything" {
2154pub fn getHashPtrAddrFn(comptime K: type, comptime Context: type) (fn (Context, K) u32) {2156pub fn getHashPtrAddrFn(comptime K: type, comptime Context: type) (fn (Context, K) u32) {
2155 return struct {2157 return struct {
2156 fn hash(ctx: Context, key: K) u32 {2158 fn hash(ctx: Context, key: K) u32 {
2159 _ = ctx;
2157 return getAutoHashFn(usize, void)({}, @ptrToInt(key));2160 return getAutoHashFn(usize, void)({}, @ptrToInt(key));
2158 }2161 }
2159 }.hash;2162 }.hash;
...@@ -2162,6 +2165,7 @@ pub fn getHashPtrAddrFn(comptime K: type, comptime Context: type) (fn (Context,...@@ -2162,6 +2165,7 @@ pub fn getHashPtrAddrFn(comptime K: type, comptime Context: type) (fn (Context,
2162pub fn getTrivialEqlFn(comptime K: type, comptime Context: type) (fn (Context, K, K) bool) {2165pub fn getTrivialEqlFn(comptime K: type, comptime Context: type) (fn (Context, K, K) bool) {
2163 return struct {2166 return struct {
2164 fn eql(ctx: Context, a: K, b: K) bool {2167 fn eql(ctx: Context, a: K, b: K) bool {
2168 _ = ctx;
2165 return a == b;2169 return a == b;
2166 }2170 }
2167 }.eql;2171 }.eql;
...@@ -2177,6 +2181,7 @@ pub fn AutoContext(comptime K: type) type {...@@ -2177,6 +2181,7 @@ pub fn AutoContext(comptime K: type) type {
2177pub fn getAutoHashFn(comptime K: type, comptime Context: type) (fn (Context, K) u32) {2181pub fn getAutoHashFn(comptime K: type, comptime Context: type) (fn (Context, K) u32) {
2178 return struct {2182 return struct {
2179 fn hash(ctx: Context, key: K) u32 {2183 fn hash(ctx: Context, key: K) u32 {
2184 _ = ctx;
2180 if (comptime trait.hasUniqueRepresentation(K)) {2185 if (comptime trait.hasUniqueRepresentation(K)) {
2181 return @truncate(u32, Wyhash.hash(0, std.mem.asBytes(&key)));2186 return @truncate(u32, Wyhash.hash(0, std.mem.asBytes(&key)));
2182 } else {2187 } else {
...@@ -2191,6 +2196,7 @@ pub fn getAutoHashFn(comptime K: type, comptime Context: type) (fn (Context, K)...@@ -2191,6 +2196,7 @@ pub fn getAutoHashFn(comptime K: type, comptime Context: type) (fn (Context, K)
2191pub fn getAutoEqlFn(comptime K: type, comptime Context: type) (fn (Context, K, K) bool) {2196pub fn getAutoEqlFn(comptime K: type, comptime Context: type) (fn (Context, K, K) bool) {
2192 return struct {2197 return struct {
2193 fn eql(ctx: Context, a: K, b: K) bool {2198 fn eql(ctx: Context, a: K, b: K) bool {
2199 _ = ctx;
2194 return meta.eql(a, b);2200 return meta.eql(a, b);
2195 }2201 }
2196 }.eql;2202 }.eql;
...@@ -2217,6 +2223,7 @@ pub fn autoEqlIsCheap(comptime K: type) bool {...@@ -2217,6 +2223,7 @@ pub fn autoEqlIsCheap(comptime K: type) bool {
2217pub fn getAutoHashStratFn(comptime K: type, comptime Context: type, comptime strategy: std.hash.Strategy) (fn (Context, K) u32) {2223pub fn getAutoHashStratFn(comptime K: type, comptime Context: type, comptime strategy: std.hash.Strategy) (fn (Context, K) u32) {
2218 return struct {2224 return struct {
2219 fn hash(ctx: Context, key: K) u32 {2225 fn hash(ctx: Context, key: K) u32 {
2226 _ = ctx;
2220 var hasher = Wyhash.init(0);2227 var hasher = Wyhash.init(0);
2221 std.hash.autoHashStrat(&hasher, key, strategy);2228 std.hash.autoHashStrat(&hasher, key, strategy);
2222 return @truncate(u32, hasher.final());2229 return @truncate(u32, hasher.final());
lib/std/atomic/Atomic.zig+2
...@@ -232,6 +232,7 @@ test "Atomic.loadUnchecked" {...@@ -232,6 +232,7 @@ test "Atomic.loadUnchecked" {
232232
233test "Atomic.storeUnchecked" {233test "Atomic.storeUnchecked" {
234 inline for (atomicIntTypes()) |Int| {234 inline for (atomicIntTypes()) |Int| {
235 _ = Int;
235 var x = Atomic(usize).init(5);236 var x = Atomic(usize).init(5);
236 x.storeUnchecked(10);237 x.storeUnchecked(10);
237 try testing.expectEqual(x.loadUnchecked(), 10);238 try testing.expectEqual(x.loadUnchecked(), 10);
...@@ -250,6 +251,7 @@ test "Atomic.load" {...@@ -250,6 +251,7 @@ test "Atomic.load" {
250test "Atomic.store" {251test "Atomic.store" {
251 inline for (atomicIntTypes()) |Int| {252 inline for (atomicIntTypes()) |Int| {
252 inline for (.{ .Unordered, .Monotonic, .Release, .SeqCst }) |ordering| {253 inline for (.{ .Unordered, .Monotonic, .Release, .SeqCst }) |ordering| {
254 _ = Int;
253 var x = Atomic(usize).init(5);255 var x = Atomic(usize).init(5);
254 x.store(10, ordering);256 x.store(10, ordering);
255 try testing.expectEqual(x.load(.SeqCst), 10);257 try testing.expectEqual(x.load(.SeqCst), 10);
lib/std/base64.zig-5
...@@ -112,9 +112,6 @@ pub const Base64Encoder = struct {...@@ -112,9 +112,6 @@ pub const Base64Encoder = struct {
112 const out_len = encoder.calcSize(source.len);112 const out_len = encoder.calcSize(source.len);
113 assert(dest.len >= out_len);113 assert(dest.len >= out_len);
114114
115 const nibbles = source.len / 3;
116 const leftover = source.len - 3 * nibbles;
117
118 var acc: u12 = 0;115 var acc: u12 = 0;
119 var acc_len: u4 = 0;116 var acc_len: u4 = 0;
120 var out_idx: usize = 0;117 var out_idx: usize = 0;
...@@ -223,7 +220,6 @@ pub const Base64Decoder = struct {...@@ -223,7 +220,6 @@ pub const Base64Decoder = struct {
223 if (decoder.pad_char) |pad_char| {220 if (decoder.pad_char) |pad_char| {
224 const padding_len = acc_len / 2;221 const padding_len = acc_len / 2;
225 var padding_chars: usize = 0;222 var padding_chars: usize = 0;
226 var i: usize = 0;
227 for (leftover) |c| {223 for (leftover) |c| {
228 if (c != pad_char) {224 if (c != pad_char) {
229 return if (c == Base64Decoder.invalid_char) error.InvalidCharacter else error.InvalidPadding;225 return if (c == Base64Decoder.invalid_char) error.InvalidCharacter else error.InvalidPadding;
...@@ -302,7 +298,6 @@ pub const Base64DecoderWithIgnore = struct {...@@ -302,7 +298,6 @@ pub const Base64DecoderWithIgnore = struct {
302 var leftover = source[leftover_idx.?..];298 var leftover = source[leftover_idx.?..];
303 if (decoder.pad_char) |pad_char| {299 if (decoder.pad_char) |pad_char| {
304 var padding_chars: usize = 0;300 var padding_chars: usize = 0;
305 var i: usize = 0;
306 for (leftover) |c| {301 for (leftover) |c| {
307 if (decoder_with_ignore.char_is_ignored[c]) continue;302 if (decoder_with_ignore.char_is_ignored[c]) continue;
308 if (c != pad_char) {303 if (c != pad_char) {
lib/std/bit_set.zig+4-2
...@@ -84,6 +84,7 @@ pub fn IntegerBitSet(comptime size: u16) type {...@@ -84,6 +84,7 @@ pub fn IntegerBitSet(comptime size: u16) type {
8484
85 /// Returns the number of bits in this bit set85 /// Returns the number of bits in this bit set
86 pub inline fn capacity(self: Self) usize {86 pub inline fn capacity(self: Self) usize {
87 _ = self;
87 return bit_length;88 return bit_length;
88 }89 }
8990
...@@ -311,6 +312,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type {...@@ -311,6 +312,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type {
311312
312 /// Returns the number of bits in this bit set313 /// Returns the number of bits in this bit set
313 pub inline fn capacity(self: Self) usize {314 pub inline fn capacity(self: Self) usize {
315 _ = self;
314 return bit_length;316 return bit_length;
315 }317 }
316318
...@@ -373,7 +375,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type {...@@ -373,7 +375,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type {
373375
374 /// Flips every bit in the bit set.376 /// Flips every bit in the bit set.
375 pub fn toggleAll(self: *Self) void {377 pub fn toggleAll(self: *Self) void {
376 for (self.masks) |*mask, i| {378 for (self.masks) |*mask| {
377 mask.* = ~mask.*;379 mask.* = ~mask.*;
378 }380 }
379381
...@@ -642,7 +644,7 @@ pub const DynamicBitSetUnmanaged = struct {...@@ -642,7 +644,7 @@ pub const DynamicBitSetUnmanaged = struct {
642 if (bit_length == 0) return;644 if (bit_length == 0) return;
643645
644 const num_masks = numMasks(self.bit_length);646 const num_masks = numMasks(self.bit_length);
645 for (self.masks[0..num_masks]) |*mask, i| {647 for (self.masks[0..num_masks]) |*mask| {
646 mask.* = ~mask.*;648 mask.* = ~mask.*;
647 }649 }
648650
lib/std/build.zig+5-2
...@@ -390,6 +390,7 @@ pub const Builder = struct {...@@ -390,6 +390,7 @@ pub const Builder = struct {
390 }390 }
391391
392 pub fn version(self: *const Builder, major: u32, minor: u32, patch: u32) LibExeObjStep.SharedLibKind {392 pub fn version(self: *const Builder, major: u32, minor: u32, patch: u32) LibExeObjStep.SharedLibKind {
393 _ = self;
393 return .{394 return .{
394 .versioned = .{395 .versioned = .{
395 .major = major,396 .major = major,
...@@ -543,7 +544,7 @@ pub const Builder = struct {...@@ -543,7 +544,7 @@ pub const Builder = struct {
543 return null;544 return null;
544 },545 },
545 .scalar => |s| {546 .scalar => |s| {
546 const n = std.fmt.parseFloat(T, s) catch |err| {547 const n = std.fmt.parseFloat(T, s) catch {
547 warn("Expected -D{s} to be a float of type {s}.\n\n", .{ name, @typeName(T) });548 warn("Expected -D{s} to be a float of type {s}.\n\n", .{ name, @typeName(T) });
548 self.markInvalidUserInput();549 self.markInvalidUserInput();
549 return null;550 return null;
...@@ -3129,7 +3130,9 @@ pub const Step = struct {...@@ -3129,7 +3130,9 @@ pub const Step = struct {
3129 self.dependencies.append(other) catch unreachable;3130 self.dependencies.append(other) catch unreachable;
3130 }3131 }
31313132
3132 fn makeNoOp(self: *Step) anyerror!void {}3133 fn makeNoOp(self: *Step) anyerror!void {
3134 _ = self;
3135 }
31333136
3134 pub fn cast(step: *Step, comptime T: type) ?*T {3137 pub fn cast(step: *Step, comptime T: type) ?*T {
3135 if (step.id == T.base_id) {3138 if (step.id == T.base_id) {
lib/std/build/InstallRawStep.zig+2
...@@ -139,6 +139,7 @@ const BinaryElfOutput = struct {...@@ -139,6 +139,7 @@ const BinaryElfOutput = struct {
139 }139 }
140140
141 fn segmentSortCompare(context: void, left: *BinaryElfSegment, right: *BinaryElfSegment) bool {141 fn segmentSortCompare(context: void, left: *BinaryElfSegment, right: *BinaryElfSegment) bool {
142 _ = context;
142 if (left.physicalAddress < right.physicalAddress) {143 if (left.physicalAddress < right.physicalAddress) {
143 return true;144 return true;
144 }145 }
...@@ -149,6 +150,7 @@ const BinaryElfOutput = struct {...@@ -149,6 +150,7 @@ const BinaryElfOutput = struct {
149 }150 }
150151
151 fn sectionSortCompare(context: void, left: *BinaryElfSection, right: *BinaryElfSection) bool {152 fn sectionSortCompare(context: void, left: *BinaryElfSection, right: *BinaryElfSection) bool {
153 _ = context;
152 return left.binaryOffset < right.binaryOffset;154 return left.binaryOffset < right.binaryOffset;
153 }155 }
154};156};
lib/std/builtin.zig+3
...@@ -65,6 +65,8 @@ pub const StackTrace = struct {...@@ -65,6 +65,8 @@ pub const StackTrace = struct {
65 options: std.fmt.FormatOptions,65 options: std.fmt.FormatOptions,
66 writer: anytype,66 writer: anytype,
67 ) !void {67 ) !void {
68 _ = fmt;
69 _ = options;
68 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);70 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
69 defer arena.deinit();71 defer arena.deinit();
70 const debug_info = std.debug.getSelfDebugInfo() catch |err| {72 const debug_info = std.debug.getSelfDebugInfo() catch |err| {
...@@ -521,6 +523,7 @@ pub const Version = struct {...@@ -521,6 +523,7 @@ pub const Version = struct {
521 options: std.fmt.FormatOptions,523 options: std.fmt.FormatOptions,
522 out_stream: anytype,524 out_stream: anytype,
523 ) !void {525 ) !void {
526 _ = options;
524 if (fmt.len == 0) {527 if (fmt.len == 0) {
525 if (self.patch == 0) {528 if (self.patch == 0) {
526 if (self.minor == 0) {529 if (self.minor == 0) {
lib/std/c/tokenizer.zig+6-7
...@@ -351,7 +351,6 @@ pub const Tokenizer = struct {...@@ -351,7 +351,6 @@ pub const Tokenizer = struct {
351 pp_directive: bool = false,351 pp_directive: bool = false,
352352
353 pub fn next(self: *Tokenizer) Token {353 pub fn next(self: *Tokenizer) Token {
354 const start_index = self.index;
355 var result = Token{354 var result = Token{
356 .id = .Eof,355 .id = .Eof,
357 .start = self.index,356 .start = self.index,
...@@ -1380,12 +1379,12 @@ test "operators" {...@@ -1380,12 +1379,12 @@ test "operators" {
13801379
1381test "keywords" {1380test "keywords" {
1382 try expectTokens(1381 try expectTokens(
1383 \\auto break case char const continue default do 1382 \\auto break case char const continue default do
1384 \\double else enum extern float for goto if int 1383 \\double else enum extern float for goto if int
1385 \\long register return short signed sizeof static 1384 \\long register return short signed sizeof static
1386 \\struct switch typedef union unsigned void volatile 1385 \\struct switch typedef union unsigned void volatile
1387 \\while _Bool _Complex _Imaginary inline restrict _Alignas 1386 \\while _Bool _Complex _Imaginary inline restrict _Alignas
1388 \\_Alignof _Atomic _Generic _Noreturn _Static_assert _Thread_local 1387 \\_Alignof _Atomic _Generic _Noreturn _Static_assert _Thread_local
1389 \\1388 \\
1390 , &[_]Token.Id{1389 , &[_]Token.Id{
1391 .Keyword_auto,1390 .Keyword_auto,
lib/std/compress/gzip.zig+2
...@@ -62,6 +62,8 @@ pub fn GzipStream(comptime ReaderType: type) type {...@@ -62,6 +62,8 @@ pub fn GzipStream(comptime ReaderType: type) type {
62 const XFL = header[8];62 const XFL = header[8];
63 // Operating system where the compression took place63 // Operating system where the compression took place
64 const OS = header[9];64 const OS = header[9];
65 _ = XFL;
66 _ = OS;
6567
66 if (FLG & FEXTRA != 0) {68 if (FLG & FEXTRA != 0) {
67 // Skip the extra data, we could read and expose it to the user69 // 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 {...@@ -35,6 +35,7 @@ pub fn ZlibStream(comptime ReaderType: type) type {
35 const CM = @truncate(u4, header[0]);35 const CM = @truncate(u4, header[0]);
36 const CINFO = @truncate(u4, header[0] >> 4);36 const CINFO = @truncate(u4, header[0] >> 4);
37 const FCHECK = @truncate(u5, header[1]);37 const FCHECK = @truncate(u5, header[1]);
38 _ = FCHECK;
38 const FDICT = @truncate(u1, header[1] >> 5);39 const FDICT = @truncate(u1, header[1] >> 5);
3940
40 if ((@as(u16, header[0]) << 8 | header[1]) % 31 != 0)41 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 {...@@ -23,6 +23,7 @@ pub fn ComptimeStringMap(comptime V: type, comptime kvs: anytype) type {
23 var sorted_kvs: [kvs.len]KV = undefined;23 var sorted_kvs: [kvs.len]KV = undefined;
24 const lenAsc = (struct {24 const lenAsc = (struct {
25 fn lenAsc(context: void, a: KV, b: KV) bool {25 fn lenAsc(context: void, a: KV, b: KV) bool {
26 _ = context;
26 return a.key.len < b.key.len;27 return a.key.len < b.key.len;
27 }28 }
28 }).lenAsc;29 }).lenAsc;
lib/std/crypto/25519/ed25519.zig+1-1
...@@ -346,7 +346,7 @@ test "ed25519 test vectors" {...@@ -346,7 +346,7 @@ test "ed25519 test vectors" {
346 .expected = error.IdentityElement, // 11 - small-order A346 .expected = error.IdentityElement, // 11 - small-order A
347 },347 },
348 };348 };
349 for (entries) |entry, i| {349 for (entries) |entry| {
350 var msg: [entry.msg_hex.len / 2]u8 = undefined;350 var msg: [entry.msg_hex.len / 2]u8 = undefined;
351 _ = try fmt.hexToBytes(&msg, entry.msg_hex);351 _ = try fmt.hexToBytes(&msg, entry.msg_hex);
352 var public_key: [32]u8 = undefined;352 var public_key: [32]u8 = undefined;
lib/std/crypto/25519/scalar.zig-6
...@@ -330,13 +330,10 @@ pub const Scalar = struct {...@@ -330,13 +330,10 @@ pub const Scalar = struct {
330 const carry9 = z02 >> 56;330 const carry9 = z02 >> 56;
331 const c01 = carry9;331 const c01 = carry9;
332 const carry10 = (z12 + c01) >> 56;332 const carry10 = (z12 + c01) >> 56;
333 const t21 = @truncate(u64, z12 + c01) & 0xffffffffffffff;
334 const c11 = carry10;333 const c11 = carry10;
335 const carry11 = (z22 + c11) >> 56;334 const carry11 = (z22 + c11) >> 56;
336 const t22 = @truncate(u64, z22 + c11) & 0xffffffffffffff;
337 const c21 = carry11;335 const c21 = carry11;
338 const carry12 = (z32 + c21) >> 56;336 const carry12 = (z32 + c21) >> 56;
339 const t23 = @truncate(u64, z32 + c21) & 0xffffffffffffff;
340 const c31 = carry12;337 const c31 = carry12;
341 const carry13 = (z42 + c31) >> 56;338 const carry13 = (z42 + c31) >> 56;
342 const t24 = @truncate(u64, z42 + c31) & 0xffffffffffffff;339 const t24 = @truncate(u64, z42 + c31) & 0xffffffffffffff;
...@@ -605,13 +602,10 @@ const ScalarDouble = struct {...@@ -605,13 +602,10 @@ const ScalarDouble = struct {
605 const carry0 = z01 >> 56;602 const carry0 = z01 >> 56;
606 const c00 = carry0;603 const c00 = carry0;
607 const carry1 = (z11 + c00) >> 56;604 const carry1 = (z11 + c00) >> 56;
608 const t100 = @as(u64, @truncate(u64, z11 + c00)) & 0xffffffffffffff;
609 const c10 = carry1;605 const c10 = carry1;
610 const carry2 = (z21 + c10) >> 56;606 const carry2 = (z21 + c10) >> 56;
611 const t101 = @as(u64, @truncate(u64, z21 + c10)) & 0xffffffffffffff;
612 const c20 = carry2;607 const c20 = carry2;
613 const carry3 = (z31 + c20) >> 56;608 const carry3 = (z31 + c20) >> 56;
614 const t102 = @as(u64, @truncate(u64, z31 + c20)) & 0xffffffffffffff;
615 const c30 = carry3;609 const c30 = carry3;
616 const carry4 = (z41 + c30) >> 56;610 const carry4 = (z41 + c30) >> 56;
617 const t103 = @as(u64, @truncate(u64, z41 + c30)) & 0xffffffffffffff;611 const t103 = @as(u64, @truncate(u64, z41 + c30)) & 0xffffffffffffff;
lib/std/crypto/aes/soft.zig-8
...@@ -49,8 +49,6 @@ pub const Block = struct {...@@ -49,8 +49,6 @@ pub const Block = struct {
4949
50 /// Encrypt a block with a round key.50 /// Encrypt a block with a round key.
51 pub inline fn encrypt(block: Block, round_key: Block) Block {51 pub inline fn encrypt(block: Block, round_key: Block) Block {
52 const src = &block.repr;
53
54 const s0 = block.repr[0];52 const s0 = block.repr[0];
55 const s1 = block.repr[1];53 const s1 = block.repr[1];
56 const s2 = block.repr[2];54 const s2 = block.repr[2];
...@@ -66,8 +64,6 @@ pub const Block = struct {...@@ -66,8 +64,6 @@ pub const Block = struct {
6664
67 /// Encrypt a block with the last round key.65 /// Encrypt a block with the last round key.
68 pub inline fn encryptLast(block: Block, round_key: Block) Block {66 pub inline fn encryptLast(block: Block, round_key: Block) Block {
69 const src = &block.repr;
70
71 const t0 = block.repr[0];67 const t0 = block.repr[0];
72 const t1 = block.repr[1];68 const t1 = block.repr[1];
73 const t2 = block.repr[2];69 const t2 = block.repr[2];
...@@ -88,8 +84,6 @@ pub const Block = struct {...@@ -88,8 +84,6 @@ pub const Block = struct {
8884
89 /// Decrypt a block with a round key.85 /// Decrypt a block with a round key.
90 pub inline fn decrypt(block: Block, round_key: Block) Block {86 pub inline fn decrypt(block: Block, round_key: Block) Block {
91 const src = &block.repr;
92
93 const s0 = block.repr[0];87 const s0 = block.repr[0];
94 const s1 = block.repr[1];88 const s1 = block.repr[1];
95 const s2 = block.repr[2];89 const s2 = block.repr[2];
...@@ -105,8 +99,6 @@ pub const Block = struct {...@@ -105,8 +99,6 @@ pub const Block = struct {
10599
106 /// Decrypt a block with the last round key.100 /// Decrypt a block with the last round key.
107 pub inline fn decryptLast(block: Block, round_key: Block) Block {101 pub inline fn decryptLast(block: Block, round_key: Block) Block {
108 const src = &block.repr;
109
110 const t0 = block.repr[0];102 const t0 = block.repr[0];
111 const t1 = block.repr[1];103 const t1 = block.repr[1];
112 const t2 = block.repr[2];104 const t2 = block.repr[2];
lib/std/crypto/aes_gcm.zig-1
...@@ -114,7 +114,6 @@ test "Aes256Gcm - Empty message and no associated data" {...@@ -114,7 +114,6 @@ test "Aes256Gcm - Empty message and no associated data" {
114 const ad = "";114 const ad = "";
115 const m = "";115 const m = "";
116 var c: [m.len]u8 = undefined;116 var c: [m.len]u8 = undefined;
117 var m2: [m.len]u8 = undefined;
118 var tag: [Aes256Gcm.tag_length]u8 = undefined;117 var tag: [Aes256Gcm.tag_length]u8 = undefined;
119118
120 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);119 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
lib/std/crypto/aes_ocb.zig-1
...@@ -271,7 +271,6 @@ test "AesOcb test vector 1" {...@@ -271,7 +271,6 @@ test "AesOcb test vector 1" {
271 var c: [0]u8 = undefined;271 var c: [0]u8 = undefined;
272 Aes128Ocb.encrypt(&c, &tag, "", "", nonce, k);272 Aes128Ocb.encrypt(&c, &tag, "", "", nonce, k);
273273
274 var expected_c: [c.len]u8 = undefined;
275 var expected_tag: [tag.len]u8 = undefined;274 var expected_tag: [tag.len]u8 = undefined;
276 _ = try hexToBytes(&expected_tag, "785407BFFFC8AD9EDCC5520AC9111EE6");275 _ = try hexToBytes(&expected_tag, "785407BFFFC8AD9EDCC5520AC9111EE6");
277276
lib/std/crypto/bcrypt.zig-2
...@@ -48,7 +48,6 @@ const State = struct {...@@ -48,7 +48,6 @@ const State = struct {
48 fn expand0(state: *State, key: []const u8) void {48 fn expand0(state: *State, key: []const u8) void {
49 var i: usize = 0;49 var i: usize = 0;
50 var j: usize = 0;50 var j: usize = 0;
51 var t: u32 = undefined;
52 while (i < state.subkeys.len) : (i += 1) {51 while (i < state.subkeys.len) : (i += 1) {
53 state.subkeys[i] ^= toWord(key, &j);52 state.subkeys[i] ^= toWord(key, &j);
54 }53 }
...@@ -75,7 +74,6 @@ const State = struct {...@@ -75,7 +74,6 @@ const State = struct {
75 fn expand(state: *State, data: []const u8, key: []const u8) void {74 fn expand(state: *State, data: []const u8, key: []const u8) void {
76 var i: usize = 0;75 var i: usize = 0;
77 var j: usize = 0;76 var j: usize = 0;
78 var t: u32 = undefined;
79 while (i < state.subkeys.len) : (i += 1) {77 while (i < state.subkeys.len) : (i += 1) {
80 state.subkeys[i] ^= toWord(key, &j);78 state.subkeys[i] ^= toWord(key, &j);
81 }79 }
lib/std/crypto/blake3.zig+1
...@@ -394,6 +394,7 @@ pub const Blake3 = struct {...@@ -394,6 +394,7 @@ pub const Blake3 = struct {
394 /// Construct a new `Blake3` for the key derivation function. The context394 /// Construct a new `Blake3` for the key derivation function. The context
395 /// string should be hardcoded, globally unique, and application-specific.395 /// string should be hardcoded, globally unique, and application-specific.
396 pub fn initKdf(context: []const u8, options: KdfOptions) Blake3 {396 pub fn initKdf(context: []const u8, options: KdfOptions) Blake3 {
397 _ = options;
397 var context_hasher = Blake3.init_internal(IV, DERIVE_KEY_CONTEXT);398 var context_hasher = Blake3.init_internal(IV, DERIVE_KEY_CONTEXT);
398 context_hasher.update(context);399 context_hasher.update(context);
399 var context_key: [KEY_LEN]u8 = undefined;400 var context_key: [KEY_LEN]u8 = undefined;
lib/std/crypto/chacha20.zig-1
...@@ -444,7 +444,6 @@ fn ChaChaWith64BitNonce(comptime rounds_nb: usize) type {...@@ -444,7 +444,6 @@ fn ChaChaWith64BitNonce(comptime rounds_nb: usize) type {
444 if (comptime @sizeOf(usize) > 4) {444 if (comptime @sizeOf(usize) > 4) {
445 // A big block is giant: 256 GiB, but we can avoid this limitation445 // A big block is giant: 256 GiB, but we can avoid this limitation
446 var remaining_blocks: u32 = @intCast(u32, (in.len / big_block));446 var remaining_blocks: u32 = @intCast(u32, (in.len / big_block));
447 var i: u32 = 0;
448 while (remaining_blocks > 0) : (remaining_blocks -= 1) {447 while (remaining_blocks > 0) : (remaining_blocks -= 1) {
449 ChaChaImpl(rounds_nb).chacha20Xor(out[cursor .. cursor + big_block], in[cursor .. cursor + big_block], k, c);448 ChaChaImpl(rounds_nb).chacha20Xor(out[cursor .. cursor + big_block], in[cursor .. cursor + big_block], k, c);
450 c[1] += 1; // upper 32-bit of counter, generic chacha20Xor() doesn't know about this.449 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 {...@@ -219,6 +219,7 @@ pub const Hash = struct {
219 const Self = @This();219 const Self = @This();
220220
221 pub fn init(options: Options) Self {221 pub fn init(options: Options) Self {
222 _ = options;
222 return Self{223 return Self{
223 .state = State{ .data = [_]u32{0} ** (State.BLOCKBYTES / 4) },224 .state = State{ .data = [_]u32{0} ** (State.BLOCKBYTES / 4) },
224 .buf_off = 0,225 .buf_off = 0,
lib/std/crypto/md5.zig+1
...@@ -45,6 +45,7 @@ pub const Md5 = struct {...@@ -45,6 +45,7 @@ pub const Md5 = struct {
45 total_len: u64,45 total_len: u64,
4646
47 pub fn init(options: Options) Self {47 pub fn init(options: Options) Self {
48 _ = options;
48 return Self{49 return Self{
49 .s = [_]u32{50 .s = [_]u32{
50 0x67452301,51 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...@@ -63,7 +63,7 @@ pub fn add(a: CompressedScalar, b: CompressedScalar, endian: builtin.Endian) Non
6363
64/// Return -s (mod L)64/// Return -s (mod L)
65pub fn neg(s: CompressedScalar, endian: builtin.Endian) NonCanonicalError!CompressedScalar {65pub 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);
67}67}
6868
69/// Return (a-b) (mod L)69/// Return (a-b) (mod L)
lib/std/crypto/sha1.zig+1
...@@ -43,6 +43,7 @@ pub const Sha1 = struct {...@@ -43,6 +43,7 @@ pub const Sha1 = struct {
43 total_len: u64 = 0,43 total_len: u64 = 0,
4444
45 pub fn init(options: Options) Self {45 pub fn init(options: Options) Self {
46 _ = options;
46 return Self{47 return Self{
47 .s = [_]u32{48 .s = [_]u32{
48 0x67452301,49 0x67452301,
lib/std/crypto/sha2.zig+2
...@@ -95,6 +95,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {...@@ -95,6 +95,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
95 total_len: u64 = 0,95 total_len: u64 = 0,
9696
97 pub fn init(options: Options) Self {97 pub fn init(options: Options) Self {
98 _ = options;
98 return Self{99 return Self{
99 .s = [_]u32{100 .s = [_]u32{
100 params.iv0,101 params.iv0,
...@@ -462,6 +463,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {...@@ -462,6 +463,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {
462 total_len: u128 = 0,463 total_len: u128 = 0,
463464
464 pub fn init(options: Options) Self {465 pub fn init(options: Options) Self {
466 _ = options;
465 return Self{467 return Self{
466 .s = [_]u64{468 .s = [_]u64{
467 params.iv0,469 params.iv0,
lib/std/crypto/sha3.zig+1
...@@ -28,6 +28,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type {...@@ -28,6 +28,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type {
28 rate: usize,28 rate: usize,
2929
30 pub fn init(options: Options) Self {30 pub fn init(options: Options) Self {
31 _ = options;
31 return Self{ .s = [_]u8{0} ** 200, .offset = 0, .rate = 200 - (bits / 4) };32 return Self{ .s = [_]u8{0} ** 200, .offset = 0, .rate = 200 - (bits / 4) };
32 }33 }
3334
lib/std/crypto/tlcsprng.zig+1-1
...@@ -84,7 +84,7 @@ fn tlsCsprngFill(_: *const std.rand.Random, buffer: []u8) void {...@@ -84,7 +84,7 @@ fn tlsCsprngFill(_: *const std.rand.Random, buffer: []u8) void {
84 os.MAP_PRIVATE | os.MAP_ANONYMOUS,84 os.MAP_PRIVATE | os.MAP_ANONYMOUS,
85 -1,85 -1,
86 0,86 0,
87 ) catch |err| {87 ) catch {
88 // Could not allocate memory for the local state, fall back to88 // Could not allocate memory for the local state, fall back to
89 // the OS syscall.89 // the OS syscall.
90 return fillWithOsEntropy(buffer);90 return fillWithOsEntropy(buffer);
lib/std/debug.zig+6-1
...@@ -325,6 +325,7 @@ pub fn writeStackTrace(...@@ -325,6 +325,7 @@ pub fn writeStackTrace(
325 debug_info: *DebugInfo,325 debug_info: *DebugInfo,
326 tty_config: TTY.Config,326 tty_config: TTY.Config,
327) !void {327) !void {
328 _ = allocator;
328 if (builtin.strip_debug_info) return error.MissingDebugInfo;329 if (builtin.strip_debug_info) return error.MissingDebugInfo;
329 var frame_index: usize = 0;330 var frame_index: usize = 0;
330 var frames_left: usize = std.math.min(stack_trace.index, stack_trace.instruction_addresses.len);331 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...@@ -680,6 +681,7 @@ fn readCoffDebugInfo(allocator: *mem.Allocator, coff_file: File) !ModuleDebugInf
680 try di.coff.loadSections();681 try di.coff.loadSections();
681 if (di.coff.getSection(".debug_info")) |sec| {682 if (di.coff.getSection(".debug_info")) |sec| {
682 // This coff file has embedded DWARF debug info683 // This coff file has embedded DWARF debug info
684 _ = sec;
683 // TODO: free the section data slices685 // TODO: free the section data slices
684 const debug_info_data = di.coff.getSectionData(".debug_info", allocator) catch null;686 const debug_info_data = di.coff.getSectionData(".debug_info", allocator) catch null;
685 const debug_abbrev_data = di.coff.getSectionData(".debug_abbrev", allocator) catch null;687 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 {...@@ -896,7 +898,6 @@ fn printLineFromFileAnyOs(out_stream: anytype, line_info: LineInfo) !void {
896 var buf: [mem.page_size]u8 = undefined;898 var buf: [mem.page_size]u8 = undefined;
897 var line: usize = 1;899 var line: usize = 1;
898 var column: usize = 1;900 var column: usize = 1;
899 var abs_index: usize = 0;
900 while (true) {901 while (true) {
901 const amt_read = try f.read(buf[0..]);902 const amt_read = try f.read(buf[0..]);
902 const slice = buf[0..amt_read];903 const slice = buf[0..amt_read];
...@@ -931,6 +932,7 @@ const MachoSymbol = struct {...@@ -931,6 +932,7 @@ const MachoSymbol = struct {
931 }932 }
932933
933 fn addressLessThan(context: void, lhs: MachoSymbol, rhs: MachoSymbol) bool {934 fn addressLessThan(context: void, lhs: MachoSymbol, rhs: MachoSymbol) bool {
935 _ = context;
934 return lhs.address() < rhs.address();936 return lhs.address() < rhs.address();
935 }937 }
936};938};
...@@ -1135,6 +1137,7 @@ pub const DebugInfo = struct {...@@ -1135,6 +1137,7 @@ pub const DebugInfo = struct {
11351137
1136 if (os.dl_iterate_phdr(&ctx, anyerror, struct {1138 if (os.dl_iterate_phdr(&ctx, anyerror, struct {
1137 fn callback(info: *os.dl_phdr_info, size: usize, context: *CtxTy) !void {1139 fn callback(info: *os.dl_phdr_info, size: usize, context: *CtxTy) !void {
1140 _ = size;
1138 // The base address is too high1141 // The base address is too high
1139 if (context.address < info.dlpi_addr)1142 if (context.address < info.dlpi_addr)
1140 return;1143 return;
...@@ -1190,6 +1193,8 @@ pub const DebugInfo = struct {...@@ -1190,6 +1193,8 @@ pub const DebugInfo = struct {
1190 }1193 }
11911194
1192 fn lookupModuleHaiku(self: *DebugInfo, address: usize) !*ModuleDebugInfo {1195 fn lookupModuleHaiku(self: *DebugInfo, address: usize) !*ModuleDebugInfo {
1196 _ = self;
1197 _ = address;
1193 @panic("TODO implement lookup module for Haiku");1198 @panic("TODO implement lookup module for Haiku");
1194 }1199 }
1195};1200};
lib/std/dwarf.zig+4-2
...@@ -283,6 +283,7 @@ fn parseFormValueBlock(allocator: *mem.Allocator, in_stream: anytype, endian: bu...@@ -283,6 +283,7 @@ fn parseFormValueBlock(allocator: *mem.Allocator, in_stream: anytype, endian: bu
283}283}
284284
285fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: anytype, signed: bool, endian: builtin.Endian, comptime size: i32) !FormValue {285fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: anytype, signed: bool, endian: builtin.Endian, comptime size: i32) !FormValue {
286 _ = allocator;
286 // TODO: Please forgive me, I've worked around zig not properly spilling some intermediate values here.287 // TODO: Please forgive me, I've worked around zig not properly spilling some intermediate values here.
287 // `nosuspend` should be removed from all the function calls once it is fixed.288 // `nosuspend` should be removed from all the function calls once it is fixed.
288 return FormValue{289 return FormValue{
...@@ -310,6 +311,7 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: anytype, signed:...@@ -310,6 +311,7 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: anytype, signed:
310311
311// TODO the nosuspends here are workarounds312// TODO the nosuspends here are workarounds
312fn parseFormValueRef(allocator: *mem.Allocator, in_stream: anytype, endian: builtin.Endian, size: i32) !FormValue {313fn parseFormValueRef(allocator: *mem.Allocator, in_stream: anytype, endian: builtin.Endian, size: i32) !FormValue {
314 _ = allocator;
313 return FormValue{315 return FormValue{
314 .Ref = switch (size) {316 .Ref = switch (size) {
315 1 => try nosuspend in_stream.readInt(u8, endian),317 1 => try nosuspend in_stream.readInt(u8, endian),
...@@ -453,13 +455,13 @@ pub const DwarfInfo = struct {...@@ -453,13 +455,13 @@ pub const DwarfInfo = struct {
453 if (this_die_obj.getAttr(AT_name)) |_| {455 if (this_die_obj.getAttr(AT_name)) |_| {
454 const name = try this_die_obj.getAttrString(di, AT_name);456 const name = try this_die_obj.getAttrString(di, AT_name);
455 break :x name;457 break :x name;
456 } else if (this_die_obj.getAttr(AT_abstract_origin)) |ref| {458 } else if (this_die_obj.getAttr(AT_abstract_origin)) |_| {
457 // Follow the DIE it points to and repeat459 // Follow the DIE it points to and repeat
458 const ref_offset = try this_die_obj.getAttrRef(AT_abstract_origin);460 const ref_offset = try this_die_obj.getAttrRef(AT_abstract_origin);
459 if (ref_offset > next_offset) return error.InvalidDebugInfo;461 if (ref_offset > next_offset) return error.InvalidDebugInfo;
460 try seekable.seekTo(this_unit_offset + ref_offset);462 try seekable.seekTo(this_unit_offset + ref_offset);
461 this_die_obj = (try di.parseDie(in, abbrev_table, is_64)) orelse return error.InvalidDebugInfo;463 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)) |_| {
463 // Follow the DIE it points to and repeat465 // Follow the DIE it points to and repeat
464 const ref_offset = try this_die_obj.getAttrRef(AT_specification);466 const ref_offset = try this_die_obj.getAttrRef(AT_specification);
465 if (ref_offset > next_offset) return error.InvalidDebugInfo;467 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 {...@@ -66,6 +66,7 @@ pub fn get_DYNAMIC() ?[*]elf.Dyn {
66}66}
6767
68pub fn linkmap_iterator(phdrs: []elf.Phdr) !LinkMap.Iterator {68pub fn linkmap_iterator(phdrs: []elf.Phdr) !LinkMap.Iterator {
69 _ = phdrs;
69 const _DYNAMIC = get_DYNAMIC() orelse {70 const _DYNAMIC = get_DYNAMIC() orelse {
70 // No PT_DYNAMIC means this is either a statically-linked program or a71 // No PT_DYNAMIC means this is either a statically-linked program or a
71 // badly corrupted dynamically-linked one.72 // badly corrupted dynamically-linked one.
...@@ -407,7 +408,7 @@ test "dynamic_library" {...@@ -407,7 +408,7 @@ test "dynamic_library" {
407 else => return error.SkipZigTest,408 else => return error.SkipZigTest,
408 };409 };
409410
410 const dynlib = DynLib.open(libname) catch |err| {411 _ = DynLib.open(libname) catch |err| {
411 try testing.expect(err == error.FileNotFound);412 try testing.expect(err == error.FileNotFound);
412 return;413 return;
413 };414 };
lib/std/enums.zig+9-4
...@@ -18,7 +18,7 @@ const EnumField = std.builtin.TypeInfo.EnumField;...@@ -18,7 +18,7 @@ const EnumField = std.builtin.TypeInfo.EnumField;
18pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_default: ?Data) type {18pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_default: ?Data) type {
19 const StructField = std.builtin.TypeInfo.StructField;19 const StructField = std.builtin.TypeInfo.StructField;
20 var fields: []const StructField = &[_]StructField{};20 var fields: []const StructField = &[_]StructField{};
21 for (std.meta.fields(E)) |field, i| {21 for (std.meta.fields(E)) |field| {
22 fields = fields ++ &[_]StructField{.{22 fields = fields ++ &[_]StructField{.{
23 .name = field.name,23 .name = field.name,
24 .field_type = Data,24 .field_type = Data,
...@@ -144,7 +144,7 @@ pub fn directEnumArrayDefault(...@@ -144,7 +144,7 @@ pub fn directEnumArrayDefault(
144) [directEnumArrayLen(E, max_unused_slots)]Data {144) [directEnumArrayLen(E, max_unused_slots)]Data {
145 const len = comptime directEnumArrayLen(E, max_unused_slots);145 const len = comptime directEnumArrayLen(E, max_unused_slots);
146 var result: [len]Data = if (default) |d| [_]Data{d} ** len else undefined;146 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| {
148 const enum_value = @field(E, f.name);148 const enum_value = @field(E, f.name);
149 const index = @intCast(usize, @enumToInt(enum_value));149 const index = @intCast(usize, @enumToInt(enum_value));
150 result[index] = @field(init_values, f.name);150 result[index] = @field(init_values, f.name);
...@@ -334,6 +334,7 @@ pub fn EnumArray(comptime E: type, comptime V: type) type {...@@ -334,6 +334,7 @@ pub fn EnumArray(comptime E: type, comptime V: type) type {
334/// TODO: Once #8169 is fixed, consider switching this param334/// TODO: Once #8169 is fixed, consider switching this param
335/// back to an optional.335/// back to an optional.
336pub fn NoExtension(comptime Self: type) type {336pub fn NoExtension(comptime Self: type) type {
337 _ = Self;
337 return NoExt;338 return NoExt;
338}339}
339const NoExt = struct {};340const NoExt = struct {};
...@@ -729,6 +730,7 @@ test "std.enums.ensureIndexer" {...@@ -729,6 +730,7 @@ test "std.enums.ensureIndexer" {
729}730}
730731
731fn ascByValue(ctx: void, comptime a: EnumField, comptime b: EnumField) bool {732fn ascByValue(ctx: void, comptime a: EnumField, comptime b: EnumField) bool {
733 _ = ctx;
732 return a.value < b.value;734 return a.value < b.value;
733}735}
734pub fn EnumIndexer(comptime E: type) type {736pub fn EnumIndexer(comptime E: type) type {
...@@ -743,9 +745,11 @@ pub fn EnumIndexer(comptime E: type) type {...@@ -743,9 +745,11 @@ pub fn EnumIndexer(comptime E: type) type {
743 pub const Key = E;745 pub const Key = E;
744 pub const count: usize = 0;746 pub const count: usize = 0;
745 pub fn indexOf(e: E) usize {747 pub fn indexOf(e: E) usize {
748 _ = e;
746 unreachable;749 unreachable;
747 }750 }
748 pub fn keyForIndex(i: usize) E {751 pub fn keyForIndex(i: usize) E {
752 _ = i;
749 unreachable;753 unreachable;
750 }754 }
751 };755 };
...@@ -753,10 +757,11 @@ pub fn EnumIndexer(comptime E: type) type {...@@ -753,10 +757,11 @@ pub fn EnumIndexer(comptime E: type) type {
753 std.sort.sort(EnumField, &fields, {}, ascByValue);757 std.sort.sort(EnumField, &fields, {}, ascByValue);
754 const min = fields[0].value;758 const min = fields[0].value;
755 const max = fields[fields.len - 1].value;759 const max = fields[fields.len - 1].value;
760 const fields_len = fields.len;
756 if (max - min == fields.len - 1) {761 if (max - min == fields.len - 1) {
757 return struct {762 return struct {
758 pub const Key = E;763 pub const Key = E;
759 pub const count = fields.len;764 pub const count = fields_len;
760 pub fn indexOf(e: E) usize {765 pub fn indexOf(e: E) usize {
761 return @intCast(usize, @enumToInt(e) - min);766 return @intCast(usize, @enumToInt(e) - min);
762 }767 }
...@@ -774,7 +779,7 @@ pub fn EnumIndexer(comptime E: type) type {...@@ -774,7 +779,7 @@ pub fn EnumIndexer(comptime E: type) type {
774779
775 return struct {780 return struct {
776 pub const Key = E;781 pub const Key = E;
777 pub const count = fields.len;782 pub const count = fields_len;
778 pub fn indexOf(e: E) usize {783 pub fn indexOf(e: E) usize {
779 for (keys) |k, i| {784 for (keys) |k, i| {
780 if (k == e) return i;785 if (k == e) return i;
lib/std/event/channel.zig-1
...@@ -308,7 +308,6 @@ test "std.event.Channel wraparound" {...@@ -308,7 +308,6 @@ test "std.event.Channel wraparound" {
308308
309 // add items to channel and pull them out until309 // add items to channel and pull them out until
310 // the buffer wraps around, make sure it doesn't crash.310 // the buffer wraps around, make sure it doesn't crash.
311 var result: i32 = undefined;
312 channel.put(5);311 channel.put(5);
313 try testing.expectEqual(@as(i32, 5), channel.get());312 try testing.expectEqual(@as(i32, 5), channel.get());
314 channel.put(6);313 channel.put(6);
lib/std/event/group.zig+1-1
...@@ -130,7 +130,7 @@ test "std.event.Group" {...@@ -130,7 +130,7 @@ test "std.event.Group" {
130 // TODO this file has bit-rotted. repair it130 // TODO this file has bit-rotted. repair it
131 if (true) return error.SkipZigTest;131 if (true) return error.SkipZigTest;
132132
133 const handle = async testGroup(std.heap.page_allocator);133 _ = async testGroup(std.heap.page_allocator);
134}134}
135fn testGroup(allocator: *Allocator) callconv(.Async) void {135fn testGroup(allocator: *Allocator) callconv(.Async) void {
136 var count: usize = 0;136 var count: usize = 0;
lib/std/event/loop.zig+2-2
...@@ -345,7 +345,7 @@ pub const Loop = struct {...@@ -345,7 +345,7 @@ pub const Loop = struct {
345 );345 );
346 errdefer windows.CloseHandle(self.os_data.io_port);346 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| {
349 eventfd_node.* = std.atomic.Stack(ResumeNode.EventFd).Node{349 eventfd_node.* = std.atomic.Stack(ResumeNode.EventFd).Node{
350 .data = ResumeNode.EventFd{350 .data = ResumeNode.EventFd{
351 .base = ResumeNode{351 .base = ResumeNode{
...@@ -680,7 +680,7 @@ pub const Loop = struct {...@@ -680,7 +680,7 @@ pub const Loop = struct {
680 fn run(func_args: Args, loop: *Loop, allocator: *mem.Allocator) void {680 fn run(func_args: Args, loop: *Loop, allocator: *mem.Allocator) void {
681 loop.beginOneEvent();681 loop.beginOneEvent();
682 loop.yield();682 loop.yield();
683 const result = @call(.{}, func, func_args);683 @call(.{}, func, func_args); // compile error when called with non-void ret type
684 suspend {684 suspend {
685 loop.finishOneEvent();685 loop.finishOneEvent();
686 allocator.destroy(@frame());686 allocator.destroy(@frame());
lib/std/event/rwlock.zig+1-1
...@@ -225,7 +225,7 @@ test "std.event.RwLock" {...@@ -225,7 +225,7 @@ test "std.event.RwLock" {
225 var lock = RwLock.init();225 var lock = RwLock.init();
226 defer lock.deinit();226 defer lock.deinit();
227227
228 const handle = testLock(std.heap.page_allocator, &lock);228 _ = testLock(std.heap.page_allocator, &lock);
229229
230 const expected_result = [1]i32{shared_it_count * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;230 const expected_result = [1]i32{shared_it_count * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;
231 try testing.expectEqualSlices(i32, expected_result, shared_test_data);231 try testing.expectEqualSlices(i32, expected_result, shared_test_data);
lib/std/fmt.zig+14-4
...@@ -369,6 +369,7 @@ pub fn format(...@@ -369,6 +369,7 @@ pub fn format(
369}369}
370370
371pub fn formatAddress(value: anytype, options: FormatOptions, writer: anytype) @TypeOf(writer).Error!void {371pub fn formatAddress(value: anytype, options: FormatOptions, writer: anytype) @TypeOf(writer).Error!void {
372 _ = options;
372 const T = @TypeOf(value);373 const T = @TypeOf(value);
373374
374 switch (@typeInfo(T)) {375 switch (@typeInfo(T)) {
...@@ -553,7 +554,7 @@ pub fn formatType(...@@ -553,7 +554,7 @@ pub fn formatType(
553 .Many, .C => {554 .Many, .C => {
554 if (actual_fmt.len == 0)555 if (actual_fmt.len == 0)
555 @compileError("cannot format pointer without a specifier (i.e. {s} or {*})");556 @compileError("cannot format pointer without a specifier (i.e. {s} or {*})");
556 if (ptr_info.sentinel) |sentinel| {557 if (ptr_info.sentinel) |_| {
557 return formatType(mem.span(value), actual_fmt, options, writer, max_depth);558 return formatType(mem.span(value), actual_fmt, options, writer, max_depth);
558 }559 }
559 if (ptr_info.child == u8) {560 if (ptr_info.child == u8) {
...@@ -741,6 +742,8 @@ fn formatSliceHexImpl(comptime case: Case) type {...@@ -741,6 +742,8 @@ fn formatSliceHexImpl(comptime case: Case) type {
741 options: std.fmt.FormatOptions,742 options: std.fmt.FormatOptions,
742 writer: anytype,743 writer: anytype,
743 ) !void {744 ) !void {
745 _ = fmt;
746 _ = options;
744 var buf: [2]u8 = undefined;747 var buf: [2]u8 = undefined;
745748
746 for (bytes) |c| {749 for (bytes) |c| {
...@@ -777,6 +780,8 @@ fn formatSliceEscapeImpl(comptime case: Case) type {...@@ -777,6 +780,8 @@ fn formatSliceEscapeImpl(comptime case: Case) type {
777 options: std.fmt.FormatOptions,780 options: std.fmt.FormatOptions,
778 writer: anytype,781 writer: anytype,
779 ) !void {782 ) !void {
783 _ = fmt;
784 _ = options;
780 var buf: [4]u8 = undefined;785 var buf: [4]u8 = undefined;
781786
782 buf[0] = '\\';787 buf[0] = '\\';
...@@ -820,6 +825,7 @@ fn formatSizeImpl(comptime radix: comptime_int) type {...@@ -820,6 +825,7 @@ fn formatSizeImpl(comptime radix: comptime_int) type {
820 options: FormatOptions,825 options: FormatOptions,
821 writer: anytype,826 writer: anytype,
822 ) !void {827 ) !void {
828 _ = fmt;
823 if (value == 0) {829 if (value == 0) {
824 return writer.writeAll("0B");830 return writer.writeAll("0B");
825 }831 }
...@@ -903,6 +909,7 @@ pub fn formatAsciiChar(...@@ -903,6 +909,7 @@ pub fn formatAsciiChar(
903 options: FormatOptions,909 options: FormatOptions,
904 writer: anytype,910 writer: anytype,
905) !void {911) !void {
912 _ = options;
906 return writer.writeAll(@as(*const [1]u8, &c));913 return writer.writeAll(@as(*const [1]u8, &c));
907}914}
908915
...@@ -1140,7 +1147,7 @@ pub fn formatFloatHexadecimal(...@@ -1140,7 +1147,7 @@ pub fn formatFloatHexadecimal(
11401147
1141 // +1 for the decimal part.1148 // +1 for the decimal part.
1142 var buf: [1 + mantissa_digits]u8 = undefined;1149 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
1145 try writer.writeAll("0x");1152 try writer.writeAll("0x");
1146 try writer.writeByte(buf[0]);1153 try writer.writeByte(buf[0]);
...@@ -1362,6 +1369,8 @@ pub fn formatIntBuf(out_buf: []u8, value: anytype, base: u8, case: Case, options...@@ -1362,6 +1369,8 @@ pub fn formatIntBuf(out_buf: []u8, value: anytype, base: u8, case: Case, options
1362}1369}
13631370
1364fn formatDuration(ns: u64, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {1371fn formatDuration(ns: u64, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
1372 _ = fmt;
1373 _ = options;
1365 var ns_remaining = ns;1374 var ns_remaining = ns;
1366 inline for (.{1375 inline for (.{
1367 .{ .ns = 365 * std.time.ns_per_day, .sep = 'y' },1376 .{ .ns = 365 * std.time.ns_per_day, .sep = 'y' },
...@@ -2152,6 +2161,7 @@ test "custom" {...@@ -2152,6 +2161,7 @@ test "custom" {
2152 options: FormatOptions,2161 options: FormatOptions,
2153 writer: anytype,2162 writer: anytype,
2154 ) !void {2163 ) !void {
2164 _ = options;
2155 if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "p")) {2165 if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "p")) {
2156 return std.fmt.format(writer, "({d:.3},{d:.3})", .{ self.x, self.y });2166 return std.fmt.format(writer, "({d:.3},{d:.3})", .{ self.x, self.y });
2157 } else if (comptime std.mem.eql(u8, fmt, "d")) {2167 } else if (comptime std.mem.eql(u8, fmt, "d")) {
...@@ -2162,7 +2172,6 @@ test "custom" {...@@ -2162,7 +2172,6 @@ test "custom" {
2162 }2172 }
2163 };2173 };
21642174
2165 var buf1: [32]u8 = undefined;
2166 var value = Vec2{2175 var value = Vec2{
2167 .x = 10.2,2176 .x = 10.2,
2168 .y = 2.22,2177 .y = 2.22,
...@@ -2220,7 +2229,7 @@ test "union" {...@@ -2220,7 +2229,7 @@ test "union" {
2220 try std.testing.expect(mem.eql(u8, uu_result[0..3], "UU@"));2229 try std.testing.expect(mem.eql(u8, uu_result[0..3], "UU@"));
22212230
2222 const eu_result = try bufPrint(buf[0..], "{}", .{eu_inst});2231 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@"));
2224}2233}
22252234
2226test "enum" {2235test "enum" {
...@@ -2341,6 +2350,7 @@ test "formatType max_depth" {...@@ -2341,6 +2350,7 @@ test "formatType max_depth" {
2341 options: FormatOptions,2350 options: FormatOptions,
2342 writer: anytype,2351 writer: anytype,
2343 ) !void {2352 ) !void {
2353 _ = options;
2344 if (fmt.len == 0) {2354 if (fmt.len == 0) {
2345 return std.fmt.format(writer, "({d:.3},{d:.3})", .{ self.x, self.y });2355 return std.fmt.format(writer, "({d:.3},{d:.3})", .{ self.x, self.y });
2346 } else {2356 } else {
lib/std/fmt/parse_float.zig-1
...@@ -200,7 +200,6 @@ const ParseResult = enum {...@@ -200,7 +200,6 @@ const ParseResult = enum {
200200
201fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {201fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
202 var digit_index: usize = 0;202 var digit_index: usize = 0;
203 var negative = false;
204 var negative_exp = false;203 var negative_exp = false;
205 var exponent: i32 = 0;204 var exponent: i32 = 0;
206205
lib/std/fs.zig+4-3
...@@ -477,7 +477,7 @@ pub const Dir = struct {...@@ -477,7 +477,7 @@ pub const Dir = struct {
477 }477 }
478478
479 var stat_info: os.libc_stat = undefined;479 var stat_info: os.libc_stat = undefined;
480 const rc2 = os.system._kern_read_stat(480 _ = os.system._kern_read_stat(
481 self.dir.fd,481 self.dir.fd,
482 &haiku_entry.d_name,482 &haiku_entry.d_name,
483 false,483 false,
...@@ -1541,7 +1541,7 @@ pub const Dir = struct {...@@ -1541,7 +1541,7 @@ pub const Dir = struct {
1541 self: Dir,1541 self: Dir,
1542 target_path: []const u8,1542 target_path: []const u8,
1543 sym_link_path: []const u8,1543 sym_link_path: []const u8,
1544 flags: SymLinkFlags,1544 _: SymLinkFlags,
1545 ) !void {1545 ) !void {
1546 return os.symlinkatWasi(target_path, self.fd, sym_link_path);1546 return os.symlinkatWasi(target_path, self.fd, sym_link_path);
1547 }1547 }
...@@ -1879,6 +1879,7 @@ pub const Dir = struct {...@@ -1879,6 +1879,7 @@ pub const Dir = struct {
1879 /// * NtDll prefixed1879 /// * NtDll prefixed
1880 /// TODO currently this ignores `flags`.1880 /// TODO currently this ignores `flags`.
1881 pub fn accessW(self: Dir, sub_path_w: [*:0]const u16, flags: File.OpenFlags) AccessError!void {1881 pub fn accessW(self: Dir, sub_path_w: [*:0]const u16, flags: File.OpenFlags) AccessError!void {
1882 _ = flags;
1882 return os.faccessatW(self.fd, sub_path_w, 0, 0);1883 return os.faccessatW(self.fd, sub_path_w, 0, 0);
1883 }1884 }
18841885
...@@ -2438,7 +2439,7 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {...@@ -2438,7 +2439,7 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
2438 }) catch continue;2439 }) catch continue;
24392440
2440 var real_path_buf: [MAX_PATH_BYTES]u8 = undefined;2441 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| {
2442 // found a file, and hope it is the right file2443 // found a file, and hope it is the right file
2443 if (real_path.len > out_buffer.len)2444 if (real_path.len > out_buffer.len)
2444 return error.NameTooLong;2445 return error.NameTooLong;
lib/std/fs/path.zig+2-2
...@@ -579,7 +579,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {...@@ -579,7 +579,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
579 // Now we know the disk designator to use, if any, and what kind it is. And our result579 // Now we know the disk designator to use, if any, and what kind it is. And our result
580 // is big enough to append all the paths to.580 // is big enough to append all the paths to.
581 var correct_disk_designator = true;581 var correct_disk_designator = true;
582 for (paths[first_index..]) |p, i| {582 for (paths[first_index..]) |p| {
583 const parsed = windowsParsePath(p);583 const parsed = windowsParsePath(p);
584584
585 if (parsed.kind != WindowsPath.Kind.None) {585 if (parsed.kind != WindowsPath.Kind.None) {
...@@ -660,7 +660,7 @@ pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {...@@ -660,7 +660,7 @@ pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
660 }660 }
661 errdefer allocator.free(result);661 errdefer allocator.free(result);
662662
663 for (paths[first_index..]) |p, i| {663 for (paths[first_index..]) |p| {
664 var it = mem.tokenize(p, "/");664 var it = mem.tokenize(p, "/");
665 while (it.next()) |component| {665 while (it.next()) |component| {
666 if (mem.eql(u8, component, ".")) {666 if (mem.eql(u8, component, ".")) {
lib/std/fs/test.zig+2
...@@ -541,6 +541,7 @@ test "makePath, put some files in it, deleteTree" {...@@ -541,6 +541,7 @@ test "makePath, put some files in it, deleteTree" {
541 try tmp.dir.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "file2.txt", "blah");541 try tmp.dir.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "file2.txt", "blah");
542 try tmp.dir.deleteTree("os_test_tmp");542 try tmp.dir.deleteTree("os_test_tmp");
543 if (tmp.dir.openDir("os_test_tmp", .{})) |dir| {543 if (tmp.dir.openDir("os_test_tmp", .{})) |dir| {
544 _ = dir;
544 @panic("expected error");545 @panic("expected error");
545 } else |err| {546 } else |err| {
546 try testing.expect(err == error.FileNotFound);547 try testing.expect(err == error.FileNotFound);
...@@ -638,6 +639,7 @@ test "access file" {...@@ -638,6 +639,7 @@ test "access file" {
638639
639 try tmp.dir.makePath("os_test_tmp");640 try tmp.dir.makePath("os_test_tmp");
640 if (tmp.dir.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", .{})) |ok| {641 if (tmp.dir.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", .{})) |ok| {
642 _ = ok;
641 @panic("expected error");643 @panic("expected error");
642 } else |err| {644 } else |err| {
643 try testing.expect(err == error.FileNotFound);645 try testing.expect(err == error.FileNotFound);
lib/std/fs/wasi.zig+2
...@@ -36,6 +36,8 @@ pub const PreopenType = union(PreopenTypeTag) {...@@ -36,6 +36,8 @@ pub const PreopenType = union(PreopenTypeTag) {
36 }36 }
3737
38 pub fn format(self: Self, comptime fmt: []const u8, options: std.fmt.FormatOptions, out_stream: anytype) !void {38 pub fn format(self: Self, comptime fmt: []const u8, options: std.fmt.FormatOptions, out_stream: anytype) !void {
39 _ = fmt;
40 _ = options;
39 try out_stream.print("PreopenType{{ ", .{});41 try out_stream.print("PreopenType{{ ", .{});
40 switch (self) {42 switch (self) {
41 PreopenType.Dir => |path| try out_stream.print(".Dir = '{}'", .{std.zig.fmtId(path)}),43 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 {...@@ -353,7 +353,6 @@ fn SMHasherTest(comptime hash_fn: anytype) u32 {
353353
354 var key: [256]u8 = undefined;354 var key: [256]u8 = undefined;
355 var hashes_bytes: [256 * @sizeOf(HashResult)]u8 = undefined;355 var hashes_bytes: [256 * @sizeOf(HashResult)]u8 = undefined;
356 var final: HashResult = 0;
357356
358 std.mem.set(u8, &key, 0);357 std.mem.set(u8, &key, 0);
359 std.mem.set(u8, &hashes_bytes, 0);358 std.mem.set(u8, &hashes_bytes, 0);
...@@ -376,6 +375,7 @@ fn SMHasherTest(comptime hash_fn: anytype) u32 {...@@ -376,6 +375,7 @@ fn SMHasherTest(comptime hash_fn: anytype) u32 {
376}375}
377376
378fn CityHash32hashIgnoreSeed(str: []const u8, seed: u32) u32 {377fn CityHash32hashIgnoreSeed(str: []const u8, seed: u32) u32 {
378 _ = seed;
379 return CityHash32.hash(str);379 return CityHash32.hash(str);
380}380}
381381
lib/std/hash/wyhash.zig-2
...@@ -166,8 +166,6 @@ pub const Wyhash = struct {...@@ -166,8 +166,6 @@ pub const Wyhash = struct {
166 }166 }
167167
168 pub fn final(self: *Wyhash) u64 {168 pub fn final(self: *Wyhash) u64 {
169 const seed = self.state.seed;
170 const rem_len = @intCast(u5, self.buf_len);
171 const rem_key = self.buf[0..self.buf_len];169 const rem_key = self.buf[0..self.buf_len];
172170
173 return self.state.final(rem_key);171 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)...@@ -29,6 +29,7 @@ pub fn getAutoHashFn(comptime K: type, comptime Context: type) (fn (Context, K)
2929
30 return struct {30 return struct {
31 fn hash(ctx: Context, key: K) u64 {31 fn hash(ctx: Context, key: K) u64 {
32 _ = ctx;
32 if (comptime trait.hasUniqueRepresentation(K)) {33 if (comptime trait.hasUniqueRepresentation(K)) {
33 return Wyhash.hash(0, std.mem.asBytes(&key));34 return Wyhash.hash(0, std.mem.asBytes(&key));
34 } else {35 } else {
...@@ -43,6 +44,7 @@ pub fn getAutoHashFn(comptime K: type, comptime Context: type) (fn (Context, K)...@@ -43,6 +44,7 @@ pub fn getAutoHashFn(comptime K: type, comptime Context: type) (fn (Context, K)
43pub fn getAutoEqlFn(comptime K: type, comptime Context: type) (fn (Context, K, K) bool) {44pub fn getAutoEqlFn(comptime K: type, comptime Context: type) (fn (Context, K, K) bool) {
44 return struct {45 return struct {
45 fn eql(ctx: Context, a: K, b: K) bool {46 fn eql(ctx: Context, a: K, b: K) bool {
47 _ = ctx;
46 return meta.eql(a, b);48 return meta.eql(a, b);
47 }49 }
48 }.eql;50 }.eql;
...@@ -78,9 +80,11 @@ pub fn StringHashMapUnmanaged(comptime V: type) type {...@@ -78,9 +80,11 @@ pub fn StringHashMapUnmanaged(comptime V: type) type {
7880
79pub const StringContext = struct {81pub const StringContext = struct {
80 pub fn hash(self: @This(), s: []const u8) u64 {82 pub fn hash(self: @This(), s: []const u8) u64 {
83 _ = self;
81 return hashString(s);84 return hashString(s);
82 }85 }
83 pub fn eql(self: @This(), a: []const u8, b: []const u8) bool {86 pub fn eql(self: @This(), a: []const u8, b: []const u8) bool {
87 _ = self;
84 return eqlString(a, b);88 return eqlString(a, b);
85 }89 }
86};90};
...@@ -1809,7 +1813,7 @@ test "std.hash_map getOrPut" {...@@ -1809,7 +1813,7 @@ test "std.hash_map getOrPut" {
18091813
1810 i = 0;1814 i = 0;
1811 while (i < 20) : (i += 1) {1815 while (i < 20) : (i += 1) {
1812 var n = try map.getOrPutValue(i, 1);1816 _ = try map.getOrPutValue(i, 1);
1813 }1817 }
18141818
1815 i = 0;1819 i = 0;
...@@ -1887,9 +1891,11 @@ test "std.hash_map clone" {...@@ -1887,9 +1891,11 @@ test "std.hash_map clone" {
1887test "std.hash_map getOrPutAdapted" {1891test "std.hash_map getOrPutAdapted" {
1888 const AdaptedContext = struct {1892 const AdaptedContext = struct {
1889 fn eql(self: @This(), adapted_key: []const u8, test_key: u64) bool {1893 fn eql(self: @This(), adapted_key: []const u8, test_key: u64) bool {
1894 _ = self;
1890 return std.fmt.parseInt(u64, adapted_key, 10) catch unreachable == test_key;1895 return std.fmt.parseInt(u64, adapted_key, 10) catch unreachable == test_key;
1891 }1896 }
1892 fn hash(self: @This(), adapted_key: []const u8) u64 {1897 fn hash(self: @This(), adapted_key: []const u8) u64 {
1898 _ = self;
1893 const key = std.fmt.parseInt(u64, adapted_key, 10) catch unreachable;1899 const key = std.fmt.parseInt(u64, adapted_key, 10) catch unreachable;
1894 return (AutoContext(u64){}).hash(key);1900 return (AutoContext(u64){}).hash(key);
1895 }1901 }
lib/std/heap.zig+30
...@@ -108,6 +108,8 @@ const CAllocator = struct {...@@ -108,6 +108,8 @@ const CAllocator = struct {
108 len_align: u29,108 len_align: u29,
109 return_address: usize,109 return_address: usize,
110 ) error{OutOfMemory}![]u8 {110 ) error{OutOfMemory}![]u8 {
111 _ = allocator;
112 _ = return_address;
111 assert(len > 0);113 assert(len > 0);
112 assert(std.math.isPowerOfTwo(alignment));114 assert(std.math.isPowerOfTwo(alignment));
113115
...@@ -134,6 +136,9 @@ const CAllocator = struct {...@@ -134,6 +136,9 @@ const CAllocator = struct {
134 len_align: u29,136 len_align: u29,
135 return_address: usize,137 return_address: usize,
136 ) Allocator.Error!usize {138 ) Allocator.Error!usize {
139 _ = allocator;
140 _ = buf_align;
141 _ = return_address;
137 if (new_len == 0) {142 if (new_len == 0) {
138 alignedFree(buf.ptr);143 alignedFree(buf.ptr);
139 return 0;144 return 0;
...@@ -178,6 +183,9 @@ fn rawCAlloc(...@@ -178,6 +183,9 @@ fn rawCAlloc(
178 len_align: u29,183 len_align: u29,
179 ret_addr: usize,184 ret_addr: usize,
180) Allocator.Error![]u8 {185) Allocator.Error![]u8 {
186 _ = self;
187 _ = len_align;
188 _ = ret_addr;
181 assert(ptr_align <= @alignOf(std.c.max_align_t));189 assert(ptr_align <= @alignOf(std.c.max_align_t));
182 const ptr = @ptrCast([*]u8, c.malloc(len) orelse return error.OutOfMemory);190 const ptr = @ptrCast([*]u8, c.malloc(len) orelse return error.OutOfMemory);
183 return ptr[0..len];191 return ptr[0..len];
...@@ -191,6 +199,9 @@ fn rawCResize(...@@ -191,6 +199,9 @@ fn rawCResize(
191 len_align: u29,199 len_align: u29,
192 ret_addr: usize,200 ret_addr: usize,
193) Allocator.Error!usize {201) Allocator.Error!usize {
202 _ = self;
203 _ = old_align;
204 _ = ret_addr;
194 if (new_len == 0) {205 if (new_len == 0) {
195 c.free(buf.ptr);206 c.free(buf.ptr);
196 return 0;207 return 0;
...@@ -231,6 +242,8 @@ pub var next_mmap_addr_hint: ?[*]align(mem.page_size) u8 = null;...@@ -231,6 +242,8 @@ pub var next_mmap_addr_hint: ?[*]align(mem.page_size) u8 = null;
231242
232const PageAllocator = struct {243const PageAllocator = struct {
233 fn alloc(allocator: *Allocator, n: usize, alignment: u29, len_align: u29, ra: usize) error{OutOfMemory}![]u8 {244 fn alloc(allocator: *Allocator, n: usize, alignment: u29, len_align: u29, ra: usize) error{OutOfMemory}![]u8 {
245 _ = allocator;
246 _ = ra;
234 assert(n > 0);247 assert(n > 0);
235 const aligned_len = mem.alignForward(n, mem.page_size);248 const aligned_len = mem.alignForward(n, mem.page_size);
236249
...@@ -334,6 +347,9 @@ const PageAllocator = struct {...@@ -334,6 +347,9 @@ const PageAllocator = struct {
334 len_align: u29,347 len_align: u29,
335 return_address: usize,348 return_address: usize,
336 ) Allocator.Error!usize {349 ) Allocator.Error!usize {
350 _ = allocator;
351 _ = buf_align;
352 _ = return_address;
337 const new_size_aligned = mem.alignForward(new_size, mem.page_size);353 const new_size_aligned = mem.alignForward(new_size, mem.page_size);
338354
339 if (builtin.os.tag == .windows) {355 if (builtin.os.tag == .windows) {
...@@ -482,6 +498,8 @@ const WasmPageAllocator = struct {...@@ -482,6 +498,8 @@ const WasmPageAllocator = struct {
482 }498 }
483499
484 fn alloc(allocator: *Allocator, len: usize, alignment: u29, len_align: u29, ra: usize) error{OutOfMemory}![]u8 {500 fn alloc(allocator: *Allocator, len: usize, alignment: u29, len_align: u29, ra: usize) error{OutOfMemory}![]u8 {
501 _ = allocator;
502 _ = ra;
485 const page_count = nPages(len);503 const page_count = nPages(len);
486 const page_idx = try allocPages(page_count, alignment);504 const page_idx = try allocPages(page_count, alignment);
487 return @intToPtr([*]u8, page_idx * mem.page_size)[0..alignPageAllocLen(page_count * mem.page_size, len, len_align)];505 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 {...@@ -542,6 +560,9 @@ const WasmPageAllocator = struct {
542 len_align: u29,560 len_align: u29,
543 return_address: usize,561 return_address: usize,
544 ) error{OutOfMemory}!usize {562 ) error{OutOfMemory}!usize {
563 _ = allocator;
564 _ = buf_align;
565 _ = return_address;
545 const aligned_len = mem.alignForward(buf.len, mem.page_size);566 const aligned_len = mem.alignForward(buf.len, mem.page_size);
546 if (new_len > aligned_len) return error.OutOfMemory;567 if (new_len > aligned_len) return error.OutOfMemory;
547 const current_n = nPages(aligned_len);568 const current_n = nPages(aligned_len);
...@@ -588,6 +609,7 @@ pub const HeapAllocator = switch (builtin.os.tag) {...@@ -588,6 +609,7 @@ pub const HeapAllocator = switch (builtin.os.tag) {
588 len_align: u29,609 len_align: u29,
589 return_address: usize,610 return_address: usize,
590 ) error{OutOfMemory}![]u8 {611 ) error{OutOfMemory}![]u8 {
612 _ = return_address;
591 const self = @fieldParentPtr(HeapAllocator, "allocator", allocator);613 const self = @fieldParentPtr(HeapAllocator, "allocator", allocator);
592614
593 const amt = n + ptr_align - 1 + @sizeOf(usize);615 const amt = n + ptr_align - 1 + @sizeOf(usize);
...@@ -622,6 +644,8 @@ pub const HeapAllocator = switch (builtin.os.tag) {...@@ -622,6 +644,8 @@ pub const HeapAllocator = switch (builtin.os.tag) {
622 len_align: u29,644 len_align: u29,
623 return_address: usize,645 return_address: usize,
624 ) error{OutOfMemory}!usize {646 ) error{OutOfMemory}!usize {
647 _ = buf_align;
648 _ = return_address;
625 const self = @fieldParentPtr(HeapAllocator, "allocator", allocator);649 const self = @fieldParentPtr(HeapAllocator, "allocator", allocator);
626 if (new_size == 0) {650 if (new_size == 0) {
627 os.windows.HeapFree(self.heap_handle.?, 0, @intToPtr(*c_void, getRecordPtr(buf).*));651 os.windows.HeapFree(self.heap_handle.?, 0, @intToPtr(*c_void, getRecordPtr(buf).*));
...@@ -694,6 +718,8 @@ pub const FixedBufferAllocator = struct {...@@ -694,6 +718,8 @@ pub const FixedBufferAllocator = struct {
694 }718 }
695719
696 fn alloc(allocator: *Allocator, n: usize, ptr_align: u29, len_align: u29, ra: usize) ![]u8 {720 fn alloc(allocator: *Allocator, n: usize, ptr_align: u29, len_align: u29, ra: usize) ![]u8 {
721 _ = len_align;
722 _ = ra;
697 const self = @fieldParentPtr(FixedBufferAllocator, "allocator", allocator);723 const self = @fieldParentPtr(FixedBufferAllocator, "allocator", allocator);
698 const adjust_off = mem.alignPointerOffset(self.buffer.ptr + self.end_index, ptr_align) orelse724 const adjust_off = mem.alignPointerOffset(self.buffer.ptr + self.end_index, ptr_align) orelse
699 return error.OutOfMemory;725 return error.OutOfMemory;
...@@ -716,6 +742,8 @@ pub const FixedBufferAllocator = struct {...@@ -716,6 +742,8 @@ pub const FixedBufferAllocator = struct {
716 len_align: u29,742 len_align: u29,
717 return_address: usize,743 return_address: usize,
718 ) Allocator.Error!usize {744 ) Allocator.Error!usize {
745 _ = buf_align;
746 _ = return_address;
719 const self = @fieldParentPtr(FixedBufferAllocator, "allocator", allocator);747 const self = @fieldParentPtr(FixedBufferAllocator, "allocator", allocator);
720 assert(self.ownsSlice(buf)); // sanity check748 assert(self.ownsSlice(buf)); // sanity check
721749
...@@ -766,6 +794,8 @@ pub const ThreadSafeFixedBufferAllocator = blk: {...@@ -766,6 +794,8 @@ pub const ThreadSafeFixedBufferAllocator = blk: {
766 }794 }
767795
768 fn alloc(allocator: *Allocator, n: usize, ptr_align: u29, len_align: u29, ra: usize) ![]u8 {796 fn alloc(allocator: *Allocator, n: usize, ptr_align: u29, len_align: u29, ra: usize) ![]u8 {
797 _ = len_align;
798 _ = ra;
769 const self = @fieldParentPtr(ThreadSafeFixedBufferAllocator, "allocator", allocator);799 const self = @fieldParentPtr(ThreadSafeFixedBufferAllocator, "allocator", allocator);
770 var end_index = @atomicLoad(usize, &self.end_index, builtin.AtomicOrder.SeqCst);800 var end_index = @atomicLoad(usize, &self.end_index, builtin.AtomicOrder.SeqCst);
771 while (true) {801 while (true) {
lib/std/heap/arena_allocator.zig+5
...@@ -66,6 +66,8 @@ pub const ArenaAllocator = struct {...@@ -66,6 +66,8 @@ pub const ArenaAllocator = struct {
66 }66 }
6767
68 fn alloc(allocator: *Allocator, n: usize, ptr_align: u29, len_align: u29, ra: usize) ![]u8 {68 fn alloc(allocator: *Allocator, n: usize, ptr_align: u29, len_align: u29, ra: usize) ![]u8 {
69 _ = len_align;
70 _ = ra;
69 const self = @fieldParentPtr(ArenaAllocator, "allocator", allocator);71 const self = @fieldParentPtr(ArenaAllocator, "allocator", allocator);
7072
71 var cur_node = if (self.state.buffer_list.first) |first_node| first_node else try self.createNode(0, n + ptr_align);73 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 {...@@ -95,6 +97,9 @@ pub const ArenaAllocator = struct {
95 }97 }
9698
97 fn resize(allocator: *Allocator, buf: []u8, buf_align: u29, new_len: usize, len_align: u29, ret_addr: usize) Allocator.Error!usize {99 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;
98 const self = @fieldParentPtr(ArenaAllocator, "allocator", allocator);103 const self = @fieldParentPtr(ArenaAllocator, "allocator", allocator);
99104
100 const cur_node = self.state.buffer_list.first orelse return error.OutOfMemory;105 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 {...@@ -37,9 +37,9 @@ pub fn LogToWriterAllocator(comptime Writer: type) type {
37 const self = @fieldParentPtr(Self, "allocator", allocator);37 const self = @fieldParentPtr(Self, "allocator", allocator);
38 self.writer.print("alloc : {}", .{len}) catch {};38 self.writer.print("alloc : {}", .{len}) catch {};
39 const result = self.parent_allocator.allocFn(self.parent_allocator, len, ptr_align, len_align, ra);39 const result = self.parent_allocator.allocFn(self.parent_allocator, len, ptr_align, len_align, ra);
40 if (result) |buff| {40 if (result) |_| {
41 self.writer.print(" success!\n", .{}) catch {};41 self.writer.print(" success!\n", .{}) catch {};
42 } else |err| {42 } else |_| {
43 self.writer.print(" failure!\n", .{}) catch {};43 self.writer.print(" failure!\n", .{}) catch {};
44 }44 }
45 return result;45 return result;
lib/std/heap/logging_allocator.zig+1-1
...@@ -65,7 +65,7 @@ pub fn ScopedLoggingAllocator(...@@ -65,7 +65,7 @@ pub fn ScopedLoggingAllocator(
65 ) error{OutOfMemory}![]u8 {65 ) error{OutOfMemory}![]u8 {
66 const self = @fieldParentPtr(Self, "allocator", allocator);66 const self = @fieldParentPtr(Self, "allocator", allocator);
67 const result = self.parent_allocator.allocFn(self.parent_allocator, len, ptr_align, len_align, ra);67 const result = self.parent_allocator.allocFn(self.parent_allocator, len, ptr_align, len_align, ra);
68 if (result) |buff| {68 if (result) |_| {
69 logHelper(69 logHelper(
70 success_log_level,70 success_log_level,
71 "alloc - success - len: {}, ptr_align: {}, len_align: {}",71 "alloc - success - len: {}, ptr_align: {}, len_align: {}",
lib/std/io.zig+1
...@@ -161,6 +161,7 @@ pub const null_writer = @as(NullWriter, .{ .context = {} });...@@ -161,6 +161,7 @@ pub const null_writer = @as(NullWriter, .{ .context = {} });
161161
162const NullWriter = Writer(void, error{}, dummyWrite);162const NullWriter = Writer(void, error{}, dummyWrite);
163fn dummyWrite(context: void, data: []const u8) error{}!usize {163fn dummyWrite(context: void, data: []const u8) error{}!usize {
164 _ = context;
164 return data.len;165 return data.len;
165}166}
166167
lib/std/io/bit_reader.zig+1-1
...@@ -149,7 +149,7 @@ pub fn BitReader(endian: builtin.Endian, comptime ReaderType: type) type {...@@ -149,7 +149,7 @@ pub fn BitReader(endian: builtin.Endian, comptime ReaderType: type) type {
149 var out_bits_total = @as(usize, 0);149 var out_bits_total = @as(usize, 0);
150 //@NOTE: I'm not sure this is a good idea, maybe alignToByte should be forced150 //@NOTE: I'm not sure this is a good idea, maybe alignToByte should be forced
151 if (self.bit_count > 0) {151 if (self.bit_count > 0) {
152 for (buffer) |*b, i| {152 for (buffer) |*b| {
153 b.* = try self.readBits(u8, u8_bit_count, &out_bits);153 b.* = try self.readBits(u8, u8_bit_count, &out_bits);
154 out_bits_total += out_bits;154 out_bits_total += out_bits;
155 }155 }
lib/std/io/bit_writer.zig+1-1
...@@ -128,7 +128,7 @@ pub fn BitWriter(endian: builtin.Endian, comptime WriterType: type) type {...@@ -128,7 +128,7 @@ pub fn BitWriter(endian: builtin.Endian, comptime WriterType: type) type {
128 pub fn write(self: *Self, buffer: []const u8) Error!usize {128 pub fn write(self: *Self, buffer: []const u8) Error!usize {
129 // TODO: I'm not sure this is a good idea, maybe flushBits should be forced129 // TODO: I'm not sure this is a good idea, maybe flushBits should be forced
130 if (self.bit_count > 0) {130 if (self.bit_count > 0) {
131 for (buffer) |b, i|131 for (buffer) |b|
132 try self.writeBits(b, u8_bit_count);132 try self.writeBits(b, u8_bit_count);
133 return buffer.len;133 return buffer.len;
134 }134 }
lib/std/json.zig+8-6
...@@ -1221,11 +1221,11 @@ test "json.token premature object close" {...@@ -1221,11 +1221,11 @@ test "json.token premature object close" {
1221pub fn validate(s: []const u8) bool {1221pub fn validate(s: []const u8) bool {
1222 var p = StreamingParser.init();1222 var p = StreamingParser.init();
12231223
1224 for (s) |c, i| {1224 for (s) |c| {
1225 var token1: ?Token = undefined;1225 var token1: ?Token = undefined;
1226 var token2: ?Token = undefined;1226 var token2: ?Token = undefined;
12271227
1228 p.feed(c, &token1, &token2) catch |err| {1228 p.feed(c, &token1, &token2) catch {
1229 return false;1229 return false;
1230 };1230 };
1231 }1231 }
...@@ -1410,7 +1410,7 @@ fn parsedEqual(a: anytype, b: @TypeOf(a)) bool {...@@ -1410,7 +1410,7 @@ fn parsedEqual(a: anytype, b: @TypeOf(a)) bool {
1410 if (a == null or b == null) return false;1410 if (a == null or b == null) return false;
1411 return parsedEqual(a.?, b.?);1411 return parsedEqual(a.?, b.?);
1412 },1412 },
1413 .Union => |unionInfo| {1413 .Union => {
1414 if (info.tag_type) |UnionTag| {1414 if (info.tag_type) |UnionTag| {
1415 const tag_a = std.meta.activeTag(a);1415 const tag_a = std.meta.activeTag(a);
1416 const tag_b = std.meta.activeTag(b);1416 const tag_b = std.meta.activeTag(b);
...@@ -1771,7 +1771,7 @@ fn parseInternal(comptime T: type, token: Token, tokens: *TokenStream, options:...@@ -1771,7 +1771,7 @@ fn parseInternal(comptime T: type, token: Token, tokens: *TokenStream, options:
1771 const source_slice = stringToken.slice(tokens.slice, tokens.i - 1);1771 const source_slice = stringToken.slice(tokens.slice, tokens.i - 1);
1772 switch (stringToken.escapes) {1772 switch (stringToken.escapes) {
1773 .None => return allocator.dupe(u8, source_slice),1773 .None => return allocator.dupe(u8, source_slice),
1774 .Some => |some_escapes| {1774 .Some => {
1775 const output = try allocator.alloc(u8, stringToken.decodedLength());1775 const output = try allocator.alloc(u8, stringToken.decodedLength());
1776 errdefer allocator.free(output);1776 errdefer allocator.free(output);
1777 try unescapeValidString(output, source_slice);1777 try unescapeValidString(output, source_slice);
...@@ -2391,7 +2391,7 @@ pub const Parser = struct {...@@ -2391,7 +2391,7 @@ pub const Parser = struct {
2391 const slice = s.slice(input, i);2391 const slice = s.slice(input, i);
2392 switch (s.escapes) {2392 switch (s.escapes) {
2393 .None => return Value{ .String = if (p.copy_strings) try allocator.dupe(u8, slice) else slice },2393 .None => return Value{ .String = if (p.copy_strings) try allocator.dupe(u8, slice) else slice },
2394 .Some => |some_escapes| {2394 .Some => {
2395 const output = try allocator.alloc(u8, s.decodedLength());2395 const output = try allocator.alloc(u8, s.decodedLength());
2396 errdefer allocator.free(output);2396 errdefer allocator.free(output);
2397 try unescapeValidString(output, slice);2397 try unescapeValidString(output, slice);
...@@ -2401,6 +2401,7 @@ pub const Parser = struct {...@@ -2401,6 +2401,7 @@ pub const Parser = struct {
2401 }2401 }
24022402
2403 fn parseNumber(p: *Parser, n: std.meta.TagPayload(Token, Token.Number), input: []const u8, i: usize) !Value {2403 fn parseNumber(p: *Parser, n: std.meta.TagPayload(Token, Token.Number), input: []const u8, i: usize) !Value {
2404 _ = p;
2404 return if (n.is_integer)2405 return if (n.is_integer)
2405 Value{2406 Value{
2406 .Integer = std.fmt.parseInt(i64, n.slice(input, i), 10) catch |e| switch (e) {2407 .Integer = std.fmt.parseInt(i64, n.slice(input, i), 10) catch |e| switch (e) {
...@@ -2815,7 +2816,7 @@ pub fn stringify(...@@ -2815,7 +2816,7 @@ pub fn stringify(
2815 if (child_options.whitespace) |*child_whitespace| {2816 if (child_options.whitespace) |*child_whitespace| {
2816 child_whitespace.indent_level += 1;2817 child_whitespace.indent_level += 1;
2817 }2818 }
2818 inline for (S.fields) |Field, field_i| {2819 inline for (S.fields) |Field| {
2819 // don't include void fields2820 // don't include void fields
2820 if (Field.field_type == void) continue;2821 if (Field.field_type == void) continue;
28212822
...@@ -3114,6 +3115,7 @@ test "stringify struct with custom stringifier" {...@@ -3114,6 +3115,7 @@ test "stringify struct with custom stringifier" {
3114 options: StringifyOptions,3115 options: StringifyOptions,
3115 out_stream: anytype,3116 out_stream: anytype,
3116 ) !void {3117 ) !void {
3118 _ = value;
3117 try out_stream.writeAll("[\"something special\",");3119 try out_stream.writeAll("[\"something special\",");
3118 try stringify(42, options, out_stream);3120 try stringify(42, options, out_stream);
3119 try out_stream.writeByte(']');3121 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...@@ -198,7 +198,7 @@ fn test_read_ileb128_seq(comptime T: type, comptime N: usize, encoded: []const u
198 var reader = std.io.fixedBufferStream(encoded);198 var reader = std.io.fixedBufferStream(encoded);
199 var i: usize = 0;199 var i: usize = 0;
200 while (i < N) : (i += 1) {200 while (i < N) : (i += 1) {
201 const v1 = try readILEB128(T, reader.reader());201 _ = try readILEB128(T, reader.reader());
202 }202 }
203}203}
204204
...@@ -206,7 +206,7 @@ fn test_read_uleb128_seq(comptime T: type, comptime N: usize, encoded: []const u...@@ -206,7 +206,7 @@ fn test_read_uleb128_seq(comptime T: type, comptime N: usize, encoded: []const u
206 var reader = std.io.fixedBufferStream(encoded);206 var reader = std.io.fixedBufferStream(encoded);
207 var i: usize = 0;207 var i: usize = 0;
208 while (i < N) : (i += 1) {208 while (i < N) : (i += 1) {
209 const v1 = try readULEB128(T, reader.reader());209 _ = try readULEB128(T, reader.reader());
210 }210 }
211}211}
212212
...@@ -309,7 +309,6 @@ fn test_write_leb128(value: anytype) !void {...@@ -309,7 +309,6 @@ fn test_write_leb128(value: anytype) !void {
309 const B = std.meta.Int(signedness, larger_type_bits);309 const B = std.meta.Int(signedness, larger_type_bits);
310310
311 const bytes_needed = bn: {311 const bytes_needed = bn: {
312 const S = std.meta.Int(signedness, @sizeOf(T) * 8);
313 if (@typeInfo(T).Int.bits <= 7) break :bn @as(u16, 1);312 if (@typeInfo(T).Int.bits <= 7) break :bn @as(u16, 1);
314313
315 const unused_bits = if (value < 0) @clz(T, ~value) else @clz(T, value);314 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" {...@@ -359,8 +359,8 @@ test "basic TailQueue test" {
359 }359 }
360 }360 }
361361
362 var first = list.popFirst(); // {2, 3, 4, 5}362 _ = list.popFirst(); // {2, 3, 4, 5}
363 var last = list.pop(); // {2, 3, 4}363 _ = list.pop(); // {2, 3, 4}
364 list.remove(&three); // {2, 4}364 list.remove(&three); // {2, 4}
365365
366 try testing.expect(list.first.?.data == 2);366 try testing.expect(list.first.?.data == 2);
lib/std/math/big/int.zig+4-2
...@@ -458,6 +458,7 @@ pub const Mutable = struct {...@@ -458,6 +458,7 @@ pub const Mutable = struct {
458 /// If `allocator` is provided, it will be used for temporary storage to improve458 /// If `allocator` is provided, it will be used for temporary storage to improve
459 /// multiplication performance. `error.OutOfMemory` is handled with a fallback algorithm.459 /// multiplication performance. `error.OutOfMemory` is handled with a fallback algorithm.
460 pub fn sqrNoAlias(rma: *Mutable, a: Const, opt_allocator: ?*Allocator) void {460 pub fn sqrNoAlias(rma: *Mutable, a: Const, opt_allocator: ?*Allocator) void {
461 _ = opt_allocator;
461 assert(rma.limbs.ptr != a.limbs.ptr); // illegal aliasing462 assert(rma.limbs.ptr != a.limbs.ptr); // illegal aliasing
462463
463 mem.set(Limb, rma.limbs, 0);464 mem.set(Limb, rma.limbs, 0);
...@@ -676,6 +677,7 @@ pub const Mutable = struct {...@@ -676,6 +677,7 @@ pub const Mutable = struct {
676 ///677 ///
677 /// `limbs_buffer` is used for temporary storage during the operation.678 /// `limbs_buffer` is used for temporary storage during the operation.
678 pub fn gcdNoAlias(rma: *Mutable, x: Const, y: Const, limbs_buffer: *std.ArrayList(Limb)) !void {679 pub fn gcdNoAlias(rma: *Mutable, x: Const, y: Const, limbs_buffer: *std.ArrayList(Limb)) !void {
680 _ = limbs_buffer;
679 assert(rma.limbs.ptr != x.limbs.ptr); // illegal aliasing681 assert(rma.limbs.ptr != x.limbs.ptr); // illegal aliasing
680 assert(rma.limbs.ptr != y.limbs.ptr); // illegal aliasing682 assert(rma.limbs.ptr != y.limbs.ptr); // illegal aliasing
681 return gcdLehmer(rma, x, y, allocator);683 return gcdLehmer(rma, x, y, allocator);
...@@ -1141,6 +1143,7 @@ pub const Const = struct {...@@ -1141,6 +1143,7 @@ pub const Const = struct {
1141 options: std.fmt.FormatOptions,1143 options: std.fmt.FormatOptions,
1142 out_stream: anytype,1144 out_stream: anytype,
1143 ) !void {1145 ) !void {
1146 _ = options;
1144 comptime var radix = 10;1147 comptime var radix = 10;
1145 comptime var case: std.fmt.Case = .lower;1148 comptime var case: std.fmt.Case = .lower;
11461149
...@@ -1618,6 +1621,7 @@ pub const Managed = struct {...@@ -1618,6 +1621,7 @@ pub const Managed = struct {
1618 /// Converts self to a string in the requested base. Memory is allocated from the provided1621 /// Converts self to a string in the requested base. Memory is allocated from the provided
1619 /// allocator and not the one present in self.1622 /// allocator and not the one present in self.
1620 pub fn toString(self: Managed, allocator: *Allocator, base: u8, case: std.fmt.Case) ![]u8 {1623 pub fn toString(self: Managed, allocator: *Allocator, base: u8, case: std.fmt.Case) ![]u8 {
1624 _ = allocator;
1621 if (base < 2 or base > 16) return error.InvalidBase;1625 if (base < 2 or base > 16) return error.InvalidBase;
1622 return self.toConst().toStringAlloc(self.allocator, base, case);1626 return self.toConst().toStringAlloc(self.allocator, base, case);
1623 }1627 }
...@@ -2000,8 +2004,6 @@ fn llmulacc_karatsuba(allocator: *Allocator, r: []Limb, x: []const Limb, y: []co...@@ -2000,8 +2004,6 @@ fn llmulacc_karatsuba(allocator: *Allocator, r: []Limb, x: []const Limb, y: []co
2000 } else {2004 } else {
2001 llsub(j1, y0[0..y0_len], y1[0..y1_len]);2005 llsub(j1, y0[0..y0_len], y1[0..y1_len]);
2002 }2006 }
2003 const j0_len = llnormalize(j0);
2004 const j1_len = llnormalize(j1);
2005 if (x_cmp == y_cmp) {2007 if (x_cmp == y_cmp) {
2006 mem.set(Limb, tmp[0..length], 0);2008 mem.set(Limb, tmp[0..length], 0);
2007 llmulacc(allocator, tmp, j0, j1);2009 llmulacc(allocator, tmp, j0, j1);
lib/std/math/big/rational.zig-1
...@@ -204,7 +204,6 @@ pub const Rational = struct {...@@ -204,7 +204,6 @@ pub const Rational = struct {
204 const esize = math.floatExponentBits(T);204 const esize = math.floatExponentBits(T);
205 const ebias = (1 << (esize - 1)) - 1;205 const ebias = (1 << (esize - 1)) - 1;
206 const emin = 1 - ebias;206 const emin = 1 - ebias;
207 const emax = ebias;
208207
209 if (self.p.eqZero()) {208 if (self.p.eqZero()) {
210 return 0;209 return 0;
lib/std/math/complex/ldexp.zig+1-1
...@@ -12,8 +12,8 @@...@@ -12,8 +12,8 @@
12const std = @import("../../std.zig");12const std = @import("../../std.zig");
13const debug = std.debug;13const debug = std.debug;
14const math = std.math;14const math = std.math;
15const cmath = math.complex;
16const testing = std.testing;15const testing = std.testing;
16const cmath = math.complex;
17const Complex = cmath.Complex;17const Complex = cmath.Complex;
1818
19/// Returns exp(z) scaled to avoid overflow.19/// Returns exp(z) scaled to avoid overflow.
lib/std/math/expm1.zig-4
...@@ -316,16 +316,12 @@ test "math.expm1_64" {...@@ -316,16 +316,12 @@ test "math.expm1_64" {
316}316}
317317
318test "math.expm1_32.special" {318test "math.expm1_32.special" {
319 const epsilon = 0.000001;
320
321 try expect(math.isPositiveInf(expm1_32(math.inf(f32))));319 try expect(math.isPositiveInf(expm1_32(math.inf(f32))));
322 try expect(expm1_32(-math.inf(f32)) == -1.0);320 try expect(expm1_32(-math.inf(f32)) == -1.0);
323 try expect(math.isNan(expm1_32(math.nan(f32))));321 try expect(math.isNan(expm1_32(math.nan(f32))));
324}322}
325323
326test "math.expm1_64.special" {324test "math.expm1_64.special" {
327 const epsilon = 0.000001;
328
329 try expect(math.isPositiveInf(expm1_64(math.inf(f64))));325 try expect(math.isPositiveInf(expm1_64(math.inf(f64))));
330 try expect(expm1_64(-math.inf(f64)) == -1.0);326 try expect(expm1_64(-math.inf(f64)) == -1.0);
331 try expect(math.isNan(expm1_64(math.nan(f64))));327 try expect(math.isNan(expm1_64(math.nan(f64))));
lib/std/math/modf.zig+2-5
...@@ -12,6 +12,7 @@...@@ -12,6 +12,7 @@
12const std = @import("../std.zig");12const std = @import("../std.zig");
13const math = std.math;13const math = std.math;
14const expect = std.testing.expect;14const expect = std.testing.expect;
15const expectEqual = std.testing.expectEqual;
15const maxInt = std.math.maxInt;16const maxInt = std.math.maxInt;
1617
17fn modf_result(comptime T: type) type {18fn modf_result(comptime T: type) type {
...@@ -131,11 +132,7 @@ test "math.modf" {...@@ -131,11 +132,7 @@ test "math.modf" {
131 const a = modf(@as(f32, 1.0));132 const a = modf(@as(f32, 1.0));
132 const b = modf32(1.0);133 const b = modf32(1.0);
133 // NOTE: No struct comparison on generic return type function? non-named, makes sense, but still.134 // 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 try expectEqual(a, b);
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);
139}136}
140137
141test "math.modf32" {138test "math.modf32" {
lib/std/mem.zig+5
...@@ -139,6 +139,11 @@ var failAllocator = Allocator{...@@ -139,6 +139,11 @@ var failAllocator = Allocator{
139 .resizeFn = Allocator.noResize,139 .resizeFn = Allocator.noResize,
140};140};
141fn failAllocatorAlloc(self: *Allocator, n: usize, alignment: u29, len_align: u29, ra: usize) Allocator.Error![]u8 {141fn 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;
142 return error.OutOfMemory;147 return error.OutOfMemory;
143}148}
144149
lib/std/mem/Allocator.zig+4
...@@ -55,6 +55,10 @@ pub fn noResize(...@@ -55,6 +55,10 @@ pub fn noResize(
55 len_align: u29,55 len_align: u29,
56 ret_addr: usize,56 ret_addr: usize,
57) Error!usize {57) Error!usize {
58 _ = self;
59 _ = buf_align;
60 _ = len_align;
61 _ = ret_addr;
58 if (new_len > buf.len)62 if (new_len > buf.len)
59 return error.OutOfMemory;63 return error.OutOfMemory;
60 return new_len;64 return new_len;
lib/std/meta.zig+1-7
...@@ -654,7 +654,6 @@ pub fn TagPayload(comptime U: type, tag: Tag(U)) type {...@@ -654,7 +654,6 @@ pub fn TagPayload(comptime U: type, tag: Tag(U)) type {
654 try testing.expect(trait.is(.Union)(U));654 try testing.expect(trait.is(.Union)(U));
655655
656 const info = @typeInfo(U).Union;656 const info = @typeInfo(U).Union;
657 const tag_info = @typeInfo(Tag(U)).Enum;
658657
659 inline for (info.fields) |field_info| {658 inline for (info.fields) |field_info| {
660 if (comptime mem.eql(u8, field_info.name, @tagName(tag)))659 if (comptime mem.eql(u8, field_info.name, @tagName(tag)))
...@@ -757,12 +756,6 @@ test "std.meta.eql" {...@@ -757,12 +756,6 @@ test "std.meta.eql" {
757 .c = "12345".*,756 .c = "12345".*,
758 };757 };
759758
760 const s_2 = S{
761 .a = 1,
762 .b = 123.3,
763 .c = "54321".*,
764 };
765
766 var s_3 = S{759 var s_3 = S{
767 .a = 134,760 .a = 134,
768 .b = 123.3,761 .b = 123.3,
...@@ -850,6 +843,7 @@ pub const refAllDecls = @compileError("refAllDecls has been moved from std.meta...@@ -850,6 +843,7 @@ pub const refAllDecls = @compileError("refAllDecls has been moved from std.meta
850pub fn declList(comptime Namespace: type, comptime Decl: type) []const *const Decl {843pub fn declList(comptime Namespace: type, comptime Decl: type) []const *const Decl {
851 const S = struct {844 const S = struct {
852 fn declNameLessThan(context: void, lhs: *const Decl, rhs: *const Decl) bool {845 fn declNameLessThan(context: void, lhs: *const Decl, rhs: *const Decl) bool {
846 _ = context;
853 return mem.lessThan(u8, lhs.name, rhs.name);847 return mem.lessThan(u8, lhs.name, rhs.name);
854 }848 }
855 };849 };
lib/std/meta/trailer_flags.zig+3-3
...@@ -96,18 +96,18 @@ pub fn TrailerFlags(comptime Fields: type) type {...@@ -96,18 +96,18 @@ pub fn TrailerFlags(comptime Fields: type) type {
96 pub fn ptr(self: Self, p: [*]align(@alignOf(Fields)) u8, comptime field: FieldEnum) *Field(field) {96 pub fn ptr(self: Self, p: [*]align(@alignOf(Fields)) u8, comptime field: FieldEnum) *Field(field) {
97 if (@sizeOf(Field(field)) == 0)97 if (@sizeOf(Field(field)) == 0)
98 return undefined;98 return undefined;
99 const off = self.offset(p, field);99 const off = self.offset(field);
100 return @ptrCast(*Field(field), @alignCast(@alignOf(Field(field)), p + off));100 return @ptrCast(*Field(field), @alignCast(@alignOf(Field(field)), p + off));
101 }101 }
102102
103 pub fn ptrConst(self: Self, p: [*]align(@alignOf(Fields)) const u8, comptime field: FieldEnum) *const Field(field) {103 pub fn ptrConst(self: Self, p: [*]align(@alignOf(Fields)) const u8, comptime field: FieldEnum) *const Field(field) {
104 if (@sizeOf(Field(field)) == 0)104 if (@sizeOf(Field(field)) == 0)
105 return undefined;105 return undefined;
106 const off = self.offset(p, field);106 const off = self.offset(field);
107 return @ptrCast(*const Field(field), @alignCast(@alignOf(Field(field)), p + off));107 return @ptrCast(*const Field(field), @alignCast(@alignOf(Field(field)), p + off));
108 }108 }
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 {
111 var off: usize = 0;111 var off: usize = 0;
112 inline for (@typeInfo(Fields).Struct.fields) |field_info, i| {112 inline for (@typeInfo(Fields).Struct.fields) |field_info, i| {
113 const active = (self.bits & (1 << i)) != 0;113 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 {...@@ -92,6 +92,7 @@ pub fn MultiArrayList(comptime S: type) type {
92 }92 }
93 const Sort = struct {93 const Sort = struct {
94 fn lessThan(trash: *i32, lhs: Data, rhs: Data) bool {94 fn lessThan(trash: *i32, lhs: Data, rhs: Data) bool {
95 _ = trash;
95 return lhs.alignment > rhs.alignment;96 return lhs.alignment > rhs.alignment;
96 }97 }
97 };98 };
...@@ -221,7 +222,7 @@ pub fn MultiArrayList(comptime S: type) type {...@@ -221,7 +222,7 @@ pub fn MultiArrayList(comptime S: type) type {
221 /// retain list ordering.222 /// retain list ordering.
222 pub fn swapRemove(self: *Self, index: usize) void {223 pub fn swapRemove(self: *Self, index: usize) void {
223 const slices = self.slice();224 const slices = self.slice();
224 inline for (fields) |field_info, i| {225 inline for (fields) |_, i| {
225 const field_slice = slices.items(@intToEnum(Field, i));226 const field_slice = slices.items(@intToEnum(Field, i));
226 field_slice[index] = field_slice[self.len - 1];227 field_slice[index] = field_slice[self.len - 1];
227 field_slice[self.len - 1] = undefined;228 field_slice[self.len - 1] = undefined;
...@@ -233,7 +234,7 @@ pub fn MultiArrayList(comptime S: type) type {...@@ -233,7 +234,7 @@ pub fn MultiArrayList(comptime S: type) type {
233 /// after it to preserve order.234 /// after it to preserve order.
234 pub fn orderedRemove(self: *Self, index: usize) void {235 pub fn orderedRemove(self: *Self, index: usize) void {
235 const slices = self.slice();236 const slices = self.slice();
236 inline for (fields) |field_info, field_index| {237 inline for (fields) |_, field_index| {
237 const field_slice = slices.items(@intToEnum(Field, field_index));238 const field_slice = slices.items(@intToEnum(Field, field_index));
238 var i = index;239 var i = index;
239 while (i < self.len - 1) : (i += 1) {240 while (i < self.len - 1) : (i += 1) {
lib/std/net.zig+7
...@@ -270,6 +270,8 @@ pub const Ip4Address = extern struct {...@@ -270,6 +270,8 @@ pub const Ip4Address = extern struct {
270 options: std.fmt.FormatOptions,270 options: std.fmt.FormatOptions,
271 out_stream: anytype,271 out_stream: anytype,
272 ) !void {272 ) !void {
273 _ = fmt;
274 _ = options;
273 const bytes = @ptrCast(*const [4]u8, &self.sa.addr);275 const bytes = @ptrCast(*const [4]u8, &self.sa.addr);
274 try std.fmt.format(out_stream, "{}.{}.{}.{}:{}", .{276 try std.fmt.format(out_stream, "{}.{}.{}.{}:{}", .{
275 bytes[0],277 bytes[0],
...@@ -281,6 +283,7 @@ pub const Ip4Address = extern struct {...@@ -281,6 +283,7 @@ pub const Ip4Address = extern struct {
281 }283 }
282284
283 pub fn getOsSockLen(self: Ip4Address) os.socklen_t {285 pub fn getOsSockLen(self: Ip4Address) os.socklen_t {
286 _ = self;
284 return @sizeOf(os.sockaddr_in);287 return @sizeOf(os.sockaddr_in);
285 }288 }
286};289};
...@@ -556,6 +559,8 @@ pub const Ip6Address = extern struct {...@@ -556,6 +559,8 @@ pub const Ip6Address = extern struct {
556 options: std.fmt.FormatOptions,559 options: std.fmt.FormatOptions,
557 out_stream: anytype,560 out_stream: anytype,
558 ) !void {561 ) !void {
562 _ = fmt;
563 _ = options;
559 const port = mem.bigToNative(u16, self.sa.port);564 const port = mem.bigToNative(u16, self.sa.port);
560 if (mem.eql(u8, self.sa.addr[0..12], &[_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) {565 if (mem.eql(u8, self.sa.addr[0..12], &[_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) {
561 try std.fmt.format(out_stream, "[::ffff:{}.{}.{}.{}]:{}", .{566 try std.fmt.format(out_stream, "[::ffff:{}.{}.{}.{}]:{}", .{
...@@ -598,6 +603,7 @@ pub const Ip6Address = extern struct {...@@ -598,6 +603,7 @@ pub const Ip6Address = extern struct {
598 }603 }
599604
600 pub fn getOsSockLen(self: Ip6Address) os.socklen_t {605 pub fn getOsSockLen(self: Ip6Address) os.socklen_t {
606 _ = self;
601 return @sizeOf(os.sockaddr_in6);607 return @sizeOf(os.sockaddr_in6);
602 }608 }
603};609};
...@@ -1062,6 +1068,7 @@ fn IN6_IS_ADDR_SITELOCAL(a: [16]u8) bool {...@@ -1062,6 +1068,7 @@ fn IN6_IS_ADDR_SITELOCAL(a: [16]u8) bool {
10621068
1063// Parameters `b` and `a` swapped to make this descending.1069// Parameters `b` and `a` swapped to make this descending.
1064fn addrCmpLessThan(context: void, b: LookupAddr, a: LookupAddr) bool {1070fn addrCmpLessThan(context: void, b: LookupAddr, a: LookupAddr) bool {
1071 _ = context;
1065 return a.sortkey < b.sortkey;1072 return a.sortkey < b.sortkey;
1066}1073}
10671074
lib/std/once.zig+1
...@@ -61,6 +61,7 @@ test "Once executes its function just once" {...@@ -61,6 +61,7 @@ test "Once executes its function just once" {
61 for (threads) |*handle| {61 for (threads) |*handle| {
62 handle.* = try std.Thread.spawn(struct {62 handle.* = try std.Thread.spawn(struct {
63 fn thread_fn(x: u8) void {63 fn thread_fn(x: u8) void {
64 _ = x;
64 global_once.call();65 global_once.call();
65 }66 }
66 }.thread_fn, 0);67 }.thread_fn, 0);
lib/std/os.zig+13-3
...@@ -1164,6 +1164,7 @@ fn openOptionsFromFlags(flags: u32) windows.OpenFileOptions {...@@ -1164,6 +1164,7 @@ fn openOptionsFromFlags(flags: u32) windows.OpenFileOptions {
1164/// TODO currently, this function does not handle all flag combinations1164/// TODO currently, this function does not handle all flag combinations
1165/// or makes use of perm argument.1165/// or makes use of perm argument.
1166pub fn openW(file_path_w: []const u16, flags: u32, perm: mode_t) OpenError!fd_t {1166pub fn openW(file_path_w: []const u16, flags: u32, perm: mode_t) OpenError!fd_t {
1167 _ = perm;
1167 var options = openOptionsFromFlags(flags);1168 var options = openOptionsFromFlags(flags);
1168 options.dir = std.fs.cwd().fd;1169 options.dir = std.fs.cwd().fd;
1169 return windows.OpenFile(file_path_w, options) catch |err| switch (err) {1170 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)...@@ -1273,6 +1274,7 @@ pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: u32, mode: mode_t)
1273/// TODO currently, this function does not handle all flag combinations1274/// TODO currently, this function does not handle all flag combinations
1274/// or makes use of perm argument.1275/// or makes use of perm argument.
1275pub fn openatW(dir_fd: fd_t, file_path_w: []const u16, flags: u32, mode: mode_t) OpenError!fd_t {1276pub fn openatW(dir_fd: fd_t, file_path_w: []const u16, flags: u32, mode: mode_t) OpenError!fd_t {
1277 _ = mode;
1276 var options = openOptionsFromFlags(flags);1278 var options = openOptionsFromFlags(flags);
1277 options.dir = dir_fd;1279 options.dir = dir_fd;
1278 return windows.OpenFile(file_path_w, options) catch |err| switch (err) {1280 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...@@ -2169,6 +2171,7 @@ pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!v
2169pub const mkdiratC = @compileError("deprecated: renamed to mkdiratZ");2171pub const mkdiratC = @compileError("deprecated: renamed to mkdiratZ");
21702172
2171pub fn mkdiratWasi(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!void {2173pub fn mkdiratWasi(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!void {
2174 _ = mode;
2172 switch (wasi.path_create_directory(dir_fd, sub_dir_path.ptr, sub_dir_path.len)) {2175 switch (wasi.path_create_directory(dir_fd, sub_dir_path.ptr, sub_dir_path.len)) {
2173 wasi.ESUCCESS => return,2176 wasi.ESUCCESS => return,
2174 wasi.EACCES => return error.AccessDenied,2177 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...@@ -2216,6 +2219,7 @@ pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirErr
2216}2219}
22172220
2218pub fn mkdiratW(dir_fd: fd_t, sub_path_w: []const u16, mode: u32) MakeDirError!void {2221pub fn mkdiratW(dir_fd: fd_t, sub_path_w: []const u16, mode: u32) MakeDirError!void {
2222 _ = mode;
2219 const sub_dir_handle = windows.OpenFile(sub_path_w, .{2223 const sub_dir_handle = windows.OpenFile(sub_path_w, .{
2220 .dir = dir_fd,2224 .dir = dir_fd,
2221 .access_mask = windows.GENERIC_READ | windows.SYNCHRONIZE,2225 .access_mask = windows.GENERIC_READ | windows.SYNCHRONIZE,
...@@ -2291,6 +2295,7 @@ pub fn mkdirZ(dir_path: [*:0]const u8, mode: u32) MakeDirError!void {...@@ -2291,6 +2295,7 @@ pub fn mkdirZ(dir_path: [*:0]const u8, mode: u32) MakeDirError!void {
22912295
2292/// Windows-only. Same as `mkdir` but the parameters is WTF16 encoded.2296/// Windows-only. Same as `mkdir` but the parameters is WTF16 encoded.
2293pub fn mkdirW(dir_path_w: []const u16, mode: u32) MakeDirError!void {2297pub fn mkdirW(dir_path_w: []const u16, mode: u32) MakeDirError!void {
2298 _ = mode;
2294 const sub_dir_handle = windows.OpenFile(dir_path_w, .{2299 const sub_dir_handle = windows.OpenFile(dir_path_w, .{
2295 .dir = std.fs.cwd().fd,2300 .dir = std.fs.cwd().fd,
2296 .access_mask = windows.GENERIC_READ | windows.SYNCHRONIZE,2301 .access_mask = windows.GENERIC_READ | windows.SYNCHRONIZE,
...@@ -3868,6 +3873,7 @@ pub fn accessZ(path: [*:0]const u8, mode: u32) AccessError!void {...@@ -3868,6 +3873,7 @@ pub fn accessZ(path: [*:0]const u8, mode: u32) AccessError!void {
3868/// Otherwise use `access` or `accessC`.3873/// Otherwise use `access` or `accessC`.
3869/// TODO currently this ignores `mode`.3874/// TODO currently this ignores `mode`.
3870pub fn accessW(path: [*:0]const u16, mode: u32) windows.GetFileAttributesError!void {3875pub fn accessW(path: [*:0]const u16, mode: u32) windows.GetFileAttributesError!void {
3876 _ = mode;
3871 const ret = try windows.GetFileAttributesW(path);3877 const ret = try windows.GetFileAttributesW(path);
3872 if (ret != windows.INVALID_FILE_ATTRIBUTES) {3878 if (ret != windows.INVALID_FILE_ATTRIBUTES) {
3873 return;3879 return;
...@@ -3918,6 +3924,8 @@ pub fn faccessatZ(dirfd: fd_t, path: [*:0]const u8, mode: u32, flags: u32) Acces...@@ -3918,6 +3924,8 @@ pub fn faccessatZ(dirfd: fd_t, path: [*:0]const u8, mode: u32, flags: u32) Acces
3918/// is NtDll-prefixed, null-terminated, WTF-16 encoded.3924/// is NtDll-prefixed, null-terminated, WTF-16 encoded.
3919/// TODO currently this ignores `mode` and `flags`3925/// TODO currently this ignores `mode` and `flags`
3920pub fn faccessatW(dirfd: fd_t, sub_path_w: [*:0]const u16, mode: u32, flags: u32) AccessError!void {3926pub fn faccessatW(dirfd: fd_t, sub_path_w: [*:0]const u16, mode: u32, flags: u32) AccessError!void {
3927 _ = mode;
3928 _ = flags;
3921 if (sub_path_w[0] == '.' and sub_path_w[1] == 0) {3929 if (sub_path_w[0] == '.' and sub_path_w[1] == 0) {
3922 return;3930 return;
3923 }3931 }
...@@ -4895,6 +4903,8 @@ pub fn res_mkquery(...@@ -4895,6 +4903,8 @@ pub fn res_mkquery(
4895 newrr: ?[*]const u8,4903 newrr: ?[*]const u8,
4896 buf: []u8,4904 buf: []u8,
4897) usize {4905) usize {
4906 _ = data;
4907 _ = newrr;
4898 // This implementation is ported from musl libc.4908 // This implementation is ported from musl libc.
4899 // A more idiomatic "ziggy" implementation would be welcome.4909 // A more idiomatic "ziggy" implementation would be welcome.
4900 var name = dname;4910 var name = dname;
...@@ -5341,7 +5351,7 @@ pub fn sendfile(...@@ -5341,7 +5351,7 @@ pub fn sendfile(
5341 ENXIO => return error.Unseekable,5351 ENXIO => return error.Unseekable,
5342 ESPIPE => return error.Unseekable,5352 ESPIPE => return error.Unseekable,
5343 else => |err| {5353 else => |err| {
5344 const discard = unexpectedErrno(err);5354 unexpectedErrno(err) catch {};
5345 break :sf;5355 break :sf;
5346 },5356 },
5347 }5357 }
...@@ -5422,7 +5432,7 @@ pub fn sendfile(...@@ -5422,7 +5432,7 @@ pub fn sendfile(
5422 EPIPE => return error.BrokenPipe,5432 EPIPE => return error.BrokenPipe,
54235433
5424 else => {5434 else => {
5425 const discard = unexpectedErrno(err);5435 unexpectedErrno(err) catch {};
5426 if (amt != 0) {5436 if (amt != 0) {
5427 return amt;5437 return amt;
5428 } else {5438 } else {
...@@ -5484,7 +5494,7 @@ pub fn sendfile(...@@ -5484,7 +5494,7 @@ pub fn sendfile(
5484 EPIPE => return error.BrokenPipe,5494 EPIPE => return error.BrokenPipe,
54855495
5486 else => {5496 else => {
5487 const discard = unexpectedErrno(err);5497 unexpectedErrno(err) catch {};
5488 if (amt != 0) {5498 if (amt != 0) {
5489 return amt;5499 return amt;
5490 } else {5500 } else {
lib/std/os/bits/linux.zig+1-1
...@@ -1286,7 +1286,7 @@ pub const CAP_BLOCK_SUSPEND = 36;...@@ -1286,7 +1286,7 @@ pub const CAP_BLOCK_SUSPEND = 36;
1286pub const CAP_AUDIT_READ = 37;1286pub const CAP_AUDIT_READ = 37;
1287pub const CAP_LAST_CAP = CAP_AUDIT_READ;1287pub const CAP_LAST_CAP = CAP_AUDIT_READ;
12881288
1289pub fn cap_valid(u8: x) bool {1289pub fn cap_valid(x: u8) bool {
1290 return x >= 0 and x <= CAP_LAST_CAP;1290 return x >= 0 and x <= CAP_LAST_CAP;
1291}1291}
12921292
lib/std/os/linux.zig+2-1
...@@ -70,6 +70,7 @@ fn splitValueLE64(val: i64) [2]u32 {...@@ -70,6 +70,7 @@ fn splitValueLE64(val: i64) [2]u32 {
70 };70 };
71}71}
72fn splitValueBE64(val: i64) [2]u32 {72fn splitValueBE64(val: i64) [2]u32 {
73 const u = @bitCast(u64, val);
73 return [2]u32{74 return [2]u32{
74 @truncate(u32, u >> 32),75 @truncate(u32, u >> 32),
75 @truncate(u32, u),76 @truncate(u32, u),
...@@ -1022,7 +1023,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize...@@ -1022,7 +1023,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize
1022 for (msgvec[0..kvlen]) |*msg, i| {1023 for (msgvec[0..kvlen]) |*msg, i| {
1023 var size: i32 = 0;1024 var size: i32 = 0;
1024 const msg_iovlen = @intCast(usize, msg.msg_hdr.msg_iovlen); // kernel side this is treated as unsigned1025 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| {
1026 if (iov.iov_len > std.math.maxInt(i32) or @addWithOverflow(i32, size, @intCast(i32, iov.iov_len), &size)) {1027 if (iov.iov_len > std.math.maxInt(i32) or @addWithOverflow(i32, size, @intCast(i32, iov.iov_len), &size)) {
1027 // batch-send all messages up to the current message1028 // batch-send all messages up to the current message
1028 if (next_unsent < i) {1029 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...@@ -1513,7 +1513,7 @@ pub fn map_create(map_type: MapType, key_size: u32, value_size: u32, max_entries
1513 EINVAL => error.MapTypeOrAttrInvalid,1513 EINVAL => error.MapTypeOrAttrInvalid,
1514 ENOMEM => error.SystemResources,1514 ENOMEM => error.SystemResources,
1515 EPERM => error.AccessDenied,1515 EPERM => error.AccessDenied,
1516 else => |err| unexpectedErrno(rc),1516 else => |err| unexpectedErrno(err),
1517 };1517 };
1518}1518}
15191519
...@@ -1539,7 +1539,7 @@ pub fn map_lookup_elem(fd: fd_t, key: []const u8, value: []u8) !void {...@@ -1539,7 +1539,7 @@ pub fn map_lookup_elem(fd: fd_t, key: []const u8, value: []u8) !void {
1539 EINVAL => return error.FieldInAttrNeedsZeroing,1539 EINVAL => return error.FieldInAttrNeedsZeroing,
1540 ENOENT => return error.NotFound,1540 ENOENT => return error.NotFound,
1541 EPERM => return error.AccessDenied,1541 EPERM => return error.AccessDenied,
1542 else => |err| return unexpectedErrno(rc),1542 else => |err| return unexpectedErrno(err),
1543 }1543 }
1544}1544}
15451545
lib/std/os/linux/io_uring.zig+6-3
...@@ -284,6 +284,7 @@ pub const IO_Uring = struct {...@@ -284,6 +284,7 @@ pub const IO_Uring = struct {
284 }284 }
285285
286 fn copy_cqes_ready(self: *IO_Uring, cqes: []io_uring_cqe, wait_nr: u32) u32 {286 fn copy_cqes_ready(self: *IO_Uring, cqes: []io_uring_cqe, wait_nr: u32) u32 {
287 _ = wait_nr;
287 const ready = self.cq_ready();288 const ready = self.cq_ready();
288 const count = std.math.min(cqes.len, ready);289 const count = std.math.min(cqes.len, ready);
289 var head = self.cq.head.*;290 var head = self.cq.head.*;
...@@ -320,6 +321,7 @@ pub const IO_Uring = struct {...@@ -320,6 +321,7 @@ pub const IO_Uring = struct {
320 /// Not idempotent, calling more than once will result in other CQEs being lost.321 /// Not idempotent, calling more than once will result in other CQEs being lost.
321 /// Matches the implementation of cqe_seen() in liburing.322 /// Matches the implementation of cqe_seen() in liburing.
322 pub fn cqe_seen(self: *IO_Uring, cqe: *io_uring_cqe) void {323 pub fn cqe_seen(self: *IO_Uring, cqe: *io_uring_cqe) void {
324 _ = cqe;
323 self.cq_advance(1);325 self.cq_advance(1);
324 }326 }
325327
...@@ -728,6 +730,7 @@ pub const CompletionQueue = struct {...@@ -728,6 +730,7 @@ pub const CompletionQueue = struct {
728 }730 }
729731
730 pub fn deinit(self: *CompletionQueue) void {732 pub fn deinit(self: *CompletionQueue) void {
733 _ = self;
731 // A no-op since we now share the mmap with the submission queue.734 // A no-op since we now share the mmap with the submission queue.
732 // Here for symmetry with the submission queue, and for any future feature support.735 // Here for symmetry with the submission queue, and for any future feature support.
733 }736 }
...@@ -1272,12 +1275,12 @@ test "accept/connect/send/recv" {...@@ -1272,12 +1275,12 @@ test "accept/connect/send/recv" {
12721275
1273 var accept_addr: os.sockaddr = undefined;1276 var accept_addr: os.sockaddr = undefined;
1274 var accept_addr_len: os.socklen_t = @sizeOf(@TypeOf(accept_addr));1277 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);
1276 try testing.expectEqual(@as(u32, 1), try ring.submit());1279 try testing.expectEqual(@as(u32, 1), try ring.submit());
12771280
1278 const client = try os.socket(address.any.family, os.SOCK_STREAM | os.SOCK_CLOEXEC, 0);1281 const client = try os.socket(address.any.family, os.SOCK_STREAM | os.SOCK_CLOEXEC, 0);
1279 defer os.close(client);1282 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());
1281 try testing.expectEqual(@as(u32, 1), try ring.submit());1284 try testing.expectEqual(@as(u32, 1), try ring.submit());
12821285
1283 var cqe_accept = try ring.copy_cqe();1286 var cqe_accept = try ring.copy_cqe();
...@@ -1305,7 +1308,7 @@ test "accept/connect/send/recv" {...@@ -1305,7 +1308,7 @@ test "accept/connect/send/recv" {
13051308
1306 const send = try ring.send(0xeeeeeeee, client, buffer_send[0..], 0);1309 const send = try ring.send(0xeeeeeeee, client, buffer_send[0..], 0);
1307 send.flags |= linux.IOSQE_IO_LINK;1310 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);
1309 try testing.expectEqual(@as(u32, 2), try ring.submit());1312 try testing.expectEqual(@as(u32, 2), try ring.submit());
13101313
1311 const cqe_send = try ring.copy_cqe();1314 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 {...@@ -31,7 +31,8 @@ pub fn syscall_pipe(fd: *[2]i32) usize {
31 \\ sw $3, 4($4)31 \\ sw $3, 4($4)
32 \\ 2:32 \\ 2:
33 : [ret] "={$2}" (-> usize)33 : [ret] "={$2}" (-> usize)
34 : [number] "{$2}" (@enumToInt(SYS.pipe))34 : [number] "{$2}" (@enumToInt(SYS.pipe)),
35 [fd] "{$4}" (fd)
35 : "memory", "cc", "$7"36 : "memory", "cc", "$7"
36 );37 );
37}38}
lib/std/os/linux/vdso.zig-1
...@@ -15,7 +15,6 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {...@@ -15,7 +15,6 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
1515
16 const eh = @intToPtr(*elf.Ehdr, vdso_addr);16 const eh = @intToPtr(*elf.Ehdr, vdso_addr);
17 var ph_addr: usize = vdso_addr + eh.e_phoff;17 var ph_addr: usize = vdso_addr + eh.e_phoff;
18 const ph = @intToPtr(*elf.Phdr, ph_addr);
1918
20 var maybe_dynv: ?[*]usize = null;19 var maybe_dynv: ?[*]usize = null;
21 var base: usize = maxInt(usize);20 var base: usize = maxInt(usize);
lib/std/os/test.zig+4
...@@ -353,6 +353,7 @@ test "spawn threads" {...@@ -353,6 +353,7 @@ test "spawn threads" {
353}353}
354354
355fn start1(ctx: void) u8 {355fn start1(ctx: void) u8 {
356 _ = ctx;
356 return 0;357 return 0;
357}358}
358359
...@@ -379,6 +380,7 @@ test "thread local storage" {...@@ -379,6 +380,7 @@ test "thread local storage" {
379380
380threadlocal var x: i32 = 1234;381threadlocal var x: i32 = 1234;
381fn testTls(context: void) !void {382fn testTls(context: void) !void {
383 _ = context;
382 if (x != 1234) return error.TlsBadStartValue;384 if (x != 1234) return error.TlsBadStartValue;
383 x += 1;385 x += 1;
384 if (x != 1235) return error.TlsBadEndValue;386 if (x != 1235) return error.TlsBadEndValue;
...@@ -425,6 +427,7 @@ const IterFnError = error{...@@ -425,6 +427,7 @@ const IterFnError = error{
425};427};
426428
427fn iter_fn(info: *dl_phdr_info, size: usize, counter: *usize) IterFnError!void {429fn iter_fn(info: *dl_phdr_info, size: usize, counter: *usize) IterFnError!void {
430 _ = size;
428 // Count how many libraries are loaded431 // Count how many libraries are loaded
429 counter.* += @as(usize, 1);432 counter.* += @as(usize, 1);
430433
...@@ -731,6 +734,7 @@ test "sigaction" {...@@ -731,6 +734,7 @@ test "sigaction" {
731734
732 const S = struct {735 const S = struct {
733 fn handler(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_void) callconv(.C) void {736 fn handler(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_void) callconv(.C) void {
737 _ = ctx_ptr;
734 // Check that we received the correct signal.738 // Check that we received the correct signal.
735 switch (native_os) {739 switch (native_os) {
736 .netbsd => {740 .netbsd => {
lib/std/os/uefi.zig+1
...@@ -37,6 +37,7 @@ pub const Guid = extern struct {...@@ -37,6 +37,7 @@ pub const Guid = extern struct {
37 options: std.fmt.FormatOptions,37 options: std.fmt.FormatOptions,
38 writer: anytype,38 writer: anytype,
39 ) !void {39 ) !void {
40 _ = options;
40 if (f.len == 0) {41 if (f.len == 0) {
41 return std.fmt.format(writer, "{x:0>8}-{x:0>4}-{x:0>4}-{x:0>2}{x:0>2}-{x:0>12}", .{42 return std.fmt.format(writer, "{x:0>8}-{x:0>4}-{x:0>4}-{x:0>2}{x:0>2}-{x:0>12}", .{
42 self.time_low,43 self.time_low,
lib/std/os/uefi/protocols/managed_network_protocol.zig+1
...@@ -35,6 +35,7 @@ pub const ManagedNetworkProtocol = extern struct {...@@ -35,6 +35,7 @@ pub const ManagedNetworkProtocol = extern struct {
35 /// Translates an IP multicast address to a hardware (MAC) multicast address.35 /// Translates an IP multicast address to a hardware (MAC) multicast address.
36 /// This function may be unsupported in some MNP implementations.36 /// This function may be unsupported in some MNP implementations.
37 pub fn mcastIpToMac(self: *const ManagedNetworkProtocol, ipv6flag: bool, ipaddress: *const c_void, mac_address: *MacAddress) Status {37 pub fn mcastIpToMac(self: *const ManagedNetworkProtocol, ipv6flag: bool, ipaddress: *const c_void, mac_address: *MacAddress) Status {
38 _ = mac_address;
38 return self._mcast_ip_to_mac(self, ipv6flag, ipaddress);39 return self._mcast_ip_to_mac(self, ipv6flag, ipaddress);
39 }40 }
4041
lib/std/os/windows.zig-1
...@@ -1156,7 +1156,6 @@ pub fn GetFinalPathNameByHandle(...@@ -1156,7 +1156,6 @@ pub fn GetFinalPathNameByHandle(
1156 &mount_points_struct.MountPoints[0],1156 &mount_points_struct.MountPoints[0],
1157 )[0..mount_points_struct.NumberOfMountPoints];1157 )[0..mount_points_struct.NumberOfMountPoints];
11581158
1159 var found: bool = false;
1160 for (mount_points) |mount_point| {1159 for (mount_points) |mount_point| {
1161 const symlink = @ptrCast(1160 const symlink = @ptrCast(
1162 [*]const u16,1161 [*]const u16,
lib/std/packed_int_array.zig+1
...@@ -194,6 +194,7 @@ pub fn PackedIntArrayEndian(comptime Int: type, comptime endian: Endian, comptim...@@ -194,6 +194,7 @@ pub fn PackedIntArrayEndian(comptime Int: type, comptime endian: Endian, comptim
194194
195 ///Returns the number of elements in the packed array195 ///Returns the number of elements in the packed array
196 pub fn len(self: Self) usize {196 pub fn len(self: Self) usize {
197 _ = self;
197 return int_count;198 return int_count;
198 }199 }
199200
lib/std/pdb.zig+4-1
...@@ -594,6 +594,7 @@ pub const Pdb = struct {...@@ -594,6 +594,7 @@ pub const Pdb = struct {
594 error.InvalidValue => return error.InvalidDebugInfo,594 error.InvalidValue => return error.InvalidDebugInfo,
595 else => |e| return e,595 else => |e| return e,
596 };596 };
597 _ = version;
597 sect_cont_offset += @sizeOf(u32);598 sect_cont_offset += @sizeOf(u32);
598 }599 }
599 while (sect_cont_offset != section_contrib_size) {600 while (sect_cont_offset != section_contrib_size) {
...@@ -617,6 +618,7 @@ pub const Pdb = struct {...@@ -617,6 +618,7 @@ pub const Pdb = struct {
617 // Parse the InfoStreamHeader.618 // Parse the InfoStreamHeader.
618 const version = try reader.readIntLittle(u32);619 const version = try reader.readIntLittle(u32);
619 const signature = try reader.readIntLittle(u32);620 const signature = try reader.readIntLittle(u32);
621 _ = signature;
620 const age = try reader.readIntLittle(u32);622 const age = try reader.readIntLittle(u32);
621 const guid = try reader.readBytesNoEof(16);623 const guid = try reader.readBytesNoEof(16);
622624
...@@ -673,6 +675,7 @@ pub const Pdb = struct {...@@ -673,6 +675,7 @@ pub const Pdb = struct {
673 }675 }
674676
675 pub fn getSymbolName(self: *Pdb, module: *Module, address: u64) ?[]const u8 {677 pub fn getSymbolName(self: *Pdb, module: *Module, address: u64) ?[]const u8 {
678 _ = self;
676 std.debug.assert(module.populated);679 std.debug.assert(module.populated);
677680
678 var symbol_i: usize = 0;681 var symbol_i: usize = 0;
...@@ -904,7 +907,7 @@ const Msf = struct {...@@ -904,7 +907,7 @@ const Msf = struct {
904 // These streams are not used, but still participate in the file907 // These streams are not used, but still participate in the file
905 // and must be taken into account when resolving stream indices.908 // and must be taken into account when resolving stream indices.
906 const Nil = 0xFFFFFFFF;909 const Nil = 0xFFFFFFFF;
907 for (stream_sizes) |*s, i| {910 for (stream_sizes) |*s| {
908 const size = try directory.reader().readIntLittle(u32);911 const size = try directory.reader().readIntLittle(u32);
909 s.* = if (size == Nil) 0 else blockCountFromSize(size, superblock.BlockSize);912 s.* = if (size == Nil) 0 else blockCountFromSize(size, superblock.BlockSize);
910 }913 }
lib/std/priority_dequeue.zig+1-1
...@@ -428,7 +428,7 @@ pub fn PriorityDequeue(comptime T: type) type {...@@ -428,7 +428,7 @@ pub fn PriorityDequeue(comptime T: type) type {
428 warn("{}, ", .{e});428 warn("{}, ", .{e});
429 }429 }
430 warn("array: ", .{});430 warn("array: ", .{});
431 for (self.items) |e, i| {431 for (self.items) |e| {
432 warn("{}, ", .{e});432 warn("{}, ", .{e});
433 }433 }
434 warn("len: {} ", .{self.len});434 warn("len: {} ", .{self.len});
lib/std/priority_queue.zig+1-1
...@@ -249,7 +249,7 @@ pub fn PriorityQueue(comptime T: type) type {...@@ -249,7 +249,7 @@ pub fn PriorityQueue(comptime T: type) type {
249 warn("{}, ", .{e});249 warn("{}, ", .{e});
250 }250 }
251 warn("array: ", .{});251 warn("array: ", .{});
252 for (self.items) |e, i| {252 for (self.items) |e| {
253 warn("{}, ", .{e});253 warn("{}, ", .{e});
254 }254 }
255 warn("len: {} ", .{self.len});255 warn("len: {} ", .{self.len});
lib/std/process.zig+2
...@@ -419,6 +419,7 @@ pub const ArgIteratorWindows = struct {...@@ -419,6 +419,7 @@ pub const ArgIteratorWindows = struct {
419 };419 };
420 }420 }
421 fn emitBackslashes(self: *ArgIteratorWindows, buf: *std.ArrayList(u16), emit_count: usize) !void {421 fn emitBackslashes(self: *ArgIteratorWindows, buf: *std.ArrayList(u16), emit_count: usize) !void {
422 _ = self;
422 var i: usize = 0;423 var i: usize = 0;
423 while (i < emit_count) : (i += 1) {424 while (i < emit_count) : (i += 1) {
424 try buf.append(std.mem.nativeToLittle(u16, '\\'));425 try buf.append(std.mem.nativeToLittle(u16, '\\'));
...@@ -748,6 +749,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]...@@ -748,6 +749,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]
748 }749 }
749 try os.dl_iterate_phdr(&paths, error{OutOfMemory}, struct {750 try os.dl_iterate_phdr(&paths, error{OutOfMemory}, struct {
750 fn callback(info: *os.dl_phdr_info, size: usize, list: *List) !void {751 fn callback(info: *os.dl_phdr_info, size: usize, list: *List) !void {
752 _ = size;
751 const name = info.dlpi_name orelse return;753 const name = info.dlpi_name orelse return;
752 if (name[0] == '/') {754 if (name[0] == '/') {
753 const item = try list.allocator.dupeZ(u8, mem.spanZ(name));755 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" {...@@ -175,5 +175,5 @@ test "exp dist sanity" {
175test "table gen" {175test "table gen" {
176 if (please_windows_dont_oom) return error.SkipZigTest;176 if (please_windows_dont_oom) return error.SkipZigTest;
177177
178 const table = NormDist;178 _ = NormDist;
179}179}
lib/std/sort.zig+4
...@@ -37,9 +37,11 @@ pub fn binarySearch(...@@ -37,9 +37,11 @@ pub fn binarySearch(
37test "binarySearch" {37test "binarySearch" {
38 const S = struct {38 const S = struct {
39 fn order_u32(context: void, lhs: u32, rhs: u32) math.Order {39 fn order_u32(context: void, lhs: u32, rhs: u32) math.Order {
40 _ = context;
40 return math.order(lhs, rhs);41 return math.order(lhs, rhs);
41 }42 }
42 fn order_i32(context: void, lhs: i32, rhs: i32) math.Order {43 fn order_i32(context: void, lhs: i32, rhs: i32) math.Order {
44 _ = context;
43 return math.order(lhs, rhs);45 return math.order(lhs, rhs);
44 }46 }
45 };47 };
...@@ -1133,6 +1135,7 @@ fn swap(...@@ -1133,6 +1135,7 @@ fn swap(
1133pub fn asc(comptime T: type) fn (void, T, T) bool {1135pub fn asc(comptime T: type) fn (void, T, T) bool {
1134 const impl = struct {1136 const impl = struct {
1135 fn inner(context: void, a: T, b: T) bool {1137 fn inner(context: void, a: T, b: T) bool {
1138 _ = context;
1136 return a < b;1139 return a < b;
1137 }1140 }
1138 };1141 };
...@@ -1144,6 +1147,7 @@ pub fn asc(comptime T: type) fn (void, T, T) bool {...@@ -1144,6 +1147,7 @@ pub fn asc(comptime T: type) fn (void, T, T) bool {
1144pub fn desc(comptime T: type) fn (void, T, T) bool {1147pub fn desc(comptime T: type) fn (void, T, T) bool {
1145 const impl = struct {1148 const impl = struct {
1146 fn inner(context: void, a: T, b: T) bool {1149 fn inner(context: void, a: T, b: T) bool {
1150 _ = context;
1147 return a > b;1151 return a > b;
1148 }1152 }
1149 };1153 };
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 {...@@ -160,6 +160,7 @@ fn strncmp(_l: [*:0]const u8, _r: [*:0]const u8, _n: usize) callconv(.C) c_int {
160}160}
161161
162fn strerror(errnum: c_int) callconv(.C) [*:0]const u8 {162fn strerror(errnum: c_int) callconv(.C) [*:0]const u8 {
163 _ = errnum;
163 return "TODO strerror implementation";164 return "TODO strerror implementation";
164}165}
165166
...@@ -173,6 +174,7 @@ test "strncmp" {...@@ -173,6 +174,7 @@ test "strncmp" {
173// Avoid dragging in the runtime safety mechanisms into this .o file,174// Avoid dragging in the runtime safety mechanisms into this .o file,
174// unless we're trying to test this file.175// unless we're trying to test this file.
175pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {176pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
177 _ = error_return_trace;
176 if (builtin.is_test) {178 if (builtin.is_test) {
177 @setCold(true);179 @setCold(true);
178 std.debug.panic("{s}", .{msg});180 std.debug.panic("{s}", .{msg});
lib/std/special/compiler_rt.zig+1
...@@ -602,6 +602,7 @@ pub usingnamespace @import("compiler_rt/atomics.zig");...@@ -602,6 +602,7 @@ pub usingnamespace @import("compiler_rt/atomics.zig");
602// Avoid dragging in the runtime safety mechanisms into this .o file,602// Avoid dragging in the runtime safety mechanisms into this .o file,
603// unless we're trying to test this file.603// unless we're trying to test this file.
604pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {604pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
605 _ = error_return_trace;
605 @setCold(true);606 @setCold(true);
606 if (is_test) {607 if (is_test) {
607 std.debug.panic("{s}", .{msg});608 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 {...@@ -83,7 +83,6 @@ fn addXf3(comptime T: type, a: T, b: T) T {
8383
84 const signBit = (@as(Z, 1) << (significandBits + exponentBits));84 const signBit = (@as(Z, 1) << (significandBits + exponentBits));
85 const maxExponent = ((1 << exponentBits) - 1);85 const maxExponent = ((1 << exponentBits) - 1);
86 const exponentBias = (maxExponent >> 1);
8786
88 const implicitBit = (@as(Z, 1) << significandBits);87 const implicitBit = (@as(Z, 1) << significandBits);
89 const quietBit = implicitBit >> 1;88 const quietBit = implicitBit >> 1;
...@@ -98,10 +97,6 @@ fn addXf3(comptime T: type, a: T, b: T) T {...@@ -98,10 +97,6 @@ fn addXf3(comptime T: type, a: T, b: T) T {
98 const aAbs = aRep & absMask;97 const aAbs = aRep & absMask;
99 const bAbs = bRep & absMask;98 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
105 const infRep = @bitCast(Z, std.math.inf(T));100 const infRep = @bitCast(Z, std.math.inf(T));
106101
107 // Detect if a or b is zero, infinity, or NaN.102 // 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{};...@@ -80,18 +80,21 @@ var spinlocks: SpinlockTable = SpinlockTable{};
80// Those work on any object no matter the pointer alignment nor its size.80// Those work on any object no matter the pointer alignment nor its size.
8181
82fn __atomic_load(size: u32, src: [*]u8, dest: [*]u8, model: i32) callconv(.C) void {82fn __atomic_load(size: u32, src: [*]u8, dest: [*]u8, model: i32) callconv(.C) void {
83 _ = model;
83 var sl = spinlocks.get(@ptrToInt(src));84 var sl = spinlocks.get(@ptrToInt(src));
84 defer sl.release();85 defer sl.release();
85 @memcpy(dest, src, size);86 @memcpy(dest, src, size);
86}87}
8788
88fn __atomic_store(size: u32, dest: [*]u8, src: [*]u8, model: i32) callconv(.C) void {89fn __atomic_store(size: u32, dest: [*]u8, src: [*]u8, model: i32) callconv(.C) void {
90 _ = model;
89 var sl = spinlocks.get(@ptrToInt(dest));91 var sl = spinlocks.get(@ptrToInt(dest));
90 defer sl.release();92 defer sl.release();
91 @memcpy(dest, src, size);93 @memcpy(dest, src, size);
92}94}
9395
94fn __atomic_exchange(size: u32, ptr: [*]u8, val: [*]u8, old: [*]u8, model: i32) callconv(.C) void {96fn __atomic_exchange(size: u32, ptr: [*]u8, val: [*]u8, old: [*]u8, model: i32) callconv(.C) void {
97 _ = model;
95 var sl = spinlocks.get(@ptrToInt(ptr));98 var sl = spinlocks.get(@ptrToInt(ptr));
96 defer sl.release();99 defer sl.release();
97 @memcpy(old, ptr, size);100 @memcpy(old, ptr, size);
...@@ -106,6 +109,8 @@ fn __atomic_compare_exchange(...@@ -106,6 +109,8 @@ fn __atomic_compare_exchange(
106 success: i32,109 success: i32,
107 failure: i32,110 failure: i32,
108) callconv(.C) i32 {111) callconv(.C) i32 {
112 _ = success;
113 _ = failure;
109 var sl = spinlocks.get(@ptrToInt(ptr));114 var sl = spinlocks.get(@ptrToInt(ptr));
110 defer sl.release();115 defer sl.release();
111 for (ptr[0..size]) |b, i| {116 for (ptr[0..size]) |b, i| {
...@@ -135,6 +140,7 @@ comptime {...@@ -135,6 +140,7 @@ comptime {
135fn atomicLoadFn(comptime T: type) fn (*T, i32) callconv(.C) T {140fn atomicLoadFn(comptime T: type) fn (*T, i32) callconv(.C) T {
136 return struct {141 return struct {
137 fn atomic_load_N(src: *T, model: i32) callconv(.C) T {142 fn atomic_load_N(src: *T, model: i32) callconv(.C) T {
143 _ = model;
138 if (@sizeOf(T) > largest_atomic_size) {144 if (@sizeOf(T) > largest_atomic_size) {
139 var sl = spinlocks.get(@ptrToInt(src));145 var sl = spinlocks.get(@ptrToInt(src));
140 defer sl.release();146 defer sl.release();
...@@ -162,6 +168,7 @@ comptime {...@@ -162,6 +168,7 @@ comptime {
162fn atomicStoreFn(comptime T: type) fn (*T, T, i32) callconv(.C) void {168fn atomicStoreFn(comptime T: type) fn (*T, T, i32) callconv(.C) void {
163 return struct {169 return struct {
164 fn atomic_store_N(dst: *T, value: T, model: i32) callconv(.C) void {170 fn atomic_store_N(dst: *T, value: T, model: i32) callconv(.C) void {
171 _ = model;
165 if (@sizeOf(T) > largest_atomic_size) {172 if (@sizeOf(T) > largest_atomic_size) {
166 var sl = spinlocks.get(@ptrToInt(dst));173 var sl = spinlocks.get(@ptrToInt(dst));
167 defer sl.release();174 defer sl.release();
...@@ -189,6 +196,7 @@ comptime {...@@ -189,6 +196,7 @@ comptime {
189fn atomicExchangeFn(comptime T: type) fn (*T, T, i32) callconv(.C) T {196fn atomicExchangeFn(comptime T: type) fn (*T, T, i32) callconv(.C) T {
190 return struct {197 return struct {
191 fn atomic_exchange_N(ptr: *T, val: T, model: i32) callconv(.C) T {198 fn atomic_exchange_N(ptr: *T, val: T, model: i32) callconv(.C) T {
199 _ = model;
192 if (@sizeOf(T) > largest_atomic_size) {200 if (@sizeOf(T) > largest_atomic_size) {
193 var sl = spinlocks.get(@ptrToInt(ptr));201 var sl = spinlocks.get(@ptrToInt(ptr));
194 defer sl.release();202 defer sl.release();
...@@ -218,6 +226,8 @@ comptime {...@@ -218,6 +226,8 @@ comptime {
218fn atomicCompareExchangeFn(comptime T: type) fn (*T, *T, T, i32, i32) callconv(.C) i32 {226fn atomicCompareExchangeFn(comptime T: type) fn (*T, *T, T, i32, i32) callconv(.C) i32 {
219 return struct {227 return struct {
220 fn atomic_compare_exchange_N(ptr: *T, expected: *T, desired: T, success: i32, failure: i32) callconv(.C) i32 {228 fn atomic_compare_exchange_N(ptr: *T, expected: *T, desired: T, success: i32, failure: i32) callconv(.C) i32 {
229 _ = success;
230 _ = failure;
221 if (@sizeOf(T) > largest_atomic_size) {231 if (@sizeOf(T) > largest_atomic_size) {
222 var sl = spinlocks.get(@ptrToInt(ptr));232 var sl = spinlocks.get(@ptrToInt(ptr));
223 defer sl.release();233 defer sl.release();
...@@ -255,6 +265,7 @@ comptime {...@@ -255,6 +265,7 @@ comptime {
255fn fetchFn(comptime T: type, comptime op: builtin.AtomicRmwOp) fn (*T, T, i32) callconv(.C) T {265fn fetchFn(comptime T: type, comptime op: builtin.AtomicRmwOp) fn (*T, T, i32) callconv(.C) T {
256 return struct {266 return struct {
257 pub fn fetch_op_N(ptr: *T, val: T, model: i32) callconv(.C) T {267 pub fn fetch_op_N(ptr: *T, val: T, model: i32) callconv(.C) T {
268 _ = model;
258 if (@sizeOf(T) > largest_atomic_size) {269 if (@sizeOf(T) > largest_atomic_size) {
259 var sl = spinlocks.get(@ptrToInt(ptr));270 var sl = spinlocks.get(@ptrToInt(ptr));
260 defer sl.release();271 defer sl.release();
lib/std/special/compiler_rt/comparedf2_test.zig+1-1
...@@ -100,7 +100,7 @@ const test_vectors = init: {...@@ -100,7 +100,7 @@ const test_vectors = init: {
100};100};
101101
102test "compare f64" {102test "compare f64" {
103 for (test_vectors) |vector, i| {103 for (test_vectors) |vector| {
104 try std.testing.expect(test__cmpdf2(vector));104 try std.testing.expect(test__cmpdf2(vector));
105 }105 }
106}106}
lib/std/special/compiler_rt/comparesf2_test.zig+1-1
...@@ -100,7 +100,7 @@ const test_vectors = init: {...@@ -100,7 +100,7 @@ const test_vectors = init: {
100};100};
101101
102test "compare f32" {102test "compare f32" {
103 for (test_vectors) |vector, i| {103 for (test_vectors) |vector| {
104 try std.testing.expect(test__cmpsf2(vector));104 try std.testing.expect(test__cmpsf2(vector));
105 }105 }
106}106}
lib/std/special/compiler_rt/divtf3.zig-1
...@@ -12,7 +12,6 @@ const wideMultiply = @import("divdf3.zig").wideMultiply;...@@ -12,7 +12,6 @@ const wideMultiply = @import("divdf3.zig").wideMultiply;
12pub fn __divtf3(a: f128, b: f128) callconv(.C) f128 {12pub fn __divtf3(a: f128, b: f128) callconv(.C) f128 {
13 @setRuntimeSafety(builtin.is_test);13 @setRuntimeSafety(builtin.is_test);
14 const Z = std.meta.Int(.unsigned, 128);14 const Z = std.meta.Int(.unsigned, 128);
15 const SignedZ = std.meta.Int(.signed, 128);
1615
17 const significandBits = std.math.floatMantissaBits(f128);16 const significandBits = std.math.floatMantissaBits(f128);
18 const exponentBits = std.math.floatExponentBits(f128);17 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...@@ -46,7 +46,6 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: std.meta.Int(.unsi
46 const dst_rep_t = std.meta.Int(.unsigned, @typeInfo(dst_t).Float.bits);46 const dst_rep_t = std.meta.Int(.unsigned, @typeInfo(dst_t).Float.bits);
47 const srcSigBits = std.math.floatMantissaBits(src_t);47 const srcSigBits = std.math.floatMantissaBits(src_t);
48 const dstSigBits = std.math.floatMantissaBits(dst_t);48 const dstSigBits = std.math.floatMantissaBits(dst_t);
49 const SrcShift = std.math.Log2Int(src_rep_t);
50 const DstShift = std.math.Log2Int(dst_rep_t);49 const DstShift = std.math.Log2Int(dst_rep_t);
5150
52 // Various constants whose values follow from the type parameters.51 // 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...@@ -16,7 +16,6 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t
16 else => unreachable,16 else => unreachable,
17 };17 };
18 const typeWidth = @typeInfo(rep_t).Int.bits;18 const typeWidth = @typeInfo(rep_t).Int.bits;
19 const srep_t = @import("std").meta.Int(.signed, typeWidth);
20 const significandBits = switch (fp_t) {19 const significandBits = switch (fp_t) {
21 f32 => 23,20 f32 => 23,
22 f64 => 52,21 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 {...@@ -50,7 +50,6 @@ fn truncXfYf2(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t {
50 const srcSigBits = std.math.floatMantissaBits(src_t);50 const srcSigBits = std.math.floatMantissaBits(src_t);
51 const dstSigBits = std.math.floatMantissaBits(dst_t);51 const dstSigBits = std.math.floatMantissaBits(dst_t);
52 const SrcShift = std.math.Log2Int(src_rep_t);52 const SrcShift = std.math.Log2Int(src_rep_t);
53 const DstShift = std.math.Log2Int(dst_rep_t);
5453
55 // Various constants whose values follow from the type parameters.54 // Various constants whose values follow from the type parameters.
56 // Any reasonable optimizer will fold and propagate all of these.55 // 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...@@ -27,6 +27,8 @@ extern fn memmove(dest: ?[*]u8, src: ?[*]const u8, n: usize) callconv(.C) ?[*]u8
2727
28// Avoid dragging in the runtime safety mechanisms into this .o file.28// Avoid dragging in the runtime safety mechanisms into this .o file.
29pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {29pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
30 _ = msg;
31 _ = error_return_trace;
30 @setCold(true);32 @setCold(true);
31 if (@hasDecl(std.os, "abort"))33 if (@hasDecl(std.os, "abort"))
32 std.os.abort();34 std.os.abort();
lib/std/target.zig+1-1
...@@ -157,7 +157,7 @@ pub const Target = struct {...@@ -157,7 +157,7 @@ pub const Target = struct {
157 pub fn format(157 pub fn format(
158 self: WindowsVersion,158 self: WindowsVersion,
159 comptime fmt: []const u8,159 comptime fmt: []const u8,
160 options: std.fmt.FormatOptions,160 _: std.fmt.FormatOptions,
161 out_stream: anytype,161 out_stream: anytype,
162 ) !void {162 ) !void {
163 if (fmt.len > 0 and fmt[0] == 's') {163 if (fmt.len > 0 and fmt[0] == 's') {
lib/std/testing.zig-1
...@@ -191,7 +191,6 @@ test "expectEqual.union(enum)" {...@@ -191,7 +191,6 @@ test "expectEqual.union(enum)" {
191 };191 };
192192
193 const a10 = T{ .a = 10 };193 const a10 = T{ .a = 10 };
194 const a20 = T{ .a = 20 };
195194
196 try expectEqual(a10, a10);195 try expectEqual(a10, a10);
197}196}
lib/std/unicode.zig+1-1
...@@ -210,7 +210,7 @@ pub fn utf8ValidateSlice(s: []const u8) bool {...@@ -210,7 +210,7 @@ pub fn utf8ValidateSlice(s: []const u8) bool {
210 return false;210 return false;
211 }211 }
212 i += cp_len;212 i += cp_len;
213 } else |err| {213 } else |_| {
214 return false;214 return false;
215 }215 }
216 }216 }
lib/std/unicode/throughput_test.zig-2
...@@ -47,8 +47,6 @@ fn benchmarkCodepointCount(buf: []const u8) !ResultCount {...@@ -47,8 +47,6 @@ fn benchmarkCodepointCount(buf: []const u8) !ResultCount {
47pub fn main() !void {47pub fn main() !void {
48 const stdout = std.io.getStdOut().writer();48 const stdout = std.io.getStdOut().writer();
4949
50 const args = try std.process.argsAlloc(std.heap.page_allocator);
51
52 try stdout.print("short ASCII strings\n", .{});50 try stdout.print("short ASCII strings\n", .{});
53 {51 {
54 const result = try benchmarkCodepointCount("abc");52 const result = try benchmarkCodepointCount("abc");
lib/std/x/net/ip.zig+2
...@@ -53,6 +53,8 @@ pub const Address = union(enum) {...@@ -53,6 +53,8 @@ pub const Address = union(enum) {
53 opts: fmt.FormatOptions,53 opts: fmt.FormatOptions,
54 writer: anytype,54 writer: anytype,
55 ) !void {55 ) !void {
56 _ = opts;
57 _ = layout;
56 switch (self) {58 switch (self) {
57 .ipv4 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),59 .ipv4 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),
58 .ipv6 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),60 .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" {...@@ -122,7 +122,6 @@ test "reactor/linux: drive async tcp client/listener pair" {
122122
123 const IPv4 = std.x.os.IPv4;123 const IPv4 = std.x.os.IPv4;
124 const IPv6 = std.x.os.IPv6;124 const IPv6 = std.x.os.IPv6;
125 const Socket = std.x.os.Socket;
126125
127 const reactor = try Reactor.init(.{ .close_on_exec = true });126 const reactor = try Reactor.init(.{ .close_on_exec = true });
128 defer reactor.deinit();127 defer reactor.deinit();
lib/std/x/os/net.zig+2
...@@ -143,6 +143,7 @@ pub const IPv4 = extern struct {...@@ -143,6 +143,7 @@ pub const IPv4 = extern struct {
143 opts: fmt.FormatOptions,143 opts: fmt.FormatOptions,
144 writer: anytype,144 writer: anytype,
145 ) !void {145 ) !void {
146 _ = opts;
146 if (comptime layout.len != 0 and layout[0] != 's') {147 if (comptime layout.len != 0 and layout[0] != 's') {
147 @compileError("Unsupported format specifier for IPv4 type '" ++ layout ++ "'.");148 @compileError("Unsupported format specifier for IPv4 type '" ++ layout ++ "'.");
148 }149 }
...@@ -352,6 +353,7 @@ pub const IPv6 = extern struct {...@@ -352,6 +353,7 @@ pub const IPv6 = extern struct {
352 opts: fmt.FormatOptions,353 opts: fmt.FormatOptions,
353 writer: anytype,354 writer: anytype,
354 ) !void {355 ) !void {
356 _ = opts;
355 const specifier = comptime &[_]u8{if (layout.len == 0) 'x' else switch (layout[0]) {357 const specifier = comptime &[_]u8{if (layout.len == 0) 'x' else switch (layout[0]) {
356 'x', 'X' => |specifier| specifier,358 'x', 'X' => |specifier| specifier,
357 's' => 'x',359 's' => 'x',
lib/std/x/os/socket.zig+4-2
...@@ -117,7 +117,7 @@ pub const Socket = struct {...@@ -117,7 +117,7 @@ pub const Socket = struct {
117 };117 };
118 }118 }
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.
121 pub fn getNativeSize(self: Socket.Address) u32 {121 pub fn getNativeSize(self: Socket.Address) u32 {
122 return switch (self) {122 return switch (self) {
123 .ipv4 => @sizeOf(os.sockaddr_in),123 .ipv4 => @sizeOf(os.sockaddr_in),
...@@ -132,6 +132,8 @@ pub const Socket = struct {...@@ -132,6 +132,8 @@ pub const Socket = struct {
132 opts: fmt.FormatOptions,132 opts: fmt.FormatOptions,
133 writer: anytype,133 writer: anytype,
134 ) !void {134 ) !void {
135 _ = opts;
136 _ = layout;
135 switch (self) {137 switch (self) {
136 .ipv4 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),138 .ipv4 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),
137 .ipv6 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),139 .ipv6 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),
...@@ -280,7 +282,7 @@ pub const Socket = struct {...@@ -280,7 +282,7 @@ pub const Socket = struct {
280 ///282 ///
281 /// Microsoft's documentation and glibc denote the fields to be unsigned283 /// Microsoft's documentation and glibc denote the fields to be unsigned
282 /// short's on Windows, whereas glibc and musl denote the fields to be284 /// 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.
284 pub const Linger = extern struct {286 pub const Linger = extern struct {
285 pub const Field = switch (native_os.tag) {287 pub const Field = switch (native_os.tag) {
286 .windows => c_ushort,288 .windows => c_ushort,
lib/std/x/os/socket_windows.zig+7-3
...@@ -292,6 +292,7 @@ pub fn Mixin(comptime Socket: type) type {...@@ -292,6 +292,7 @@ pub fn Mixin(comptime Socket: type) type {
292 /// with a set of flags specified. It returns the number of bytes that were292 /// with a set of flags specified. It returns the number of bytes that were
293 /// read into the buffer provided.293 /// read into the buffer provided.
294 pub fn readMessage(self: Socket, msg: *Socket.Message, flags: u32) !usize {294 pub fn readMessage(self: Socket, msg: *Socket.Message, flags: u32) !usize {
295 _ = flags;
295 const call = try windows.loadWinsockExtensionFunction(ws2_32.LPFN_WSARECVMSG, self.fd, ws2_32.WSAID_WSARECVMSG);296 const call = try windows.loadWinsockExtensionFunction(ws2_32.LPFN_WSARECVMSG, self.fd, ws2_32.WSAID_WSARECVMSG);
296297
297 var num_bytes: u32 = undefined;298 var num_bytes: u32 = undefined;
...@@ -367,16 +368,19 @@ pub fn Mixin(comptime Socket: type) type {...@@ -367,16 +368,19 @@ pub fn Mixin(comptime Socket: type) type {
367368
368 /// Query and return the latest cached error on the socket.369 /// Query and return the latest cached error on the socket.
369 pub fn getError(self: Socket) !void {370 pub fn getError(self: Socket) !void {
371 _ = self;
370 return {};372 return {};
371 }373 }
372374
373 /// Query the read buffer size of the socket.375 /// Query the read buffer size of the socket.
374 pub fn getReadBufferSize(self: Socket) !u32 {376 pub fn getReadBufferSize(self: Socket) !u32 {
377 _ = self;
375 return 0;378 return 0;
376 }379 }
377380
378 /// Query the write buffer size of the socket.381 /// Query the write buffer size of the socket.
379 pub fn getWriteBufferSize(self: Socket) !u32 {382 pub fn getWriteBufferSize(self: Socket) !u32 {
383 _ = self;
380 return 0;384 return 0;
381 }385 }
382386
...@@ -406,7 +410,7 @@ pub fn Mixin(comptime Socket: type) type {...@@ -406,7 +410,7 @@ pub fn Mixin(comptime Socket: type) type {
406410
407 /// On connection-oriented sockets, have keep-alive messages be sent periodically. The timing in which keep-alive411 /// On connection-oriented sockets, have keep-alive messages be sent periodically. The timing in which keep-alive
408 /// messages are sent are dependant on operating system settings. It returns `error.UnsupportedSocketOption` if412 /// 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.
410 pub fn setKeepAlive(self: Socket, enabled: bool) !void {414 pub fn setKeepAlive(self: Socket, enabled: bool) !void {
411 return self.setOption(ws2_32.SOL_SOCKET, ws2_32.SO_KEEPALIVE, mem.asBytes(&@as(u32, @boolToInt(enabled))));415 return self.setOption(ws2_32.SOL_SOCKET, ws2_32.SO_KEEPALIVE, mem.asBytes(&@as(u32, @boolToInt(enabled))));
412 }416 }
...@@ -438,7 +442,7 @@ pub fn Mixin(comptime Socket: type) type {...@@ -438,7 +442,7 @@ pub fn Mixin(comptime Socket: type) type {
438442
439 /// WARNING: Timeouts only affect blocking sockets. It is undefined behavior if a timeout is443 /// WARNING: Timeouts only affect blocking sockets. It is undefined behavior if a timeout is
440 /// set on a non-blocking socket.444 /// set on a non-blocking socket.
441 /// 445 ///
442 /// Set a timeout on the socket that is to occur if no messages are successfully written446 /// Set a timeout on the socket that is to occur if no messages are successfully written
443 /// to its bound destination after a specified number of milliseconds. A subsequent write447 /// to its bound destination after a specified number of milliseconds. A subsequent write
444 /// to the socket will thereafter return `error.WouldBlock` should the timeout be exceeded.448 /// to the socket will thereafter return `error.WouldBlock` should the timeout be exceeded.
...@@ -448,7 +452,7 @@ pub fn Mixin(comptime Socket: type) type {...@@ -448,7 +452,7 @@ pub fn Mixin(comptime Socket: type) type {
448452
449 /// WARNING: Timeouts only affect blocking sockets. It is undefined behavior if a timeout is453 /// WARNING: Timeouts only affect blocking sockets. It is undefined behavior if a timeout is
450 /// set on a non-blocking socket.454 /// set on a non-blocking socket.
451 /// 455 ///
452 /// Set a timeout on the socket that is to occur if no messages are successfully read456 /// Set a timeout on the socket that is to occur if no messages are successfully read
453 /// from its bound destination after a specified number of milliseconds. A subsequent457 /// from its bound destination after a specified number of milliseconds. A subsequent
454 /// read from the socket will thereafter return `error.WouldBlock` should the timeout be458 /// 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 {...@@ -1866,7 +1866,7 @@ pub const Tree = struct {
1866 }1866 }
18671867
1868 fn fullStructInit(tree: Tree, info: full.StructInit.Ast) full.StructInit {1868 fn fullStructInit(tree: Tree, info: full.StructInit.Ast) full.StructInit {
1869 const token_tags = tree.tokens.items(.tag);1869 _ = tree;
1870 var result: full.StructInit = .{1870 var result: full.StructInit = .{
1871 .ast = info,1871 .ast = info,
1872 };1872 };
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 {...@@ -136,6 +136,7 @@ pub inline fn __builtin_strcmp(s1: [*c]const u8, s2: [*c]const u8) c_int {
136}136}
137137
138pub inline fn __builtin_object_size(ptr: ?*const c_void, ty: c_int) usize {138pub inline fn __builtin_object_size(ptr: ?*const c_void, ty: c_int) usize {
139 _ = ptr;
139 // clang semantics match gcc's: https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html140 // clang semantics match gcc's: https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
140 // If it is not possible to determine which objects ptr points to at compile time,141 // If it is not possible to determine which objects ptr points to at compile time,
141 // __builtin_object_size should return (size_t) -1 for type 0 or 1 and (size_t) 0142 // __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(...@@ -186,6 +187,7 @@ pub inline fn __builtin_memcpy(
186/// The return value of __builtin_expect is `expr`. `c` is the expected value187/// The return value of __builtin_expect is `expr`. `c` is the expected value
187/// of `expr` and is used as a hint to the compiler in C. Here it is unused.188/// of `expr` and is used as a hint to the compiler in C. Here it is unused.
188pub inline fn __builtin_expect(expr: c_long, c: c_long) c_long {189pub inline fn __builtin_expect(expr: c_long, c: c_long) c_long {
190 _ = c;
189 return expr;191 return expr;
190}192}
191193
lib/std/zig/fmt.zig+2
...@@ -8,6 +8,7 @@ pub fn formatId(...@@ -8,6 +8,7 @@ pub fn formatId(
8 options: std.fmt.FormatOptions,8 options: std.fmt.FormatOptions,
9 writer: anytype,9 writer: anytype,
10) !void {10) !void {
11 _ = fmt;
11 if (isValidId(bytes)) {12 if (isValidId(bytes)) {
12 return writer.writeAll(bytes);13 return writer.writeAll(bytes);
13 }14 }
...@@ -41,6 +42,7 @@ pub fn formatEscapes(...@@ -41,6 +42,7 @@ pub fn formatEscapes(
41 options: std.fmt.FormatOptions,42 options: std.fmt.FormatOptions,
42 writer: anytype,43 writer: anytype,
43) !void {44) !void {
45 _ = options;
44 for (bytes) |byte| switch (byte) {46 for (bytes) |byte| switch (byte) {
45 '\n' => try writer.writeAll("\\n"),47 '\n' => try writer.writeAll("\\n"),
46 '\r' => try writer.writeAll("\\r"),48 '\r' => try writer.writeAll("\\r"),
lib/std/zig/parse.zig+26-26
...@@ -586,7 +586,7 @@ const Parser = struct {...@@ -586,7 +586,7 @@ const Parser = struct {
586 const thread_local_token = p.eatToken(.keyword_threadlocal);586 const thread_local_token = p.eatToken(.keyword_threadlocal);
587 const var_decl = try p.parseVarDecl();587 const var_decl = try p.parseVarDecl();
588 if (var_decl != 0) {588 if (var_decl != 0) {
589 const semicolon_token = try p.expectToken(.semicolon);589 _ = try p.expectToken(.semicolon);
590 return var_decl;590 return var_decl;
591 }591 }
592 if (thread_local_token != null) {592 if (thread_local_token != null) {
...@@ -614,7 +614,7 @@ const Parser = struct {...@@ -614,7 +614,7 @@ const Parser = struct {
614 fn expectUsingNamespace(p: *Parser) !Node.Index {614 fn expectUsingNamespace(p: *Parser) !Node.Index {
615 const usingnamespace_token = p.assertToken(.keyword_usingnamespace);615 const usingnamespace_token = p.assertToken(.keyword_usingnamespace);
616 const expr = try p.expectExpr();616 const expr = try p.expectExpr();
617 const semicolon_token = try p.expectToken(.semicolon);617 _ = try p.expectToken(.semicolon);
618 return p.addNode(.{618 return p.addNode(.{
619 .tag = .@"usingnamespace",619 .tag = .@"usingnamespace",
620 .main_token = usingnamespace_token,620 .main_token = usingnamespace_token,
...@@ -647,7 +647,7 @@ const Parser = struct {...@@ -647,7 +647,7 @@ const Parser = struct {
647 const align_expr = try p.parseByteAlign();647 const align_expr = try p.parseByteAlign();
648 const section_expr = try p.parseLinkSection();648 const section_expr = try p.parseLinkSection();
649 const callconv_expr = try p.parseCallconv();649 const callconv_expr = try p.parseCallconv();
650 const bang_token = p.eatToken(.bang);650 _ = p.eatToken(.bang);
651651
652 const return_type_expr = try p.parseTypeExpr();652 const return_type_expr = try p.parseTypeExpr();
653 if (return_type_expr == 0) {653 if (return_type_expr == 0) {
...@@ -775,7 +775,7 @@ const Parser = struct {...@@ -775,7 +775,7 @@ const Parser = struct {
775775
776 /// ContainerField <- KEYWORD_comptime? IDENTIFIER (COLON (KEYWORD_anytype / TypeExpr) ByteAlign?)? (EQUAL Expr)?776 /// ContainerField <- KEYWORD_comptime? IDENTIFIER (COLON (KEYWORD_anytype / TypeExpr) ByteAlign?)? (EQUAL Expr)?
777 fn expectContainerField(p: *Parser) !Node.Index {777 fn expectContainerField(p: *Parser) !Node.Index {
778 const comptime_token = p.eatToken(.keyword_comptime);778 _ = p.eatToken(.keyword_comptime);
779 const name_token = p.assertToken(.identifier);779 const name_token = p.assertToken(.identifier);
780780
781 var align_expr: Node.Index = 0;781 var align_expr: Node.Index = 0;
...@@ -967,7 +967,7 @@ const Parser = struct {...@@ -967,7 +967,7 @@ const Parser = struct {
967 _ = try p.expectToken(.l_paren);967 _ = try p.expectToken(.l_paren);
968 const condition = try p.expectExpr();968 const condition = try p.expectExpr();
969 _ = try p.expectToken(.r_paren);969 _ = try p.expectToken(.r_paren);
970 const then_payload = try p.parsePtrPayload();970 _ = try p.parsePtrPayload();
971971
972 // TODO propose to change the syntax so that semicolons are always required972 // TODO propose to change the syntax so that semicolons are always required
973 // inside if statements, even if there is an `else`.973 // inside if statements, even if there is an `else`.
...@@ -992,7 +992,7 @@ const Parser = struct {...@@ -992,7 +992,7 @@ const Parser = struct {
992 else_required = true;992 else_required = true;
993 break :blk assign_expr;993 break :blk assign_expr;
994 };994 };
995 const else_token = p.eatToken(.keyword_else) orelse {995 _ = p.eatToken(.keyword_else) orelse {
996 if (else_required) {996 if (else_required) {
997 try p.warn(.expected_semi_or_else);997 try p.warn(.expected_semi_or_else);
998 }998 }
...@@ -1005,7 +1005,7 @@ const Parser = struct {...@@ -1005,7 +1005,7 @@ const Parser = struct {
1005 },1005 },
1006 });1006 });
1007 };1007 };
1008 const else_payload = try p.parsePayload();1008 _ = try p.parsePayload();
1009 const else_expr = try p.expectStatement();1009 const else_expr = try p.expectStatement();
1010 return p.addNode(.{1010 return p.addNode(.{
1011 .tag = .@"if",1011 .tag = .@"if",
...@@ -1087,7 +1087,7 @@ const Parser = struct {...@@ -1087,7 +1087,7 @@ const Parser = struct {
1087 else_required = true;1087 else_required = true;
1088 break :blk assign_expr;1088 break :blk assign_expr;
1089 };1089 };
1090 const else_token = p.eatToken(.keyword_else) orelse {1090 _ = p.eatToken(.keyword_else) orelse {
1091 if (else_required) {1091 if (else_required) {
1092 try p.warn(.expected_semi_or_else);1092 try p.warn(.expected_semi_or_else);
1093 }1093 }
...@@ -1122,7 +1122,7 @@ const Parser = struct {...@@ -1122,7 +1122,7 @@ const Parser = struct {
1122 _ = try p.expectToken(.l_paren);1122 _ = try p.expectToken(.l_paren);
1123 const condition = try p.expectExpr();1123 const condition = try p.expectExpr();
1124 _ = try p.expectToken(.r_paren);1124 _ = try p.expectToken(.r_paren);
1125 const then_payload = try p.parsePtrPayload();1125 _ = try p.parsePtrPayload();
1126 const cont_expr = try p.parseWhileContinueExpr();1126 const cont_expr = try p.parseWhileContinueExpr();
11271127
1128 // TODO propose to change the syntax so that semicolons are always required1128 // TODO propose to change the syntax so that semicolons are always required
...@@ -1162,7 +1162,7 @@ const Parser = struct {...@@ -1162,7 +1162,7 @@ const Parser = struct {
1162 else_required = true;1162 else_required = true;
1163 break :blk assign_expr;1163 break :blk assign_expr;
1164 };1164 };
1165 const else_token = p.eatToken(.keyword_else) orelse {1165 _ = p.eatToken(.keyword_else) orelse {
1166 if (else_required) {1166 if (else_required) {
1167 try p.warn(.expected_semi_or_else);1167 try p.warn(.expected_semi_or_else);
1168 }1168 }
...@@ -1189,7 +1189,7 @@ const Parser = struct {...@@ -1189,7 +1189,7 @@ const Parser = struct {
1189 });1189 });
1190 }1190 }
1191 };1191 };
1192 const else_payload = try p.parsePayload();1192 _ = try p.parsePayload();
1193 const else_expr = try p.expectStatement();1193 const else_expr = try p.expectStatement();
1194 return p.addNode(.{1194 return p.addNode(.{
1195 .tag = .@"while",1195 .tag = .@"while",
...@@ -1550,7 +1550,7 @@ const Parser = struct {...@@ -1550,7 +1550,7 @@ const Parser = struct {
1550 },1550 },
1551 .l_bracket => switch (p.token_tags[p.tok_i + 1]) {1551 .l_bracket => switch (p.token_tags[p.tok_i + 1]) {
1552 .asterisk => {1552 .asterisk => {
1553 const lbracket = p.nextToken();1553 _ = p.nextToken();
1554 const asterisk = p.nextToken();1554 const asterisk = p.nextToken();
1555 var sentinel: Node.Index = 0;1555 var sentinel: Node.Index = 0;
1556 prefix: {1556 prefix: {
...@@ -1907,7 +1907,7 @@ const Parser = struct {...@@ -1907,7 +1907,7 @@ const Parser = struct {
1907 if (found_payload == 0) try p.warn(.expected_loop_payload);1907 if (found_payload == 0) try p.warn(.expected_loop_payload);
19081908
1909 const then_expr = try p.expectExpr();1909 const then_expr = try p.expectExpr();
1910 const else_token = p.eatToken(.keyword_else) orelse {1910 _ = p.eatToken(.keyword_else) orelse {
1911 return p.addNode(.{1911 return p.addNode(.{
1912 .tag = .for_simple,1912 .tag = .for_simple,
1913 .main_token = for_token,1913 .main_token = for_token,
...@@ -1938,11 +1938,11 @@ const Parser = struct {...@@ -1938,11 +1938,11 @@ const Parser = struct {
1938 _ = try p.expectToken(.l_paren);1938 _ = try p.expectToken(.l_paren);
1939 const condition = try p.expectExpr();1939 const condition = try p.expectExpr();
1940 _ = try p.expectToken(.r_paren);1940 _ = try p.expectToken(.r_paren);
1941 const then_payload = try p.parsePtrPayload();1941 _ = try p.parsePtrPayload();
1942 const cont_expr = try p.parseWhileContinueExpr();1942 const cont_expr = try p.parseWhileContinueExpr();
19431943
1944 const then_expr = try p.expectExpr();1944 const then_expr = try p.expectExpr();
1945 const else_token = p.eatToken(.keyword_else) orelse {1945 _ = p.eatToken(.keyword_else) orelse {
1946 if (cont_expr == 0) {1946 if (cont_expr == 0) {
1947 return p.addNode(.{1947 return p.addNode(.{
1948 .tag = .while_simple,1948 .tag = .while_simple,
...@@ -1966,7 +1966,7 @@ const Parser = struct {...@@ -1966,7 +1966,7 @@ const Parser = struct {
1966 });1966 });
1967 }1967 }
1968 };1968 };
1969 const else_payload = try p.parsePayload();1969 _ = try p.parsePayload();
1970 const else_expr = try p.expectExpr();1970 const else_expr = try p.expectExpr();
1971 return p.addNode(.{1971 return p.addNode(.{
1972 .tag = .@"while",1972 .tag = .@"while",
...@@ -2104,7 +2104,7 @@ const Parser = struct {...@@ -2104,7 +2104,7 @@ const Parser = struct {
2104 /// FnCallArguments <- LPAREN ExprList RPAREN2104 /// FnCallArguments <- LPAREN ExprList RPAREN
2105 /// ExprList <- (Expr COMMA)* Expr?2105 /// ExprList <- (Expr COMMA)* Expr?
2106 fn parseSuffixExpr(p: *Parser) !Node.Index {2106 fn parseSuffixExpr(p: *Parser) !Node.Index {
2107 if (p.eatToken(.keyword_async)) |async_token| {2107 if (p.eatToken(.keyword_async)) |_| {
2108 var res = try p.expectPrimaryTypeExpr();2108 var res = try p.expectPrimaryTypeExpr();
2109 while (true) {2109 while (true) {
2110 const node = try p.parseSuffixOp(res);2110 const node = try p.parseSuffixOp(res);
...@@ -2565,8 +2565,8 @@ const Parser = struct {...@@ -2565,8 +2565,8 @@ const Parser = struct {
2565 p.tok_i += 2;2565 p.tok_i += 2;
2566 while (true) {2566 while (true) {
2567 if (p.eatToken(.r_brace)) |_| break;2567 if (p.eatToken(.r_brace)) |_| break;
2568 const doc_comment = try p.eatDocComments();2568 _ = try p.eatDocComments();
2569 const identifier = try p.expectToken(.identifier);2569 _ = try p.expectToken(.identifier);
2570 switch (p.token_tags[p.tok_i]) {2570 switch (p.token_tags[p.tok_i]) {
2571 .comma => p.tok_i += 1,2571 .comma => p.tok_i += 1,
2572 .r_brace => {2572 .r_brace => {
...@@ -2634,7 +2634,7 @@ const Parser = struct {...@@ -2634,7 +2634,7 @@ const Parser = struct {
2634 if (found_payload == 0) try p.warn(.expected_loop_payload);2634 if (found_payload == 0) try p.warn(.expected_loop_payload);
26352635
2636 const then_expr = try p.expectTypeExpr();2636 const then_expr = try p.expectTypeExpr();
2637 const else_token = p.eatToken(.keyword_else) orelse {2637 _ = p.eatToken(.keyword_else) orelse {
2638 return p.addNode(.{2638 return p.addNode(.{
2639 .tag = .for_simple,2639 .tag = .for_simple,
2640 .main_token = for_token,2640 .main_token = for_token,
...@@ -2665,11 +2665,11 @@ const Parser = struct {...@@ -2665,11 +2665,11 @@ const Parser = struct {
2665 _ = try p.expectToken(.l_paren);2665 _ = try p.expectToken(.l_paren);
2666 const condition = try p.expectExpr();2666 const condition = try p.expectExpr();
2667 _ = try p.expectToken(.r_paren);2667 _ = try p.expectToken(.r_paren);
2668 const then_payload = try p.parsePtrPayload();2668 _ = try p.parsePtrPayload();
2669 const cont_expr = try p.parseWhileContinueExpr();2669 const cont_expr = try p.parseWhileContinueExpr();
26702670
2671 const then_expr = try p.expectTypeExpr();2671 const then_expr = try p.expectTypeExpr();
2672 const else_token = p.eatToken(.keyword_else) orelse {2672 _ = p.eatToken(.keyword_else) orelse {
2673 if (cont_expr == 0) {2673 if (cont_expr == 0) {
2674 return p.addNode(.{2674 return p.addNode(.{
2675 .tag = .while_simple,2675 .tag = .while_simple,
...@@ -2693,7 +2693,7 @@ const Parser = struct {...@@ -2693,7 +2693,7 @@ const Parser = struct {
2693 });2693 });
2694 }2694 }
2695 };2695 };
2696 const else_payload = try p.parsePayload();2696 _ = try p.parsePayload();
2697 const else_expr = try p.expectTypeExpr();2697 const else_expr = try p.expectTypeExpr();
2698 return p.addNode(.{2698 return p.addNode(.{
2699 .tag = .@"while",2699 .tag = .@"while",
...@@ -3570,12 +3570,12 @@ const Parser = struct {...@@ -3570,12 +3570,12 @@ const Parser = struct {
3570 _ = try p.expectToken(.l_paren);3570 _ = try p.expectToken(.l_paren);
3571 const condition = try p.expectExpr();3571 const condition = try p.expectExpr();
3572 _ = try p.expectToken(.r_paren);3572 _ = try p.expectToken(.r_paren);
3573 const then_payload = try p.parsePtrPayload();3573 _ = try p.parsePtrPayload();
35743574
3575 const then_expr = try bodyParseFn(p);3575 const then_expr = try bodyParseFn(p);
3576 if (then_expr == 0) return p.fail(.invalid_token);3576 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(.{
3579 .tag = .if_simple,3579 .tag = .if_simple,
3580 .main_token = if_token,3580 .main_token = if_token,
3581 .data = .{3581 .data = .{
...@@ -3583,7 +3583,7 @@ const Parser = struct {...@@ -3583,7 +3583,7 @@ const Parser = struct {
3583 .rhs = then_expr,3583 .rhs = then_expr,
3584 },3584 },
3585 });3585 });
3586 const else_payload = try p.parsePayload();3586 _ = try p.parsePayload();
3587 const else_expr = try bodyParseFn(p);3587 const else_expr = try bodyParseFn(p);
3588 if (else_expr == 0) return p.fail(.invalid_token);3588 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...@@ -5201,7 +5201,6 @@ fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *b
5201 defer tree.deinit(allocator);5201 defer tree.deinit(allocator);
52025202
5203 for (tree.errors) |parse_error| {5203 for (tree.errors) |parse_error| {
5204 const token_start = tree.tokens.items(.start)[parse_error.token];
5205 const loc = tree.tokenLocation(0, parse_error.token);5204 const loc = tree.tokenLocation(0, parse_error.token);
5206 try stderr.print("(memory buffer):{d}:{d}: error: ", .{ loc.line + 1, loc.column + 1 });5205 try stderr.print("(memory buffer):{d}:{d}: error: ", .{ loc.line + 1, loc.column + 1 });
5207 try tree.renderError(parse_error, stderr);5206 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....@@ -1086,8 +1086,6 @@ fn renderWhile(gpa: *Allocator, ais: *Ais, tree: ast.Tree, while_node: ast.full.
1086 }1086 }
10871087
1088 if (while_node.ast.else_expr != 0) {1088 if (while_node.ast.else_expr != 0) {
1089 const first_else_expr_tok = tree.firstToken(while_node.ast.else_expr);
1090
1091 if (indent_then_expr) {1089 if (indent_then_expr) {
1092 ais.pushIndent();1090 ais.pushIndent();
1093 try renderExpression(gpa, ais, tree, while_node.ast.then_expr, .newline);1091 try renderExpression(gpa, ais, tree, while_node.ast.then_expr, .newline);
...@@ -1133,7 +1131,6 @@ fn renderContainerField(...@@ -1133,7 +1131,6 @@ fn renderContainerField(
1133 field: ast.full.ContainerField,1131 field: ast.full.ContainerField,
1134 space: Space,1132 space: Space,
1135) Error!void {1133) Error!void {
1136 const main_tokens = tree.nodes.items(.main_token);
1137 if (field.comptime_token) |t| {1134 if (field.comptime_token) |t| {
1138 try renderToken(ais, tree, t, .space); // comptime1135 try renderToken(ais, tree, t, .space); // comptime
1139 }1136 }
...@@ -1519,7 +1516,6 @@ fn renderBlock(...@@ -1519,7 +1516,6 @@ fn renderBlock(
1519) Error!void {1516) Error!void {
1520 const token_tags = tree.tokens.items(.tag);1517 const token_tags = tree.tokens.items(.tag);
1521 const node_tags = tree.nodes.items(.tag);1518 const node_tags = tree.nodes.items(.tag);
1522 const nodes_data = tree.nodes.items(.data);
1523 const lbrace = tree.nodes.items(.main_token)[block_node];1519 const lbrace = tree.nodes.items(.main_token)[block_node];
15241520
1525 if (token_tags[lbrace - 1] == .colon and1521 if (token_tags[lbrace - 1] == .colon and
...@@ -1617,7 +1613,6 @@ fn renderArrayInit(...@@ -1617,7 +1613,6 @@ fn renderArrayInit(
1617 space: Space,1613 space: Space,
1618) Error!void {1614) Error!void {
1619 const token_tags = tree.tokens.items(.tag);1615 const token_tags = tree.tokens.items(.tag);
1620 const token_starts = tree.tokens.items(.start);
16211616
1622 if (array_init.ast.type_expr == 0) {1617 if (array_init.ast.type_expr == 0) {
1623 try renderToken(ais, tree, array_init.ast.lbrace - 1, .none); // .1618 try renderToken(ais, tree, array_init.ast.lbrace - 1, .none); // .
...@@ -2046,7 +2041,6 @@ fn renderCall(...@@ -2046,7 +2041,6 @@ fn renderCall(
2046 space: Space,2041 space: Space,
2047) Error!void {2042) Error!void {
2048 const token_tags = tree.tokens.items(.tag);2043 const token_tags = tree.tokens.items(.tag);
2049 const main_tokens = tree.nodes.items(.main_token);
20502044
2051 if (call.async_token) |async_token| {2045 if (call.async_token) |async_token| {
2052 try renderToken(ais, tree, async_token, .space);2046 try renderToken(ais, tree, async_token, .space);
lib/std/zig/system.zig+3-9
...@@ -200,6 +200,7 @@ pub const NativePaths = struct {...@@ -200,6 +200,7 @@ pub const NativePaths = struct {
200 }200 }
201201
202 fn appendArray(self: *NativePaths, array: *ArrayList([:0]u8), s: []const u8) !void {202 fn appendArray(self: *NativePaths, array: *ArrayList([:0]u8), s: []const u8) !void {
203 _ = self;
203 const item = try array.allocator.dupeZ(u8, s);204 const item = try array.allocator.dupeZ(u8, s);
204 errdefer array.allocator.free(item);205 errdefer array.allocator.free(item);
205 try array.append(item);206 try array.append(item);
...@@ -332,7 +333,7 @@ pub const NativeTargetInfo = struct {...@@ -332,7 +333,7 @@ pub const NativeTargetInfo = struct {
332 if (std.builtin.Version.parse(buf[0 .. len - 1])) |ver| {333 if (std.builtin.Version.parse(buf[0 .. len - 1])) |ver| {
333 os.version_range.semver.min = ver;334 os.version_range.semver.min = ver;
334 os.version_range.semver.max = ver;335 os.version_range.semver.max = ver;
335 } else |err| {336 } else |_| {
336 return error.OSVersionDetectionFail;337 return error.OSVersionDetectionFail;
337 }338 }
338 },339 },
...@@ -478,13 +479,6 @@ pub const NativeTargetInfo = struct {...@@ -478,13 +479,6 @@ pub const NativeTargetInfo = struct {
478 }479 }
479 const ld_info_list = ld_info_list_buffer[0..ld_info_list_len];480 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
488 // Best case scenario: the executable is dynamically linked, and we can iterate482 // Best case scenario: the executable is dynamically linked, and we can iterate
489 // over our own shared objects and find a dynamic linker.483 // over our own shared objects and find a dynamic linker.
490 self_exe: {484 self_exe: {
...@@ -838,7 +832,7 @@ pub const NativeTargetInfo = struct {...@@ -838,7 +832,7 @@ pub const NativeTargetInfo = struct {
838832
839 if (dynstr) |ds| {833 if (dynstr) |ds| {
840 const strtab_len = std.math.min(ds.size, strtab_buf.len);834 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);
842 const strtab = strtab_buf[0..strtab_read_len];836 const strtab = strtab_buf[0..strtab_read_len];
843 // TODO this pointer cast should not be necessary837 // TODO this pointer cast should not be necessary
844 const rpoff_usize = std.math.cast(usize, rpoff) catch |err| switch (err) {838 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 {...@@ -68,10 +68,10 @@ pub fn detect(target_os: *Target.Os) !void {
68 return;68 return;
69 }69 }
70 continue;70 continue;
71 } else |err| {71 } else |_| {
72 return error.OSVersionDetectionFail;72 return error.OSVersionDetectionFail;
73 }73 }
74 } else |err| {74 } else |_| {
75 return error.OSVersionDetectionFail;75 return error.OSVersionDetectionFail;
76 }76 }
77 }77 }
lib/std/zig/system/x86.zig+1
...@@ -28,6 +28,7 @@ inline fn hasMask(input: u32, mask: u32) bool {...@@ -28,6 +28,7 @@ inline fn hasMask(input: u32, mask: u32) bool {
28}28}
2929
30pub fn detectNativeCpuAndFeatures(arch: Target.Cpu.Arch, os: Target.Os, cross_target: CrossTarget) Target.Cpu {30pub fn detectNativeCpuAndFeatures(arch: Target.Cpu.Arch, os: Target.Os, cross_target: CrossTarget) Target.Cpu {
31 _ = cross_target;
31 var cpu = Target.Cpu{32 var cpu = Target.Cpu{
32 .arch = arch,33 .arch = arch,
33 .model = Target.Cpu.Model.generic(arch),34 .model = Target.Cpu.Model.generic(arch),
lib/std/zig/tokenizer.zig-1
...@@ -416,7 +416,6 @@ pub const Tokenizer = struct {...@@ -416,7 +416,6 @@ pub const Tokenizer = struct {
416 self.pending_invalid_token = null;416 self.pending_invalid_token = null;
417 return token;417 return token;
418 }418 }
419 const start_index = self.index;
420 var state: State = .start;419 var state: State = .start;
421 var result = Token{420 var result = Token{
422 .tag = .eof,421 .tag = .eof,
src/AstGen.zig+415-323
...@@ -206,7 +206,6 @@ pub const ResultLoc = union(enum) {...@@ -206,7 +206,6 @@ pub const ResultLoc = union(enum) {
206 };206 };
207207
208 fn strategy(rl: ResultLoc, block_scope: *GenZir) Strategy {208 fn strategy(rl: ResultLoc, block_scope: *GenZir) Strategy {
209 var elide_store_to_block_ptr_instructions = false;
210 switch (rl) {209 switch (rl) {
211 // In this branch there will not be any store_to_block_ptr instructions.210 // In this branch there will not be any store_to_block_ptr instructions.
212 .discard, .none, .none_or_ref, .ty, .ref => return .{211 .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...@@ -482,61 +481,61 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
482481
483 .assign => {482 .assign => {
484 try assign(gz, scope, node);483 try assign(gz, scope, node);
485 return rvalue(gz, scope, rl, .void_value, node);484 return rvalue(gz, rl, .void_value, node);
486 },485 },
487486
488 .assign_bit_shift_left => {487 .assign_bit_shift_left => {
489 try assignShift(gz, scope, node, .shl);488 try assignShift(gz, scope, node, .shl);
490 return rvalue(gz, scope, rl, .void_value, node);489 return rvalue(gz, rl, .void_value, node);
491 },490 },
492 .assign_bit_shift_right => {491 .assign_bit_shift_right => {
493 try assignShift(gz, scope, node, .shr);492 try assignShift(gz, scope, node, .shr);
494 return rvalue(gz, scope, rl, .void_value, node);493 return rvalue(gz, rl, .void_value, node);
495 },494 },
496495
497 .assign_bit_and => {496 .assign_bit_and => {
498 try assignOp(gz, scope, node, .bit_and);497 try assignOp(gz, scope, node, .bit_and);
499 return rvalue(gz, scope, rl, .void_value, node);498 return rvalue(gz, rl, .void_value, node);
500 },499 },
501 .assign_bit_or => {500 .assign_bit_or => {
502 try assignOp(gz, scope, node, .bit_or);501 try assignOp(gz, scope, node, .bit_or);
503 return rvalue(gz, scope, rl, .void_value, node);502 return rvalue(gz, rl, .void_value, node);
504 },503 },
505 .assign_bit_xor => {504 .assign_bit_xor => {
506 try assignOp(gz, scope, node, .xor);505 try assignOp(gz, scope, node, .xor);
507 return rvalue(gz, scope, rl, .void_value, node);506 return rvalue(gz, rl, .void_value, node);
508 },507 },
509 .assign_div => {508 .assign_div => {
510 try assignOp(gz, scope, node, .div);509 try assignOp(gz, scope, node, .div);
511 return rvalue(gz, scope, rl, .void_value, node);510 return rvalue(gz, rl, .void_value, node);
512 },511 },
513 .assign_sub => {512 .assign_sub => {
514 try assignOp(gz, scope, node, .sub);513 try assignOp(gz, scope, node, .sub);
515 return rvalue(gz, scope, rl, .void_value, node);514 return rvalue(gz, rl, .void_value, node);
516 },515 },
517 .assign_sub_wrap => {516 .assign_sub_wrap => {
518 try assignOp(gz, scope, node, .subwrap);517 try assignOp(gz, scope, node, .subwrap);
519 return rvalue(gz, scope, rl, .void_value, node);518 return rvalue(gz, rl, .void_value, node);
520 },519 },
521 .assign_mod => {520 .assign_mod => {
522 try assignOp(gz, scope, node, .mod_rem);521 try assignOp(gz, scope, node, .mod_rem);
523 return rvalue(gz, scope, rl, .void_value, node);522 return rvalue(gz, rl, .void_value, node);
524 },523 },
525 .assign_add => {524 .assign_add => {
526 try assignOp(gz, scope, node, .add);525 try assignOp(gz, scope, node, .add);
527 return rvalue(gz, scope, rl, .void_value, node);526 return rvalue(gz, rl, .void_value, node);
528 },527 },
529 .assign_add_wrap => {528 .assign_add_wrap => {
530 try assignOp(gz, scope, node, .addwrap);529 try assignOp(gz, scope, node, .addwrap);
531 return rvalue(gz, scope, rl, .void_value, node);530 return rvalue(gz, rl, .void_value, node);
532 },531 },
533 .assign_mul => {532 .assign_mul => {
534 try assignOp(gz, scope, node, .mul);533 try assignOp(gz, scope, node, .mul);
535 return rvalue(gz, scope, rl, .void_value, node);534 return rvalue(gz, rl, .void_value, node);
536 },535 },
537 .assign_mul_wrap => {536 .assign_mul_wrap => {
538 try assignOp(gz, scope, node, .mulwrap);537 try assignOp(gz, scope, node, .mulwrap);
539 return rvalue(gz, scope, rl, .void_value, node);538 return rvalue(gz, rl, .void_value, node);
540 },539 },
541540
542 // zig fmt: off541 // zig fmt: off
...@@ -598,10 +597,10 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr...@@ -598,10 +597,10 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
598 .asm_simple => return asmExpr(gz, scope, rl, node, tree.asmSimple(node)),597 .asm_simple => return asmExpr(gz, scope, rl, node, tree.asmSimple(node)),
599 .@"asm" => return asmExpr(gz, scope, rl, node, tree.asmFull(node)),598 .@"asm" => return asmExpr(gz, scope, rl, node, tree.asmFull(node)),
600599
601 .string_literal => return stringLiteral(gz, scope, rl, node),600 .string_literal => return stringLiteral(gz, rl, node),
602 .multiline_string_literal => return multilineStringLiteral(gz, scope, 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),
605 // zig fmt: on604 // zig fmt: on
606605
607 .builtin_call_two, .builtin_call_two_comma => {606 .builtin_call_two, .builtin_call_two_comma => {
...@@ -641,7 +640,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr...@@ -641,7 +640,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
641 },640 },
642 .@"return" => return ret(gz, scope, node),641 .@"return" => return ret(gz, scope, node),
643 .field_access => return fieldAccess(gz, scope, rl, node),642 .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
646 .if_simple => return ifExpr(gz, scope, rl, node, tree.ifSimple(node)),645 .if_simple => return ifExpr(gz, scope, rl, node, tree.ifSimple(node)),
647 .@"if" => return ifExpr(gz, scope, rl, node, tree.ifFull(node)),646 .@"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...@@ -660,7 +659,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
660 .lhs = lhs,659 .lhs = lhs,
661 .start = start,660 .start = start,
662 });661 });
663 return rvalue(gz, scope, rl, result, node);662 return rvalue(gz, rl, result, node);
664 },663 },
665 .slice => {664 .slice => {
666 const lhs = try expr(gz, scope, .ref, node_datas[node].lhs);665 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...@@ -672,7 +671,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
672 .start = start,671 .start = start,
673 .end = end,672 .end = end,
674 });673 });
675 return rvalue(gz, scope, rl, result, node);674 return rvalue(gz, rl, result, node);
676 },675 },
677 .slice_sentinel => {676 .slice_sentinel => {
678 const lhs = try expr(gz, scope, .ref, node_datas[node].lhs);677 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...@@ -686,7 +685,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
686 .end = end,685 .end = end,
687 .sentinel = sentinel,686 .sentinel = sentinel,
688 });687 });
689 return rvalue(gz, scope, rl, result, node);688 return rvalue(gz, rl, result, node);
690 },689 },
691690
692 .deref => {691 .deref => {
...@@ -695,22 +694,22 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr...@@ -695,22 +694,22 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
695 .ref, .none_or_ref => return lhs,694 .ref, .none_or_ref => return lhs,
696 else => {695 else => {
697 const result = try gz.addUnNode(.load, lhs, node);696 const result = try gz.addUnNode(.load, lhs, node);
698 return rvalue(gz, scope, rl, result, node);697 return rvalue(gz, rl, result, node);
699 },698 },
700 }699 }
701 },700 },
702 .address_of => {701 .address_of => {
703 const result = try expr(gz, scope, .ref, node_datas[node].lhs);702 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);
705 },704 },
706 .undefined_literal => return rvalue(gz, scope, rl, .undef, node),705 .undefined_literal => return rvalue(gz, rl, .undef, node),
707 .true_literal => return rvalue(gz, scope, rl, .bool_true, node),706 .true_literal => return rvalue(gz, rl, .bool_true, node),
708 .false_literal => return rvalue(gz, scope, rl, .bool_false, node),707 .false_literal => return rvalue(gz, rl, .bool_false, node),
709 .null_literal => return rvalue(gz, scope, rl, .null_value, node),708 .null_literal => return rvalue(gz, rl, .null_value, node),
710 .optional_type => {709 .optional_type => {
711 const operand = try typeExpr(gz, scope, node_datas[node].lhs);710 const operand = try typeExpr(gz, scope, node_datas[node].lhs);
712 const result = try gz.addUnNode(.optional_type, operand, node);711 const result = try gz.addUnNode(.optional_type, operand, node);
713 return rvalue(gz, scope, rl, result, node);712 return rvalue(gz, rl, result, node);
714 },713 },
715 .unwrap_optional => switch (rl) {714 .unwrap_optional => switch (rl) {
716 .ref => return gz.addUnNode(715 .ref => return gz.addUnNode(
...@@ -718,7 +717,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr...@@ -718,7 +717,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
718 try expr(gz, scope, .ref, node_datas[node].lhs),717 try expr(gz, scope, .ref, node_datas[node].lhs),
719 node,718 node,
720 ),719 ),
721 else => return rvalue(gz, scope, rl, try gz.addUnNode(720 else => return rvalue(gz, rl, try gz.addUnNode(
722 .optional_payload_safe,721 .optional_payload_safe,
723 try expr(gz, scope, .none, node_datas[node].lhs),722 try expr(gz, scope, .none, node_datas[node].lhs),
724 node,723 node,
...@@ -738,13 +737,13 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr...@@ -738,13 +737,13 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
738 const statements = tree.extra_data[node_datas[node].lhs..node_datas[node].rhs];737 const statements = tree.extra_data[node_datas[node].lhs..node_datas[node].rhs];
739 return blockExpr(gz, scope, rl, node, statements);738 return blockExpr(gz, scope, rl, node, statements);
740 },739 },
741 .enum_literal => return simpleStrTok(gz, scope, rl, main_tokens[node], node, .enum_literal),740 .enum_literal => return simpleStrTok(gz, rl, main_tokens[node], node, .enum_literal),
742 .error_value => return simpleStrTok(gz, scope, rl, node_datas[node].rhs, node, .error_value),741 .error_value => return simpleStrTok(gz, rl, node_datas[node].rhs, node, .error_value),
743 .anyframe_literal => return rvalue(gz, scope, rl, .anyframe_type, node),742 .anyframe_literal => return rvalue(gz, rl, .anyframe_type, node),
744 .anyframe_type => {743 .anyframe_type => {
745 const return_type = try typeExpr(gz, scope, node_datas[node].rhs);744 const return_type = try typeExpr(gz, scope, node_datas[node].rhs);
746 const result = try gz.addUnNode(.anyframe_type, return_type, node);745 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);
748 },747 },
749 .@"catch" => {748 .@"catch" => {
750 const catch_token = main_tokens[node];749 const catch_token = main_tokens[node];
...@@ -838,14 +837,14 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr...@@ -838,14 +837,14 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
838 .grouped_expression => return expr(gz, scope, rl, node_datas[node].lhs),837 .grouped_expression => return expr(gz, scope, rl, node_datas[node].lhs),
839 .array_type => return arrayType(gz, scope, rl, node),838 .array_type => return arrayType(gz, scope, rl, node),
840 .array_type_sentinel => return arrayTypeSentinel(gz, scope, rl, node),839 .array_type_sentinel => return arrayTypeSentinel(gz, scope, rl, node),
841 .char_literal => return charLiteral(gz, scope, rl, node),840 .char_literal => return charLiteral(gz, rl, node),
842 .error_set_decl => return errorSetDecl(gz, scope, rl, node),841 .error_set_decl => return errorSetDecl(gz, rl, node),
843 .array_access => return arrayAccess(gz, scope, rl, node),842 .array_access => return arrayAccess(gz, scope, rl, node),
844 .@"comptime" => return comptimeExprAst(gz, scope, rl, node),843 .@"comptime" => return comptimeExprAst(gz, scope, rl, node),
845 .@"switch", .switch_comma => return switchExpr(gz, scope, rl, node),844 .@"switch", .switch_comma => return switchExpr(gz, scope, rl, node),
846845
847 .@"nosuspend" => return nosuspendExpr(gz, scope, rl, node),846 .@"nosuspend" => return nosuspendExpr(gz, scope, rl, node),
848 .@"suspend" => return suspendExpr(gz, scope, rl, node),847 .@"suspend" => return suspendExpr(gz, scope, node),
849 .@"await" => return awaitExpr(gz, scope, rl, node),848 .@"await" => return awaitExpr(gz, scope, rl, node),
850 .@"resume" => return resumeExpr(gz, scope, rl, node),849 .@"resume" => return resumeExpr(gz, scope, rl, node),
851850
...@@ -905,7 +904,6 @@ fn nosuspendExpr(...@@ -905,7 +904,6 @@ fn nosuspendExpr(
905 node: ast.Node.Index,904 node: ast.Node.Index,
906) InnerError!Zir.Inst.Ref {905) InnerError!Zir.Inst.Ref {
907 const astgen = gz.astgen;906 const astgen = gz.astgen;
908 const gpa = astgen.gpa;
909 const tree = astgen.tree;907 const tree = astgen.tree;
910 const node_datas = tree.nodes.items(.data);908 const node_datas = tree.nodes.items(.data);
911 const body_node = node_datas[node].lhs;909 const body_node = node_datas[node].lhs;
...@@ -918,13 +916,12 @@ fn nosuspendExpr(...@@ -918,13 +916,12 @@ fn nosuspendExpr(
918 gz.nosuspend_node = node;916 gz.nosuspend_node = node;
919 const result = try expr(gz, scope, rl, body_node);917 const result = try expr(gz, scope, rl, body_node);
920 gz.nosuspend_node = 0;918 gz.nosuspend_node = 0;
921 return rvalue(gz, scope, rl, result, node);919 return rvalue(gz, rl, result, node);
922}920}
923921
924fn suspendExpr(922fn suspendExpr(
925 gz: *GenZir,923 gz: *GenZir,
926 scope: *Scope,924 scope: *Scope,
927 rl: ResultLoc,
928 node: ast.Node.Index,925 node: ast.Node.Index,
929) InnerError!Zir.Inst.Ref {926) InnerError!Zir.Inst.Ref {
930 const astgen = gz.astgen;927 const astgen = gz.astgen;
...@@ -980,7 +977,7 @@ fn awaitExpr(...@@ -980,7 +977,7 @@ fn awaitExpr(
980 const operand = try expr(gz, scope, .none, rhs_node);977 const operand = try expr(gz, scope, .none, rhs_node);
981 const tag: Zir.Inst.Tag = if (gz.nosuspend_node != 0) .await_nosuspend else .@"await";978 const tag: Zir.Inst.Tag = if (gz.nosuspend_node != 0) .await_nosuspend else .@"await";
982 const result = try gz.addUnNode(tag, operand, node);979 const result = try gz.addUnNode(tag, operand, node);
983 return rvalue(gz, scope, rl, result, node);980 return rvalue(gz, rl, result, node);
984}981}
985982
986fn resumeExpr(983fn resumeExpr(
...@@ -995,7 +992,7 @@ fn resumeExpr(...@@ -995,7 +992,7 @@ fn resumeExpr(
995 const rhs_node = node_datas[node].lhs;992 const rhs_node = node_datas[node].lhs;
996 const operand = try expr(gz, scope, .none, rhs_node);993 const operand = try expr(gz, scope, .none, rhs_node);
997 const result = try gz.addUnNode(.@"resume", operand, node);994 const result = try gz.addUnNode(.@"resume", operand, node);
998 return rvalue(gz, scope, rl, result, node);995 return rvalue(gz, rl, result, node);
999}996}
1000997
1001fn fnProtoExpr(998fn fnProtoExpr(
...@@ -1101,7 +1098,7 @@ fn fnProtoExpr(...@@ -1101,7 +1098,7 @@ fn fnProtoExpr(
1101 .is_test = false,1098 .is_test = false,
1102 .is_extern = false,1099 .is_extern = false,
1103 });1100 });
1104 return rvalue(gz, scope, rl, result, fn_proto.ast.proto_node);1101 return rvalue(gz, rl, result, fn_proto.ast.proto_node);
1105}1102}
11061103
1107fn arrayInitExpr(1104fn arrayInitExpr(
...@@ -1113,7 +1110,6 @@ fn arrayInitExpr(...@@ -1113,7 +1110,6 @@ fn arrayInitExpr(
1113) InnerError!Zir.Inst.Ref {1110) InnerError!Zir.Inst.Ref {
1114 const astgen = gz.astgen;1111 const astgen = gz.astgen;
1115 const tree = astgen.tree;1112 const tree = astgen.tree;
1116 const gpa = astgen.gpa;
1117 const node_tags = tree.nodes.items(.tag);1113 const node_tags = tree.nodes.items(.tag);
1118 const main_tokens = tree.nodes.items(.main_token);1114 const main_tokens = tree.nodes.items(.main_token);
11191115
...@@ -1173,32 +1169,32 @@ fn arrayInitExpr(...@@ -1173,32 +1169,32 @@ fn arrayInitExpr(
1173 },1169 },
1174 .ref => {1170 .ref => {
1175 if (types.array != .none) {1171 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);
1177 } else {1173 } 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);
1179 }1175 }
1180 },1176 },
1181 .none, .none_or_ref => {1177 .none, .none_or_ref => {
1182 if (types.array != .none) {1178 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);
1184 } else {1180 } 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);
1186 }1182 }
1187 },1183 },
1188 .ty => |ty_inst| {1184 .ty => |ty_inst| {
1189 if (types.array != .none) {1185 if (types.array != .none) {
1190 const result = try arrayInitExprRlTy(gz, scope, rl, node, array_init.ast.elements, types.array, types.elem, .array_init);1186 const result = try arrayInitExprRlTy(gz, scope, node, array_init.ast.elements, types.elem, .array_init);
1191 return rvalue(gz, scope, rl, result, node);1187 return rvalue(gz, rl, result, node);
1192 } else {1188 } else {
1193 const elem_type = try gz.addUnNode(.elem_type, ty_inst, node);1189 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);
1195 }1191 }
1196 },1192 },
1197 .ptr, .inferred_ptr => |ptr_inst| {1193 .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);
1199 },1195 },
1200 .block_ptr => |block_gz| {1196 .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);
1202 },1198 },
1203 }1199 }
1204}1200}
...@@ -1206,7 +1202,6 @@ fn arrayInitExpr(...@@ -1206,7 +1202,6 @@ fn arrayInitExpr(
1206fn arrayInitExprRlNone(1202fn arrayInitExprRlNone(
1207 gz: *GenZir,1203 gz: *GenZir,
1208 scope: *Scope,1204 scope: *Scope,
1209 rl: ResultLoc,
1210 node: ast.Node.Index,1205 node: ast.Node.Index,
1211 elements: []const ast.Node.Index,1206 elements: []const ast.Node.Index,
1212 tag: Zir.Inst.Tag,1207 tag: Zir.Inst.Tag,
...@@ -1229,10 +1224,8 @@ fn arrayInitExprRlNone(...@@ -1229,10 +1224,8 @@ fn arrayInitExprRlNone(
1229fn arrayInitExprRlTy(1224fn arrayInitExprRlTy(
1230 gz: *GenZir,1225 gz: *GenZir,
1231 scope: *Scope,1226 scope: *Scope,
1232 rl: ResultLoc,
1233 node: ast.Node.Index,1227 node: ast.Node.Index,
1234 elements: []const ast.Node.Index,1228 elements: []const ast.Node.Index,
1235 array_ty_inst: Zir.Inst.Ref,
1236 elem_ty_inst: Zir.Inst.Ref,1229 elem_ty_inst: Zir.Inst.Ref,
1237 tag: Zir.Inst.Tag,1230 tag: Zir.Inst.Tag,
1238) InnerError!Zir.Inst.Ref {1231) InnerError!Zir.Inst.Ref {
...@@ -1257,7 +1250,6 @@ fn arrayInitExprRlTy(...@@ -1257,7 +1250,6 @@ fn arrayInitExprRlTy(
1257fn arrayInitExprRlPtr(1250fn arrayInitExprRlPtr(
1258 gz: *GenZir,1251 gz: *GenZir,
1259 scope: *Scope,1252 scope: *Scope,
1260 rl: ResultLoc,
1261 node: ast.Node.Index,1253 node: ast.Node.Index,
1262 elements: []const ast.Node.Index,1254 elements: []const ast.Node.Index,
1263 result_ptr: Zir.Inst.Ref,1255 result_ptr: Zir.Inst.Ref,
...@@ -1293,11 +1285,10 @@ fn structInitExpr(...@@ -1293,11 +1285,10 @@ fn structInitExpr(
1293) InnerError!Zir.Inst.Ref {1285) InnerError!Zir.Inst.Ref {
1294 const astgen = gz.astgen;1286 const astgen = gz.astgen;
1295 const tree = astgen.tree;1287 const tree = astgen.tree;
1296 const gpa = astgen.gpa;
12971288
1298 if (struct_init.ast.fields.len == 0) {1289 if (struct_init.ast.fields.len == 0) {
1299 if (struct_init.ast.type_expr == 0) {1290 if (struct_init.ast.type_expr == 0) {
1300 return rvalue(gz, scope, rl, .empty_struct, node);1291 return rvalue(gz, rl, .empty_struct, node);
1301 }1292 }
1302 array: {1293 array: {
1303 const node_tags = tree.nodes.items(.tag);1294 const node_tags = tree.nodes.items(.tag);
...@@ -1319,15 +1310,17 @@ fn structInitExpr(...@@ -1319,15 +1310,17 @@ fn structInitExpr(
1319 break :blk try gz.addArrayTypeSentinel(.zero_usize, elem_type, sentinel);1310 break :blk try gz.addArrayTypeSentinel(.zero_usize, elem_type, sentinel);
1320 };1311 };
1321 const result = try gz.addUnNode(.struct_init_empty, array_type_inst, node);1312 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);
1323 }1314 }
1324 }1315 }
1325 const ty_inst = try typeExpr(gz, scope, struct_init.ast.type_expr);1316 const ty_inst = try typeExpr(gz, scope, struct_init.ast.type_expr);
1326 const result = try gz.addUnNode(.struct_init_empty, ty_inst, node);1317 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);
1328 }1319 }
1329 switch (rl) {1320 switch (rl) {
1330 .discard => {1321 .discard => {
1322 if (struct_init.ast.type_expr != 0)
1323 _ = try typeExpr(gz, scope, struct_init.ast.type_expr);
1331 for (struct_init.ast.fields) |field_init| {1324 for (struct_init.ast.fields) |field_init| {
1332 _ = try expr(gz, scope, .discard, field_init);1325 _ = try expr(gz, scope, .discard, field_init);
1333 }1326 }
...@@ -1336,36 +1329,35 @@ fn structInitExpr(...@@ -1336,36 +1329,35 @@ fn structInitExpr(
1336 .ref => {1329 .ref => {
1337 if (struct_init.ast.type_expr != 0) {1330 if (struct_init.ast.type_expr != 0) {
1338 const ty_inst = try typeExpr(gz, scope, struct_init.ast.type_expr);1331 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);
1340 } else {1333 } 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);
1342 }1335 }
1343 },1336 },
1344 .none, .none_or_ref => {1337 .none, .none_or_ref => {
1345 if (struct_init.ast.type_expr != 0) {1338 if (struct_init.ast.type_expr != 0) {
1346 const ty_inst = try typeExpr(gz, scope, struct_init.ast.type_expr);1339 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);
1348 } else {1341 } else {
1349 return structInitExprRlNone(gz, scope, rl, node, struct_init, .struct_init_anon);1342 return structInitExprRlNone(gz, scope, node, struct_init, .struct_init_anon);
1350 }1343 }
1351 },1344 },
1352 .ty => |ty_inst| {1345 .ty => |ty_inst| {
1353 if (struct_init.ast.type_expr == 0) {1346 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);
1355 }1348 }
1356 const inner_ty_inst = try typeExpr(gz, scope, struct_init.ast.type_expr);1349 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);1350 const result = try structInitExprRlTy(gz, scope, node, struct_init, inner_ty_inst, .struct_init);
1358 return rvalue(gz, scope, rl, result, node);1351 return rvalue(gz, rl, result, node);
1359 },1352 },
1360 .ptr, .inferred_ptr => |ptr_inst| return structInitExprRlPtr(gz, scope, rl, node, struct_init, ptr_inst),1353 .ptr, .inferred_ptr => |ptr_inst| return structInitExprRlPtr(gz, scope, node, struct_init, ptr_inst),
1361 .block_ptr => |block_gz| return structInitExprRlPtr(gz, scope, rl, node, struct_init, block_gz.rl_ptr),1354 .block_ptr => |block_gz| return structInitExprRlPtr(gz, scope, node, struct_init, block_gz.rl_ptr),
1362 }1355 }
1363}1356}
13641357
1365fn structInitExprRlNone(1358fn structInitExprRlNone(
1366 gz: *GenZir,1359 gz: *GenZir,
1367 scope: *Scope,1360 scope: *Scope,
1368 rl: ResultLoc,
1369 node: ast.Node.Index,1361 node: ast.Node.Index,
1370 struct_init: ast.full.StructInit,1362 struct_init: ast.full.StructInit,
1371 tag: Zir.Inst.Tag,1363 tag: Zir.Inst.Tag,
...@@ -1400,7 +1392,6 @@ fn structInitExprRlNone(...@@ -1400,7 +1392,6 @@ fn structInitExprRlNone(
1400fn structInitExprRlPtr(1392fn structInitExprRlPtr(
1401 gz: *GenZir,1393 gz: *GenZir,
1402 scope: *Scope,1394 scope: *Scope,
1403 rl: ResultLoc,
1404 node: ast.Node.Index,1395 node: ast.Node.Index,
1405 struct_init: ast.full.StructInit,1396 struct_init: ast.full.StructInit,
1406 result_ptr: Zir.Inst.Ref,1397 result_ptr: Zir.Inst.Ref,
...@@ -1412,6 +1403,9 @@ fn structInitExprRlPtr(...@@ -1412,6 +1403,9 @@ fn structInitExprRlPtr(
1412 const field_ptr_list = try gpa.alloc(Zir.Inst.Index, struct_init.ast.fields.len);1403 const field_ptr_list = try gpa.alloc(Zir.Inst.Index, struct_init.ast.fields.len);
1413 defer gpa.free(field_ptr_list);1404 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
1415 for (struct_init.ast.fields) |field_init, i| {1409 for (struct_init.ast.fields) |field_init, i| {
1416 const name_token = tree.firstToken(field_init) - 2;1410 const name_token = tree.firstToken(field_init) - 2;
1417 const str_index = try astgen.identAsString(name_token);1411 const str_index = try astgen.identAsString(name_token);
...@@ -1432,7 +1426,6 @@ fn structInitExprRlPtr(...@@ -1432,7 +1426,6 @@ fn structInitExprRlPtr(
1432fn structInitExprRlTy(1426fn structInitExprRlTy(
1433 gz: *GenZir,1427 gz: *GenZir,
1434 scope: *Scope,1428 scope: *Scope,
1435 rl: ResultLoc,
1436 node: ast.Node.Index,1429 node: ast.Node.Index,
1437 struct_init: ast.full.StructInit,1430 struct_init: ast.full.StructInit,
1438 ty_inst: Zir.Inst.Ref,1431 ty_inst: Zir.Inst.Ref,
...@@ -1657,8 +1650,8 @@ fn blockExpr(...@@ -1657,8 +1650,8 @@ fn blockExpr(
1657 return labeledBlockExpr(gz, scope, rl, block_node, statements, .block);1650 return labeledBlockExpr(gz, scope, rl, block_node, statements, .block);
1658 }1651 }
16591652
1660 try blockExprStmts(gz, scope, block_node, statements);1653 try blockExprStmts(gz, scope, statements);
1661 return rvalue(gz, scope, rl, .void_value, block_node);1654 return rvalue(gz, rl, .void_value, block_node);
1662}1655}
16631656
1664fn checkLabelRedefinition(astgen: *AstGen, parent_scope: *Scope, label: ast.TokenIndex) !void {1657fn checkLabelRedefinition(astgen: *AstGen, parent_scope: *Scope, label: ast.TokenIndex) !void {
...@@ -1670,9 +1663,6 @@ fn checkLabelRedefinition(astgen: *AstGen, parent_scope: *Scope, label: ast.Toke...@@ -1670,9 +1663,6 @@ fn checkLabelRedefinition(astgen: *AstGen, parent_scope: *Scope, label: ast.Toke
1670 const gen_zir = scope.cast(GenZir).?;1663 const gen_zir = scope.cast(GenZir).?;
1671 if (gen_zir.label) |prev_label| {1664 if (gen_zir.label) |prev_label| {
1672 if (try astgen.tokenIdentEql(label, prev_label.token)) {1665 if (try astgen.tokenIdentEql(label, prev_label.token)) {
1673 const tree = astgen.tree;
1674 const main_tokens = tree.nodes.items(.main_token);
1675
1676 const label_name = try astgen.identifierTokenString(label);1666 const label_name = try astgen.identifierTokenString(label);
1677 return astgen.failTokNotes(label, "redefinition of label '{s}'", .{1667 return astgen.failTokNotes(label, "redefinition of label '{s}'", .{
1678 label_name,1668 label_name,
...@@ -1735,7 +1725,7 @@ fn labeledBlockExpr(...@@ -1735,7 +1725,7 @@ fn labeledBlockExpr(
1735 defer block_scope.labeled_breaks.deinit(astgen.gpa);1725 defer block_scope.labeled_breaks.deinit(astgen.gpa);
1736 defer block_scope.labeled_store_to_block_ptr_list.deinit(astgen.gpa);1726 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
1740 if (!block_scope.label.?.used) {1730 if (!block_scope.label.?.used) {
1741 return astgen.failTok(label_token, "unused block label", .{});1731 return astgen.failTok(label_token, "unused block label", .{});
...@@ -1771,21 +1761,15 @@ fn labeledBlockExpr(...@@ -1771,21 +1761,15 @@ fn labeledBlockExpr(
1771 const block_ref = gz.indexToRef(block_inst);1761 const block_ref = gz.indexToRef(block_inst);
1772 switch (rl) {1762 switch (rl) {
1773 .ref => return block_ref,1763 .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),
1775 }1765 }
1776 },1766 },
1777 }1767 }
1778}1768}
17791769
1780fn blockExprStmts(1770fn blockExprStmts(gz: *GenZir, parent_scope: *Scope, statements: []const ast.Node.Index) !void {
1781 gz: *GenZir,
1782 parent_scope: *Scope,
1783 node: ast.Node.Index,
1784 statements: []const ast.Node.Index,
1785) !void {
1786 const astgen = gz.astgen;1771 const astgen = gz.astgen;
1787 const tree = astgen.tree;1772 const tree = astgen.tree;
1788 const main_tokens = tree.nodes.items(.main_token);
1789 const node_tags = tree.nodes.items(.tag);1773 const node_tags = tree.nodes.items(.tag);
17901774
1791 var block_arena = std.heap.ArenaAllocator.init(gz.astgen.gpa);1775 var block_arena = std.heap.ArenaAllocator.init(gz.astgen.gpa);
...@@ -1800,8 +1784,8 @@ fn blockExprStmts(...@@ -1800,8 +1784,8 @@ fn blockExprStmts(
1800 .simple_var_decl => scope = try varDecl(gz, scope, statement, &block_arena.allocator, tree.simpleVarDecl(statement)),1784 .simple_var_decl => scope = try varDecl(gz, scope, statement, &block_arena.allocator, tree.simpleVarDecl(statement)),
1801 .aligned_var_decl => scope = try varDecl(gz, scope, statement, &block_arena.allocator, tree.alignedVarDecl(statement)),1785 .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),1787 .@"defer" => scope = try makeDeferScope(scope, statement, &block_arena.allocator, .defer_normal),
1804 .@"errdefer" => scope = try deferStmt(gz, scope, statement, &block_arena.allocator, .defer_error),1788 .@"errdefer" => scope = try makeDeferScope(scope, statement, &block_arena.allocator, .defer_error),
18051789
1806 .assign => try assign(gz, scope, statement),1790 .assign => try assign(gz, scope, statement),
18071791
...@@ -1826,6 +1810,7 @@ fn blockExprStmts(...@@ -1826,6 +1810,7 @@ fn blockExprStmts(
1826 }1810 }
18271811
1828 try genDefers(gz, parent_scope, scope, .none);1812 try genDefers(gz, parent_scope, scope, .none);
1813 try checkUsed(gz, parent_scope, scope);
1829}1814}
18301815
1831fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: ast.Node.Index) InnerError!void {1816fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: ast.Node.Index) InnerError!void {
...@@ -2119,6 +2104,7 @@ fn genDefers(...@@ -2119,6 +2104,7 @@ fn genDefers(
2119 inner_scope: *Scope,2104 inner_scope: *Scope,
2120 err_code: Zir.Inst.Ref,2105 err_code: Zir.Inst.Ref,
2121) InnerError!void {2106) InnerError!void {
2107 _ = err_code;
2122 const astgen = gz.astgen;2108 const astgen = gz.astgen;
2123 const tree = astgen.tree;2109 const tree = astgen.tree;
2124 const node_datas = tree.nodes.items(.data);2110 const node_datas = tree.nodes.items(.data);
...@@ -2154,8 +2140,49 @@ fn genDefers(...@@ -2154,8 +2140,49 @@ fn genDefers(
2154 }2140 }
2155}2141}
21562142
2157fn deferStmt(2143fn checkUsed(
2158 gz: *GenZir,2144 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(
2159 scope: *Scope,2186 scope: *Scope,
2160 node: ast.Node.Index,2187 node: ast.Node.Index,
2161 block_arena: *Allocator,2188 block_arena: *Allocator,
...@@ -2274,6 +2301,7 @@ fn varDecl(...@@ -2274,6 +2301,7 @@ fn varDecl(
2274 .name = ident_name,2301 .name = ident_name,
2275 .inst = init_inst,2302 .inst = init_inst,
2276 .token_src = name_token,2303 .token_src = name_token,
2304 .used = .constant,
2277 };2305 };
2278 return &sub_scope.base;2306 return &sub_scope.base;
2279 }2307 }
...@@ -2341,6 +2369,7 @@ fn varDecl(...@@ -2341,6 +2369,7 @@ fn varDecl(
2341 .name = ident_name,2369 .name = ident_name,
2342 .inst = init_inst,2370 .inst = init_inst,
2343 .token_src = name_token,2371 .token_src = name_token,
2372 .used = .constant,
2344 };2373 };
2345 return &sub_scope.base;2374 return &sub_scope.base;
2346 }2375 }
...@@ -2369,7 +2398,8 @@ fn varDecl(...@@ -2369,7 +2398,8 @@ fn varDecl(
2369 .name = ident_name,2398 .name = ident_name,
2370 .ptr = init_scope.rl_ptr,2399 .ptr = init_scope.rl_ptr,
2371 .token_src = name_token,2400 .token_src = name_token,
2372 .is_comptime = true,2401 .maybe_comptime = true,
2402 .used = .constant,
2373 };2403 };
2374 return &sub_scope.base;2404 return &sub_scope.base;
2375 },2405 },
...@@ -2414,7 +2444,7 @@ fn varDecl(...@@ -2414,7 +2444,7 @@ fn varDecl(
2414 resolve_inferred_alloc = alloc;2444 resolve_inferred_alloc = alloc;
2415 break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc } };2445 break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc } };
2416 };2446 };
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);
2418 if (resolve_inferred_alloc != .none) {2448 if (resolve_inferred_alloc != .none) {
2419 _ = try gz.addUnNode(.resolve_inferred_alloc, resolve_inferred_alloc, node);2449 _ = try gz.addUnNode(.resolve_inferred_alloc, resolve_inferred_alloc, node);
2420 }2450 }
...@@ -2425,7 +2455,8 @@ fn varDecl(...@@ -2425,7 +2455,8 @@ fn varDecl(
2425 .name = ident_name,2455 .name = ident_name,
2426 .ptr = var_data.alloc,2456 .ptr = var_data.alloc,
2427 .token_src = name_token,2457 .token_src = name_token,
2428 .is_comptime = is_comptime,2458 .maybe_comptime = is_comptime,
2459 .used = .variable,
2429 };2460 };
2430 return &sub_scope.base;2461 return &sub_scope.base;
2431 },2462 },
...@@ -2441,7 +2472,6 @@ fn emitDbgNode(gz: *GenZir, node: ast.Node.Index) !void {...@@ -2441,7 +2472,6 @@ fn emitDbgNode(gz: *GenZir, node: ast.Node.Index) !void {
24412472
2442 const astgen = gz.astgen;2473 const astgen = gz.astgen;
2443 const tree = astgen.tree;2474 const tree = astgen.tree;
2444 const node_tags = tree.nodes.items(.tag);
2445 const token_starts = tree.tokens.items(.start);2475 const token_starts = tree.tokens.items(.start);
2446 const decl_start = token_starts[tree.firstToken(gz.decl_node_index)];2476 const decl_start = token_starts[tree.firstToken(gz.decl_node_index)];
2447 const node_start = token_starts[tree.firstToken(node)];2477 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...@@ -2530,7 +2560,7 @@ fn boolNot(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) Inne
25302560
2531 const operand = try expr(gz, scope, bool_rl, node_datas[node].lhs);2561 const operand = try expr(gz, scope, bool_rl, node_datas[node].lhs);
2532 const result = try gz.addUnNode(.bool_not, operand, node);2562 const result = try gz.addUnNode(.bool_not, operand, node);
2533 return rvalue(gz, scope, rl, result, node);2563 return rvalue(gz, rl, result, node);
2534}2564}
25352565
2536fn bitNot(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!Zir.Inst.Ref {2566fn 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...@@ -2540,7 +2570,7 @@ fn bitNot(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) Inner
25402570
2541 const operand = try expr(gz, scope, .none, node_datas[node].lhs);2571 const operand = try expr(gz, scope, .none, node_datas[node].lhs);
2542 const result = try gz.addUnNode(.bit_not, operand, node);2572 const result = try gz.addUnNode(.bit_not, operand, node);
2543 return rvalue(gz, scope, rl, result, node);2573 return rvalue(gz, rl, result, node);
2544}2574}
25452575
2546fn negation(2576fn negation(
...@@ -2556,7 +2586,7 @@ fn negation(...@@ -2556,7 +2586,7 @@ fn negation(
25562586
2557 const operand = try expr(gz, scope, .none, node_datas[node].lhs);2587 const operand = try expr(gz, scope, .none, node_datas[node].lhs);
2558 const result = try gz.addUnNode(tag, operand, node);2588 const result = try gz.addUnNode(tag, operand, node);
2559 return rvalue(gz, scope, rl, result, node);2589 return rvalue(gz, rl, result, node);
2560}2590}
25612591
2562fn ptrType(2592fn ptrType(
...@@ -2566,9 +2596,6 @@ fn ptrType(...@@ -2566,9 +2596,6 @@ fn ptrType(
2566 node: ast.Node.Index,2596 node: ast.Node.Index,
2567 ptr_info: ast.full.PtrType,2597 ptr_info: ast.full.PtrType,
2568) InnerError!Zir.Inst.Ref {2598) InnerError!Zir.Inst.Ref {
2569 const astgen = gz.astgen;
2570 const tree = astgen.tree;
2571
2572 const elem_type = try typeExpr(gz, scope, ptr_info.ast.child_type);2599 const elem_type = try typeExpr(gz, scope, ptr_info.ast.child_type);
25732600
2574 const simple = ptr_info.ast.align_node == 0 and2601 const simple = ptr_info.ast.align_node == 0 and
...@@ -2585,7 +2612,7 @@ fn ptrType(...@@ -2585,7 +2612,7 @@ fn ptrType(
2585 .elem_type = elem_type,2612 .elem_type = elem_type,
2586 },2613 },
2587 } });2614 } });
2588 return rvalue(gz, scope, rl, result, node);2615 return rvalue(gz, rl, result, node);
2589 }2616 }
25902617
2591 var sentinel_ref: Zir.Inst.Ref = .none;2618 var sentinel_ref: Zir.Inst.Ref = .none;
...@@ -2645,7 +2672,7 @@ fn ptrType(...@@ -2645,7 +2672,7 @@ fn ptrType(
2645 } });2672 } });
2646 gz.instructions.appendAssumeCapacity(new_index);2673 gz.instructions.appendAssumeCapacity(new_index);
26472674
2648 return rvalue(gz, scope, rl, result, node);2675 return rvalue(gz, rl, result, node);
2649}2676}
26502677
2651fn arrayType(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !Zir.Inst.Ref {2678fn 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...@@ -2665,7 +2692,7 @@ fn arrayType(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !Z
2665 const elem_type = try typeExpr(gz, scope, node_datas[node].rhs);2692 const elem_type = try typeExpr(gz, scope, node_datas[node].rhs);
26662693
2667 const result = try gz.addBin(.array_type, len, elem_type);2694 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);
2669}2696}
26702697
2671fn arrayTypeSentinel(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !Zir.Inst.Ref {2698fn 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...@@ -2687,7 +2714,7 @@ fn arrayTypeSentinel(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.I
2687 const sentinel = try expr(gz, scope, .{ .ty = elem_type }, extra.sentinel);2714 const sentinel = try expr(gz, scope, .{ .ty = elem_type }, extra.sentinel);
26882715
2689 const result = try gz.addArrayTypeSentinel(len, elem_type, sentinel);2716 const result = try gz.addArrayTypeSentinel(len, elem_type, sentinel);
2690 return rvalue(gz, scope, rl, result, node);2717 return rvalue(gz, rl, result, node);
2691}2718}
26922719
2693const WipDecls = struct {2720const WipDecls = struct {
...@@ -2918,6 +2945,10 @@ fn fnDecl(...@@ -2918,6 +2945,10 @@ fn fnDecl(
2918 const name_token = param.name_token orelse {2945 const name_token = param.name_token orelse {
2919 return astgen.failNode(param.type_expr, "missing parameter name", .{});2946 return astgen.failNode(param.type_expr, "missing parameter name", .{});
2920 };2947 };
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;
2921 const param_name = try astgen.identAsString(name_token);2952 const param_name = try astgen.identAsString(name_token);
2922 // Create an arg instruction. This is needed to emit a semantic analysis2953 // Create an arg instruction. This is needed to emit a semantic analysis
2923 // error for shadowing decls.2954 // error for shadowing decls.
...@@ -2930,16 +2961,19 @@ fn fnDecl(...@@ -2930,16 +2961,19 @@ fn fnDecl(
2930 .name = param_name,2961 .name = param_name,
2931 .inst = arg_inst,2962 .inst = arg_inst,
2932 .token_src = name_token,2963 .token_src = name_token,
2964 .used = .fn_param,
2933 };2965 };
2934 params_scope = &sub_scope.base;2966 params_scope = &sub_scope.base;
29352967
2936 // Additionally put the param name into `string_bytes` and reference it with2968 // Additionally put the param name into `string_bytes` and reference it with
2937 // `extra` so that we have access to the data in codegen, for debug info.2969 // `extra` so that we have access to the data in codegen, for debug info.
2938 const str_index = try astgen.identAsString(name_token);2970 const str_index = try astgen.identAsString(name_token);
2939 astgen.extra.appendAssumeCapacity(str_index);2971 try astgen.extra.append(astgen.gpa, str_index);
2940 }2972 }
2973 _ = try typeExpr(&fn_gz, params_scope, fn_proto.ast.return_type);
29412974
2942 _ = try expr(&fn_gz, params_scope, .none, body_node);2975 _ = try expr(&fn_gz, params_scope, .none, body_node);
2976 try checkUsed(gz, &fn_gz.base, params_scope);
2943 }2977 }
29442978
2945 const need_implicit_ret = blk: {2979 const need_implicit_ret = blk: {
...@@ -3632,7 +3666,7 @@ fn unionDeclInner(...@@ -3632,7 +3666,7 @@ fn unionDeclInner(
3632 };3666 };
3633 defer block_scope.instructions.deinit(gpa);3667 defer block_scope.instructions.deinit(gpa);
36343668
3635 var namespace: Scope.Namespace = .{ .parent = &gz.base };3669 var namespace: Scope.Namespace = .{ .parent = scope };
3636 defer namespace.decls.deinit(gpa);3670 defer namespace.decls.deinit(gpa);
36373671
3638 var wip_decls: WipDecls = .{};3672 var wip_decls: WipDecls = .{};
...@@ -3916,7 +3950,7 @@ fn containerDecl(...@@ -3916,7 +3950,7 @@ fn containerDecl(
3916 assert(arg_inst == .none);3950 assert(arg_inst == .none);
39173951
3918 const result = try structDeclInner(gz, scope, node, container_decl, layout);3952 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);
3920 },3954 },
3921 .keyword_union => {3955 .keyword_union => {
3922 const layout = if (container_decl.layout_token) |t| switch (token_tags[t]) {3956 const layout = if (container_decl.layout_token) |t| switch (token_tags[t]) {
...@@ -3928,7 +3962,7 @@ fn containerDecl(...@@ -3928,7 +3962,7 @@ fn containerDecl(
3928 const have_auto_enum = container_decl.ast.enum_token != null;3962 const have_auto_enum = container_decl.ast.enum_token != null;
39293963
3930 const result = try unionDeclInner(gz, scope, node, container_decl.ast.members, layout, arg_inst, have_auto_enum);3964 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);
3932 },3966 },
3933 .keyword_enum => {3967 .keyword_enum => {
3934 if (container_decl.layout_token) |t| {3968 if (container_decl.layout_token) |t| {
...@@ -4033,7 +4067,7 @@ fn containerDecl(...@@ -4033,7 +4067,7 @@ fn containerDecl(
4033 };4067 };
4034 defer block_scope.instructions.deinit(gpa);4068 defer block_scope.instructions.deinit(gpa);
40354069
4036 var namespace: Scope.Namespace = .{ .parent = &gz.base };4070 var namespace: Scope.Namespace = .{ .parent = scope };
4037 defer namespace.decls.deinit(gpa);4071 defer namespace.decls.deinit(gpa);
40384072
4039 var wip_decls: WipDecls = .{};4073 var wip_decls: WipDecls = .{};
...@@ -4257,20 +4291,18 @@ fn containerDecl(...@@ -4257,20 +4291,18 @@ fn containerDecl(
4257 astgen.extra.appendAssumeCapacity(cur_bit_bag);4291 astgen.extra.appendAssumeCapacity(cur_bit_bag);
4258 astgen.extra.appendSliceAssumeCapacity(fields_data.items);4292 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);
4261 },4295 },
4262 .keyword_opaque => {4296 .keyword_opaque => {
4263 var namespace: Scope.Namespace = .{ .parent = &gz.base };4297 var namespace: Scope.Namespace = .{ .parent = scope };
4264 defer namespace.decls.deinit(gpa);4298 defer namespace.decls.deinit(gpa);
42654299
4266 var wip_decls: WipDecls = .{};4300 var wip_decls: WipDecls = .{};
4267 defer wip_decls.deinit(gpa);4301 defer wip_decls.deinit(gpa);
42684302
4269 for (container_decl.ast.members) |member_node| {4303 for (container_decl.ast.members) |member_node| {
4270 const member = switch (node_tags[member_node]) {4304 switch (node_tags[member_node]) {
4271 .container_field_init => tree.containerFieldInit(member_node),4305 .container_field_init, .container_field_align, .container_field => {},
4272 .container_field_align => tree.containerFieldAlign(member_node),
4273 .container_field => tree.containerField(member_node),
42744306
4275 .fn_decl => {4307 .fn_decl => {
4276 const fn_proto = node_datas[member_node].lhs;4308 const fn_proto = node_datas[member_node].lhs;
...@@ -4391,7 +4423,7 @@ fn containerDecl(...@@ -4391,7 +4423,7 @@ fn containerDecl(
4391 continue;4423 continue;
4392 },4424 },
4393 else => unreachable,4425 else => unreachable,
4394 };4426 }
4395 }4427 }
4396 {4428 {
4397 const empty_slot_count = WipDecls.fields_per_u32 - (wip_decls.decl_index % WipDecls.fields_per_u32);4429 const empty_slot_count = WipDecls.fields_per_u32 - (wip_decls.decl_index % WipDecls.fields_per_u32);
...@@ -4420,18 +4452,13 @@ fn containerDecl(...@@ -4420,18 +4452,13 @@ fn containerDecl(
4420 }4452 }
4421 astgen.extra.appendSliceAssumeCapacity(wip_decls.payload.items);4453 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);
4424 },4456 },
4425 else => unreachable,4457 else => unreachable,
4426 }4458 }
4427}4459}
44284460
4429fn errorSetDecl(4461fn errorSetDecl(gz: *GenZir, rl: ResultLoc, node: ast.Node.Index) InnerError!Zir.Inst.Ref {
4430 gz: *GenZir,
4431 scope: *Scope,
4432 rl: ResultLoc,
4433 node: ast.Node.Index,
4434) InnerError!Zir.Inst.Ref {
4435 const astgen = gz.astgen;4462 const astgen = gz.astgen;
4436 const gpa = astgen.gpa;4463 const gpa = astgen.gpa;
4437 const tree = astgen.tree;4464 const tree = astgen.tree;
...@@ -4459,16 +4486,11 @@ fn errorSetDecl(...@@ -4459,16 +4486,11 @@ fn errorSetDecl(
4459 }4486 }
4460 }4487 }
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 };
4467 const result = try gz.addPlNode(.error_set_decl, node, Zir.Inst.ErrorSetDecl{4489 const result = try gz.addPlNode(.error_set_decl, node, Zir.Inst.ErrorSetDecl{
4468 .fields_len = @intCast(u32, field_names.items.len),4490 .fields_len = @intCast(u32, field_names.items.len),
4469 });4491 });
4470 try astgen.extra.appendSlice(gpa, field_names.items);4492 try astgen.extra.appendSlice(gpa, field_names.items);
4471 return rvalue(gz, scope, rl, result, node);4493 return rvalue(gz, rl, result, node);
4472}4494}
44734495
4474fn tryExpr(4496fn tryExpr(
...@@ -4479,7 +4501,6 @@ fn tryExpr(...@@ -4479,7 +4501,6 @@ fn tryExpr(
4479 operand_node: ast.Node.Index,4501 operand_node: ast.Node.Index,
4480) InnerError!Zir.Inst.Ref {4502) InnerError!Zir.Inst.Ref {
4481 const astgen = parent_gz.astgen;4503 const astgen = parent_gz.astgen;
4482 const tree = astgen.tree;
44834504
4484 const fn_block = astgen.fn_block orelse {4505 const fn_block = astgen.fn_block orelse {
4485 return astgen.failNode(node, "invalid 'try' outside function scope", .{});4506 return astgen.failNode(node, "invalid 'try' outside function scope", .{});
...@@ -4528,12 +4549,11 @@ fn tryExpr(...@@ -4528,12 +4549,11 @@ fn tryExpr(
4528 const unwrapped_payload = try else_scope.addUnNode(err_ops[2], operand, node);4549 const unwrapped_payload = try else_scope.addUnNode(err_ops[2], operand, node);
4529 const else_result = switch (rl) {4550 const else_result = switch (rl) {
4530 .ref => unwrapped_payload,4551 .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),
4532 };4553 };
45334554
4534 return finishThenElseBlock(4555 return finishThenElseBlock(
4535 parent_gz,4556 parent_gz,
4536 scope,
4537 rl,4557 rl,
4538 node,4558 node,
4539 &block_scope,4559 &block_scope,
...@@ -4541,8 +4561,6 @@ fn tryExpr(...@@ -4541,8 +4561,6 @@ fn tryExpr(
4541 &else_scope,4561 &else_scope,
4542 condbr,4562 condbr,
4543 cond,4563 cond,
4544 node,
4545 node,
4546 then_result,4564 then_result,
4547 else_result,4565 else_result,
4548 block,4566 block,
...@@ -4603,12 +4621,15 @@ fn orelseCatchExpr(...@@ -4603,12 +4621,15 @@ fn orelseCatchExpr(
4603 .name = err_name,4621 .name = err_name,
4604 .inst = try then_scope.addUnNode(unwrap_code_op, operand, node),4622 .inst = try then_scope.addUnNode(unwrap_code_op, operand, node),
4605 .token_src = payload,4623 .token_src = payload,
4624 .used = .capture,
4606 };4625 };
4607 break :blk &err_val_scope.base;4626 break :blk &err_val_scope.base;
4608 };4627 };
46094628
4610 block_scope.break_count += 1;4629 block_scope.break_count += 1;
4611 const then_result = try expr(&then_scope, then_sub_scope, block_scope.break_result_loc, rhs);4630 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
4612 // We hold off on the break instructions as well as copying the then/else4633 // We hold off on the break instructions as well as copying the then/else
4613 // instructions into place until we know whether to keep store_to_block_ptr4634 // instructions into place until we know whether to keep store_to_block_ptr
4614 // instructions or not.4635 // instructions or not.
...@@ -4620,12 +4641,11 @@ fn orelseCatchExpr(...@@ -4620,12 +4641,11 @@ fn orelseCatchExpr(
4620 const unwrapped_payload = try else_scope.addUnNode(unwrap_op, operand, node);4641 const unwrapped_payload = try else_scope.addUnNode(unwrap_op, operand, node);
4621 const else_result = switch (rl) {4642 const else_result = switch (rl) {
4622 .ref => unwrapped_payload,4643 .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),
4624 };4645 };
46254646
4626 return finishThenElseBlock(4647 return finishThenElseBlock(
4627 parent_gz,4648 parent_gz,
4628 scope,
4629 rl,4649 rl,
4630 node,4650 node,
4631 &block_scope,4651 &block_scope,
...@@ -4633,8 +4653,6 @@ fn orelseCatchExpr(...@@ -4633,8 +4653,6 @@ fn orelseCatchExpr(
4633 &else_scope,4653 &else_scope,
4634 condbr,4654 condbr,
4635 cond,4655 cond,
4636 node,
4637 node,
4638 then_result,4656 then_result,
4639 else_result,4657 else_result,
4640 block,4658 block,
...@@ -4645,7 +4663,6 @@ fn orelseCatchExpr(...@@ -4645,7 +4663,6 @@ fn orelseCatchExpr(
46454663
4646fn finishThenElseBlock(4664fn finishThenElseBlock(
4647 parent_gz: *GenZir,4665 parent_gz: *GenZir,
4648 parent_scope: *Scope,
4649 rl: ResultLoc,4666 rl: ResultLoc,
4650 node: ast.Node.Index,4667 node: ast.Node.Index,
4651 block_scope: *GenZir,4668 block_scope: *GenZir,
...@@ -4653,8 +4670,6 @@ fn finishThenElseBlock(...@@ -4653,8 +4670,6 @@ fn finishThenElseBlock(
4653 else_scope: *GenZir,4670 else_scope: *GenZir,
4654 condbr: Zir.Inst.Index,4671 condbr: Zir.Inst.Index,
4655 cond: Zir.Inst.Ref,4672 cond: Zir.Inst.Ref,
4656 then_src: ast.Node.Index,
4657 else_src: ast.Node.Index,
4658 then_result: Zir.Inst.Ref,4673 then_result: Zir.Inst.Ref,
4659 else_result: Zir.Inst.Ref,4674 else_result: Zir.Inst.Ref,
4660 main_block: Zir.Inst.Index,4675 main_block: Zir.Inst.Index,
...@@ -4664,7 +4679,6 @@ fn finishThenElseBlock(...@@ -4664,7 +4679,6 @@ fn finishThenElseBlock(
4664 // We now have enough information to decide whether the result instruction should4679 // We now have enough information to decide whether the result instruction should
4665 // be communicated via result location pointer or break instructions.4680 // be communicated via result location pointer or break instructions.
4666 const strat = rl.strategy(block_scope);4681 const strat = rl.strategy(block_scope);
4667 const astgen = block_scope.astgen;
4668 switch (strat.tag) {4682 switch (strat.tag) {
4669 .break_void => {4683 .break_void => {
4670 if (!parent_gz.refIsNoReturn(then_result)) {4684 if (!parent_gz.refIsNoReturn(then_result)) {
...@@ -4697,7 +4711,7 @@ fn finishThenElseBlock(...@@ -4697,7 +4711,7 @@ fn finishThenElseBlock(
4697 const block_ref = parent_gz.indexToRef(main_block);4711 const block_ref = parent_gz.indexToRef(main_block);
4698 switch (rl) {4712 switch (rl) {
4699 .ref => return block_ref,4713 .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),
4701 }4715 }
4702 },4716 },
4703 }4717 }
...@@ -4733,7 +4747,7 @@ fn fieldAccess(...@@ -4733,7 +4747,7 @@ fn fieldAccess(
4733 .lhs = try expr(gz, scope, .ref, object_node),4747 .lhs = try expr(gz, scope, .ref, object_node),
4734 .field_name_start = str_index,4748 .field_name_start = str_index,
4735 }),4749 }),
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{
4737 .lhs = try expr(gz, scope, .none_or_ref, object_node),4751 .lhs = try expr(gz, scope, .none_or_ref, object_node),
4738 .field_name_start = str_index,4752 .field_name_start = str_index,
4739 }), node),4753 }), node),
...@@ -4748,7 +4762,6 @@ fn arrayAccess(...@@ -4748,7 +4762,6 @@ fn arrayAccess(
4748) InnerError!Zir.Inst.Ref {4762) InnerError!Zir.Inst.Ref {
4749 const astgen = gz.astgen;4763 const astgen = gz.astgen;
4750 const tree = astgen.tree;4764 const tree = astgen.tree;
4751 const main_tokens = tree.nodes.items(.main_token);
4752 const node_datas = tree.nodes.items(.data);4765 const node_datas = tree.nodes.items(.data);
4753 switch (rl) {4766 switch (rl) {
4754 .ref => return gz.addBin(4767 .ref => return gz.addBin(
...@@ -4756,7 +4769,7 @@ fn arrayAccess(...@@ -4756,7 +4769,7 @@ fn arrayAccess(
4756 try expr(gz, scope, .ref, node_datas[node].lhs),4769 try expr(gz, scope, .ref, node_datas[node].lhs),
4757 try expr(gz, scope, .{ .ty = .usize_type }, node_datas[node].rhs),4770 try expr(gz, scope, .{ .ty = .usize_type }, node_datas[node].rhs),
4758 ),4771 ),
4759 else => return rvalue(gz, scope, rl, try gz.addBin(4772 else => return rvalue(gz, rl, try gz.addBin(
4760 .elem_val,4773 .elem_val,
4761 try expr(gz, scope, .none_or_ref, node_datas[node].lhs),4774 try expr(gz, scope, .none_or_ref, node_datas[node].lhs),
4762 try expr(gz, scope, .{ .ty = .usize_type }, node_datas[node].rhs),4775 try expr(gz, scope, .{ .ty = .usize_type }, node_datas[node].rhs),
...@@ -4779,12 +4792,11 @@ fn simpleBinOp(...@@ -4779,12 +4792,11 @@ fn simpleBinOp(
4779 .lhs = try expr(gz, scope, .none, node_datas[node].lhs),4792 .lhs = try expr(gz, scope, .none, node_datas[node].lhs),
4780 .rhs = try expr(gz, scope, .none, node_datas[node].rhs),4793 .rhs = try expr(gz, scope, .none, node_datas[node].rhs),
4781 });4794 });
4782 return rvalue(gz, scope, rl, result, node);4795 return rvalue(gz, rl, result, node);
4783}4796}
47844797
4785fn simpleStrTok(4798fn simpleStrTok(
4786 gz: *GenZir,4799 gz: *GenZir,
4787 scope: *Scope,
4788 rl: ResultLoc,4800 rl: ResultLoc,
4789 ident_token: ast.TokenIndex,4801 ident_token: ast.TokenIndex,
4790 node: ast.Node.Index,4802 node: ast.Node.Index,
...@@ -4793,7 +4805,7 @@ fn simpleStrTok(...@@ -4793,7 +4805,7 @@ fn simpleStrTok(
4793 const astgen = gz.astgen;4805 const astgen = gz.astgen;
4794 const str_index = try astgen.identAsString(ident_token);4806 const str_index = try astgen.identAsString(ident_token);
4795 const result = try gz.addStrTok(op_inst_tag, str_index, ident_token);4807 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);
4797}4809}
47984810
4799fn boolBinOp(4811fn boolBinOp(
...@@ -4819,7 +4831,7 @@ fn boolBinOp(...@@ -4819,7 +4831,7 @@ fn boolBinOp(
4819 try rhs_scope.setBoolBrBody(bool_br);4831 try rhs_scope.setBoolBrBody(bool_br);
48204832
4821 const block_ref = gz.indexToRef(bool_br);4833 const block_ref = gz.indexToRef(bool_br);
4822 return rvalue(gz, scope, rl, block_ref, node);4834 return rvalue(gz, rl, block_ref, node);
4823}4835}
48244836
4825fn ifExpr(4837fn ifExpr(
...@@ -4846,7 +4858,7 @@ fn ifExpr(...@@ -4846,7 +4858,7 @@ fn ifExpr(
4846 inst: Zir.Inst.Ref,4858 inst: Zir.Inst.Ref,
4847 bool_bit: Zir.Inst.Ref,4859 bool_bit: Zir.Inst.Ref,
4848 } = c: {4860 } = c: {
4849 if (if_full.error_token) |error_token| {4861 if (if_full.error_token) |_| {
4850 const cond_rl: ResultLoc = if (payload_is_ref) .ref else .none;4862 const cond_rl: ResultLoc = if (payload_is_ref) .ref else .none;
4851 const err_union = try expr(&block_scope, &block_scope.base, cond_rl, if_full.ast.cond_expr);4863 const err_union = try expr(&block_scope, &block_scope.base, cond_rl, if_full.ast.cond_expr);
4852 const tag: Zir.Inst.Tag = if (payload_is_ref) .is_err_ptr else .is_err;4864 const tag: Zir.Inst.Tag = if (payload_is_ref) .is_err_ptr else .is_err;
...@@ -4854,7 +4866,7 @@ fn ifExpr(...@@ -4854,7 +4866,7 @@ fn ifExpr(
4854 .inst = err_union,4866 .inst = err_union,
4855 .bool_bit = try block_scope.addUnNode(tag, err_union, node),4867 .bool_bit = try block_scope.addUnNode(tag, err_union, node),
4856 };4868 };
4857 } else if (if_full.payload_token) |payload_token| {4869 } else if (if_full.payload_token) |_| {
4858 const cond_rl: ResultLoc = if (payload_is_ref) .ref else .none;4870 const cond_rl: ResultLoc = if (payload_is_ref) .ref else .none;
4859 const optional = try expr(&block_scope, &block_scope.base, cond_rl, if_full.ast.cond_expr);4871 const optional = try expr(&block_scope, &block_scope.base, cond_rl, if_full.ast.cond_expr);
4860 const tag: Zir.Inst.Tag = if (payload_is_ref) .is_non_null_ptr else .is_non_null;4872 const tag: Zir.Inst.Tag = if (payload_is_ref) .is_non_null_ptr else .is_non_null;
...@@ -4883,27 +4895,38 @@ fn ifExpr(...@@ -4883,27 +4895,38 @@ fn ifExpr(
4883 var payload_val_scope: Scope.LocalVal = undefined;4895 var payload_val_scope: Scope.LocalVal = undefined;
48844896
4885 const then_sub_scope = s: {4897 const then_sub_scope = s: {
4886 if (if_full.error_token) |error_token| {4898 if (if_full.error_token != null) {
4887 const tag: Zir.Inst.Tag = if (payload_is_ref)4899 if (if_full.payload_token) |payload_token| {
4888 .err_union_payload_unsafe_ptr4900 const tag: Zir.Inst.Tag = if (payload_is_ref)
4889 else4901 .err_union_payload_unsafe_ptr
4890 .err_union_payload_unsafe;4902 else
4891 const payload_inst = try then_scope.addUnNode(tag, cond.inst, node);4903 .err_union_payload_unsafe;
4892 const ident_name = try astgen.identAsString(error_token);4904 const payload_inst = try then_scope.addUnNode(tag, cond.inst, node);
4893 payload_val_scope = .{4905 const token_name_index = payload_token + @boolToInt(payload_is_ref);
4894 .parent = &then_scope.base,4906 const ident_name = try astgen.identAsString(token_name_index);
4895 .gen_zir = &then_scope,4907 const token_name_str = tree.tokenSlice(token_name_index);
4896 .name = ident_name,4908 if (mem.eql(u8, "_", token_name_str))
4897 .inst = payload_inst,4909 break :s &then_scope.base;
4898 .token_src = error_token,4910 payload_val_scope = .{
4899 };4911 .parent = &then_scope.base,
4900 break :s &payload_val_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 }
4901 } else if (if_full.payload_token) |payload_token| {4922 } else if (if_full.payload_token) |payload_token| {
4902 const ident_token = if (payload_is_ref) payload_token + 1 else payload_token;4923 const ident_token = if (payload_is_ref) payload_token + 1 else payload_token;
4903 const tag: Zir.Inst.Tag = if (payload_is_ref)4924 const tag: Zir.Inst.Tag = if (payload_is_ref)
4904 .optional_payload_unsafe_ptr4925 .optional_payload_unsafe_ptr
4905 else4926 else
4906 .optional_payload_unsafe;4927 .optional_payload_unsafe;
4928 if (mem.eql(u8, "_", tree.tokenSlice(ident_token)))
4929 break :s &then_scope.base;
4907 const payload_inst = try then_scope.addUnNode(tag, cond.inst, node);4930 const payload_inst = try then_scope.addUnNode(tag, cond.inst, node);
4908 const ident_name = try astgen.identAsString(ident_token);4931 const ident_name = try astgen.identAsString(ident_token);
4909 payload_val_scope = .{4932 payload_val_scope = .{
...@@ -4912,6 +4935,7 @@ fn ifExpr(...@@ -4912,6 +4935,7 @@ fn ifExpr(
4912 .name = ident_name,4935 .name = ident_name,
4913 .inst = payload_inst,4936 .inst = payload_inst,
4914 .token_src = ident_token,4937 .token_src = ident_token,
4938 .used = .capture,
4915 };4939 };
4916 break :s &payload_val_scope.base;4940 break :s &payload_val_scope.base;
4917 } else {4941 } else {
...@@ -4921,6 +4945,7 @@ fn ifExpr(...@@ -4921,6 +4945,7 @@ fn ifExpr(
49214945
4922 block_scope.break_count += 1;4946 block_scope.break_count += 1;
4923 const then_result = try expr(&then_scope, then_sub_scope, block_scope.break_result_loc, if_full.ast.then_expr);4947 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);
4924 // We hold off on the break instructions as well as copying the then/else4949 // We hold off on the break instructions as well as copying the then/else
4925 // instructions into place until we know whether to keep store_to_block_ptr4950 // instructions into place until we know whether to keep store_to_block_ptr
4926 // instructions or not.4951 // instructions or not.
...@@ -4942,21 +4967,27 @@ fn ifExpr(...@@ -4942,21 +4967,27 @@ fn ifExpr(
4942 .err_union_code;4967 .err_union_code;
4943 const payload_inst = try else_scope.addUnNode(tag, cond.inst, node);4968 const payload_inst = try else_scope.addUnNode(tag, cond.inst, node);
4944 const ident_name = try astgen.identAsString(error_token);4969 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;
4945 payload_val_scope = .{4973 payload_val_scope = .{
4946 .parent = &else_scope.base,4974 .parent = &else_scope.base,
4947 .gen_zir = &else_scope,4975 .gen_zir = &else_scope,
4948 .name = ident_name,4976 .name = ident_name,
4949 .inst = payload_inst,4977 .inst = payload_inst,
4950 .token_src = error_token,4978 .token_src = error_token,
4979 .used = .capture,
4951 };4980 };
4952 break :s &payload_val_scope.base;4981 break :s &payload_val_scope.base;
4953 } else {4982 } else {
4954 break :s &else_scope.base;4983 break :s &else_scope.base;
4955 }4984 }
4956 };4985 };
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);
4957 break :blk .{4988 break :blk .{
4958 .src = else_node,4989 .src = else_node,
4959 .result = try expr(&else_scope, sub_scope, block_scope.break_result_loc, else_node),4990 .result = e,
4960 };4991 };
4961 } else .{4992 } else .{
4962 .src = if_full.ast.then_expr,4993 .src = if_full.ast.then_expr,
...@@ -4965,7 +4996,6 @@ fn ifExpr(...@@ -4965,7 +4996,6 @@ fn ifExpr(
49654996
4966 return finishThenElseBlock(4997 return finishThenElseBlock(
4967 parent_gz,4998 parent_gz,
4968 scope,
4969 rl,4999 rl,
4970 node,5000 node,
4971 &block_scope,5001 &block_scope,
...@@ -4973,8 +5003,6 @@ fn ifExpr(...@@ -4973,8 +5003,6 @@ fn ifExpr(
4973 &else_scope,5003 &else_scope,
4974 condbr,5004 condbr,
4975 cond.bool_bit,5005 cond.bool_bit,
4976 if_full.ast.then_expr,
4977 else_info.src,
4978 then_result,5006 then_result,
4979 else_info.result,5007 else_info.result,
4980 block,5008 block,
...@@ -5087,7 +5115,7 @@ fn whileExpr(...@@ -5087,7 +5115,7 @@ fn whileExpr(
5087 inst: Zir.Inst.Ref,5115 inst: Zir.Inst.Ref,
5088 bool_bit: Zir.Inst.Ref,5116 bool_bit: Zir.Inst.Ref,
5089 } = c: {5117 } = c: {
5090 if (while_full.error_token) |error_token| {5118 if (while_full.error_token) |_| {
5091 const cond_rl: ResultLoc = if (payload_is_ref) .ref else .none;5119 const cond_rl: ResultLoc = if (payload_is_ref) .ref else .none;
5092 const err_union = try expr(&continue_scope, &continue_scope.base, cond_rl, while_full.ast.cond_expr);5120 const err_union = try expr(&continue_scope, &continue_scope.base, cond_rl, while_full.ast.cond_expr);
5093 const tag: Zir.Inst.Tag = if (payload_is_ref) .is_err_ptr else .is_err;5121 const tag: Zir.Inst.Tag = if (payload_is_ref) .is_err_ptr else .is_err;
...@@ -5095,7 +5123,7 @@ fn whileExpr(...@@ -5095,7 +5123,7 @@ fn whileExpr(
5095 .inst = err_union,5123 .inst = err_union,
5096 .bool_bit = try continue_scope.addUnNode(tag, err_union, node),5124 .bool_bit = try continue_scope.addUnNode(tag, err_union, node),
5097 };5125 };
5098 } else if (while_full.payload_token) |payload_token| {5126 } else if (while_full.payload_token) |_| {
5099 const cond_rl: ResultLoc = if (payload_is_ref) .ref else .none;5127 const cond_rl: ResultLoc = if (payload_is_ref) .ref else .none;
5100 const optional = try expr(&continue_scope, &continue_scope.base, cond_rl, while_full.ast.cond_expr);5128 const optional = try expr(&continue_scope, &continue_scope.base, cond_rl, while_full.ast.cond_expr);
5101 const tag: Zir.Inst.Tag = if (payload_is_ref) .is_non_null_ptr else .is_non_null;5129 const tag: Zir.Inst.Tag = if (payload_is_ref) .is_non_null_ptr else .is_non_null;
...@@ -5119,46 +5147,35 @@ fn whileExpr(...@@ -5119,46 +5147,35 @@ fn whileExpr(
5119 try loop_scope.instructions.append(astgen.gpa, cond_block);5147 try loop_scope.instructions.append(astgen.gpa, cond_block);
5120 try continue_scope.setBlockBody(cond_block);5148 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
5141 var then_scope = parent_gz.makeSubBlock(&continue_scope.base);5150 var then_scope = parent_gz.makeSubBlock(&continue_scope.base);
5142 defer then_scope.instructions.deinit(astgen.gpa);5151 defer then_scope.instructions.deinit(astgen.gpa);
51435152
5144 var payload_val_scope: Scope.LocalVal = undefined;5153 var payload_val_scope: Scope.LocalVal = undefined;
51455154
5146 const then_sub_scope = s: {5155 const then_sub_scope = s: {
5147 if (while_full.error_token) |error_token| {5156 if (while_full.error_token != null) {
5148 const tag: Zir.Inst.Tag = if (payload_is_ref)5157 if (while_full.payload_token) |payload_token| {
5149 .err_union_payload_unsafe_ptr5158 const tag: Zir.Inst.Tag = if (payload_is_ref)
5150 else5159 .err_union_payload_unsafe_ptr
5151 .err_union_payload_unsafe;5160 else
5152 const payload_inst = try then_scope.addUnNode(tag, cond.inst, node);5161 .err_union_payload_unsafe;
5153 const ident_name = try astgen.identAsString(error_token);5162 const payload_inst = try then_scope.addUnNode(tag, cond.inst, node);
5154 payload_val_scope = .{5163 const ident_token = if (payload_is_ref) payload_token + 1 else payload_token;
5155 .parent = &then_scope.base,5164 if (mem.eql(u8, "_", tree.tokenSlice(ident_token)))
5156 .gen_zir = &then_scope,5165 break :s &then_scope.base;
5157 .name = ident_name,5166 const ident_name = try astgen.identAsString(payload_token + @boolToInt(payload_is_ref));
5158 .inst = payload_inst,5167 payload_val_scope = .{
5159 .token_src = error_token,5168 .parent = &then_scope.base,
5160 };5169 .gen_zir = &then_scope,
5161 break :s &payload_val_scope.base;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 }
5162 } else if (while_full.payload_token) |payload_token| {5179 } else if (while_full.payload_token) |payload_token| {
5163 const ident_token = if (payload_is_ref) payload_token + 1 else payload_token;5180 const ident_token = if (payload_is_ref) payload_token + 1 else payload_token;
5164 const tag: Zir.Inst.Tag = if (payload_is_ref)5181 const tag: Zir.Inst.Tag = if (payload_is_ref)
...@@ -5167,12 +5184,15 @@ fn whileExpr(...@@ -5167,12 +5184,15 @@ fn whileExpr(
5167 .optional_payload_unsafe;5184 .optional_payload_unsafe;
5168 const payload_inst = try then_scope.addUnNode(tag, cond.inst, node);5185 const payload_inst = try then_scope.addUnNode(tag, cond.inst, node);
5169 const ident_name = try astgen.identAsString(ident_token);5186 const ident_name = try astgen.identAsString(ident_token);
5187 if (mem.eql(u8, "_", tree.tokenSlice(ident_token)))
5188 break :s &then_scope.base;
5170 payload_val_scope = .{5189 payload_val_scope = .{
5171 .parent = &then_scope.base,5190 .parent = &then_scope.base,
5172 .gen_zir = &then_scope,5191 .gen_zir = &then_scope,
5173 .name = ident_name,5192 .name = ident_name,
5174 .inst = payload_inst,5193 .inst = payload_inst,
5175 .token_src = ident_token,5194 .token_src = ident_token,
5195 .used = .capture,
5176 };5196 };
5177 break :s &payload_val_scope.base;5197 break :s &payload_val_scope.base;
5178 } else {5198 } else {
...@@ -5180,8 +5200,29 @@ fn whileExpr(...@@ -5180,8 +5200,29 @@ fn whileExpr(
5180 }5200 }
5181 };5201 };
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
5183 loop_scope.break_count += 1;5223 loop_scope.break_count += 1;
5184 const then_result = try expr(&then_scope, then_sub_scope, loop_scope.break_result_loc, while_full.ast.then_expr);5224 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
5186 var else_scope = parent_gz.makeSubBlock(&continue_scope.base);5227 var else_scope = parent_gz.makeSubBlock(&continue_scope.base);
5187 defer else_scope.instructions.deinit(astgen.gpa);5228 defer else_scope.instructions.deinit(astgen.gpa);
...@@ -5200,21 +5241,26 @@ fn whileExpr(...@@ -5200,21 +5241,26 @@ fn whileExpr(
5200 .err_union_code;5241 .err_union_code;
5201 const payload_inst = try else_scope.addUnNode(tag, cond.inst, node);5242 const payload_inst = try else_scope.addUnNode(tag, cond.inst, node);
5202 const ident_name = try astgen.identAsString(error_token);5243 const ident_name = try astgen.identAsString(error_token);
5244 if (mem.eql(u8, tree.tokenSlice(error_token), "_"))
5245 break :s &else_scope.base;
5203 payload_val_scope = .{5246 payload_val_scope = .{
5204 .parent = &else_scope.base,5247 .parent = &else_scope.base,
5205 .gen_zir = &else_scope,5248 .gen_zir = &else_scope,
5206 .name = ident_name,5249 .name = ident_name,
5207 .inst = payload_inst,5250 .inst = payload_inst,
5208 .token_src = error_token,5251 .token_src = error_token,
5252 .used = .capture,
5209 };5253 };
5210 break :s &payload_val_scope.base;5254 break :s &payload_val_scope.base;
5211 } else {5255 } else {
5212 break :s &else_scope.base;5256 break :s &else_scope.base;
5213 }5257 }
5214 };5258 };
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);
5215 break :blk .{5261 break :blk .{
5216 .src = else_node,5262 .src = else_node,
5217 .result = try expr(&else_scope, sub_scope, loop_scope.break_result_loc, else_node),5263 .result = e,
5218 };5264 };
5219 } else .{5265 } else .{
5220 .src = while_full.ast.then_expr,5266 .src = while_full.ast.then_expr,
...@@ -5229,7 +5275,6 @@ fn whileExpr(...@@ -5229,7 +5275,6 @@ fn whileExpr(
5229 const break_tag: Zir.Inst.Tag = if (is_inline) .break_inline else .@"break";5275 const break_tag: Zir.Inst.Tag = if (is_inline) .break_inline else .@"break";
5230 return finishThenElseBlock(5276 return finishThenElseBlock(
5231 parent_gz,5277 parent_gz,
5232 scope,
5233 rl,5278 rl,
5234 node,5279 node,
5235 &loop_scope,5280 &loop_scope,
...@@ -5237,8 +5282,6 @@ fn whileExpr(...@@ -5237,8 +5282,6 @@ fn whileExpr(
5237 &else_scope,5282 &else_scope,
5238 condbr,5283 condbr,
5239 cond.bool_bit,5284 cond.bool_bit,
5240 while_full.ast.then_expr,
5241 else_info.src,
5242 then_result,5285 then_result,
5243 else_info.result,5286 else_info.result,
5244 loop_block,5287 loop_block,
...@@ -5345,6 +5388,7 @@ fn forExpr(...@@ -5345,6 +5388,7 @@ fn forExpr(
5345 .name = name_str_index,5388 .name = name_str_index,
5346 .inst = payload_inst,5389 .inst = payload_inst,
5347 .token_src = ident,5390 .token_src = ident,
5391 .used = .capture,
5348 };5392 };
5349 payload_sub_scope = &payload_val_scope.base;5393 payload_sub_scope = &payload_val_scope.base;
5350 } else if (is_ptr) {5394 } else if (is_ptr) {
...@@ -5367,13 +5411,15 @@ fn forExpr(...@@ -5367,13 +5411,15 @@ fn forExpr(
5367 .name = index_name,5411 .name = index_name,
5368 .ptr = index_ptr,5412 .ptr = index_ptr,
5369 .token_src = index_token,5413 .token_src = index_token,
5370 .is_comptime = parent_gz.force_comptime,5414 .maybe_comptime = is_inline,
5415 .used = .loop_index,
5371 };5416 };
5372 break :blk &index_scope.base;5417 break :blk &index_scope.base;
5373 };5418 };
53745419
5375 loop_scope.break_count += 1;5420 loop_scope.break_count += 1;
5376 const then_result = try expr(&then_scope, then_sub_scope, loop_scope.break_result_loc, for_full.ast.then_expr);5421 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
5378 var else_scope = parent_gz.makeSubBlock(&cond_scope.base);5424 var else_scope = parent_gz.makeSubBlock(&cond_scope.base);
5379 defer else_scope.instructions.deinit(astgen.gpa);5425 defer else_scope.instructions.deinit(astgen.gpa);
...@@ -5402,7 +5448,6 @@ fn forExpr(...@@ -5402,7 +5448,6 @@ fn forExpr(
5402 const break_tag: Zir.Inst.Tag = if (is_inline) .break_inline else .@"break";5448 const break_tag: Zir.Inst.Tag = if (is_inline) .break_inline else .@"break";
5403 return finishThenElseBlock(5449 return finishThenElseBlock(
5404 parent_gz,5450 parent_gz,
5405 scope,
5406 rl,5451 rl,
5407 node,5452 node,
5408 &loop_scope,5453 &loop_scope,
...@@ -5410,8 +5455,6 @@ fn forExpr(...@@ -5410,8 +5455,6 @@ fn forExpr(
5410 &else_scope,5455 &else_scope,
5411 condbr,5456 condbr,
5412 cond,5457 cond,
5413 for_full.ast.then_expr,
5414 else_info.src,
5415 then_result,5458 then_result,
5416 else_info.result,5459 else_info.result,
5417 loop_block,5460 loop_block,
...@@ -5614,10 +5657,12 @@ fn switchExpr(...@@ -5614,10 +5657,12 @@ fn switchExpr(
5614 .name = capture_name,5657 .name = capture_name,
5615 .inst = capture,5658 .inst = capture,
5616 .token_src = payload_token,5659 .token_src = payload_token,
5660 .used = .capture,
5617 };5661 };
5618 break :blk &capture_val_scope.base;5662 break :blk &capture_val_scope.base;
5619 };5663 };
5620 const case_result = try expr(&case_scope, sub_scope, block_scope.break_result_loc, case.ast.target_expr);5664 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);
5621 if (!parent_gz.refIsNoReturn(case_result)) {5666 if (!parent_gz.refIsNoReturn(case_result)) {
5622 block_scope.break_count += 1;5667 block_scope.break_count += 1;
5623 _ = try case_scope.addBreak(.@"break", switch_block, case_result);5668 _ = try case_scope.addBreak(.@"break", switch_block, case_result);
...@@ -5706,6 +5751,7 @@ fn switchExpr(...@@ -5706,6 +5751,7 @@ fn switchExpr(
5706 .name = capture_name,5751 .name = capture_name,
5707 .inst = capture,5752 .inst = capture,
5708 .token_src = payload_token,5753 .token_src = payload_token,
5754 .used = .capture,
5709 };5755 };
5710 break :blk &capture_val_scope.base;5756 break :blk &capture_val_scope.base;
5711 };5757 };
...@@ -5739,6 +5785,7 @@ fn switchExpr(...@@ -5739,6 +5785,7 @@ fn switchExpr(
5739 }5785 }
57405786
5741 const case_result = try expr(&case_scope, sub_scope, block_scope.break_result_loc, case.ast.target_expr);5787 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);
5742 if (!parent_gz.refIsNoReturn(case_result)) {5789 if (!parent_gz.refIsNoReturn(case_result)) {
5743 block_scope.break_count += 1;5790 block_scope.break_count += 1;
5744 _ = try case_scope.addBreak(.@"break", switch_block, case_result);5791 _ = try case_scope.addBreak(.@"break", switch_block, case_result);
...@@ -5752,6 +5799,7 @@ fn switchExpr(...@@ -5752,6 +5799,7 @@ fn switchExpr(
5752 const item_node = case.ast.values[0];5799 const item_node = case.ast.values[0];
5753 const item_inst = try comptimeExpr(parent_gz, scope, item_rl, item_node);5800 const item_inst = try comptimeExpr(parent_gz, scope, item_rl, item_node);
5754 const case_result = try expr(&case_scope, sub_scope, block_scope.break_result_loc, case.ast.target_expr);5801 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);
5755 if (!parent_gz.refIsNoReturn(case_result)) {5803 if (!parent_gz.refIsNoReturn(case_result)) {
5756 block_scope.break_count += 1;5804 block_scope.break_count += 1;
5757 _ = try case_scope.addBreak(.@"break", switch_block, case_result);5805 _ = try case_scope.addBreak(.@"break", switch_block, case_result);
...@@ -5950,7 +5998,7 @@ fn switchExpr(...@@ -5950,7 +5998,7 @@ fn switchExpr(
5950 const block_ref = parent_gz.indexToRef(switch_block);5998 const block_ref = parent_gz.indexToRef(switch_block);
5951 switch (rl) {5999 switch (rl) {
5952 .ref => return block_ref,6000 .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),
5954 }6002 }
5955 },6003 },
5956 .break_void => {6004 .break_void => {
...@@ -6016,7 +6064,6 @@ fn ret(gz: *GenZir, scope: *Scope, node: ast.Node.Index) InnerError!Zir.Inst.Ref...@@ -6016,7 +6064,6 @@ fn ret(gz: *GenZir, scope: *Scope, node: ast.Node.Index) InnerError!Zir.Inst.Ref
6016 const astgen = gz.astgen;6064 const astgen = gz.astgen;
6017 const tree = astgen.tree;6065 const tree = astgen.tree;
6018 const node_datas = tree.nodes.items(.data);6066 const node_datas = tree.nodes.items(.data);
6019 const main_tokens = tree.nodes.items(.main_token);
60206067
6021 if (gz.in_defer) return astgen.failNode(node, "cannot return from defer expression", .{});6068 if (gz.in_defer) return astgen.failNode(node, "cannot return from defer expression", .{});
60226069
...@@ -6092,7 +6139,7 @@ fn identifier(...@@ -6092,7 +6139,7 @@ fn identifier(
6092 }6139 }
60936140
6094 if (simple_types.get(ident_name)) |zir_const_ref| {6141 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);
6096 }6143 }
60976144
6098 if (ident_name.len >= 2) integer: {6145 if (ident_name.len >= 2) integer: {
...@@ -6118,7 +6165,7 @@ fn identifier(...@@ -6118,7 +6165,7 @@ fn identifier(
6118 .bit_count = bit_count,6165 .bit_count = bit_count,
6119 } },6166 } },
6120 });6167 });
6121 return rvalue(gz, scope, rl, result, ident);6168 return rvalue(gz, rl, result, ident);
6122 }6169 }
6123 }6170 }
61246171
...@@ -6131,33 +6178,37 @@ fn identifier(...@@ -6131,33 +6178,37 @@ fn identifier(
6131 while (true) switch (s.tag) {6178 while (true) switch (s.tag) {
6132 .local_val => {6179 .local_val => {
6133 const local_val = s.cast(Scope.LocalVal).?;6180 const local_val = s.cast(Scope.LocalVal).?;
6134 if (hit_namespace) {6181
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 }
6139 if (local_val.name == name_str_index) {6182 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 }
6141 }6189 }
6142 s = local_val.parent;6190 s = local_val.parent;
6143 },6191 },
6144 .local_ptr => {6192 .local_ptr => {
6145 const local_ptr = s.cast(Scope.LocalPtr).?;6193 const local_ptr = s.cast(Scope.LocalPtr).?;
6146 if (local_ptr.name == name_str_index) {6194 if (local_ptr.name == name_str_index) {
6195 local_ptr.used = .used;
6147 if (hit_namespace) {6196 if (hit_namespace) {
6148 if (local_ptr.is_comptime)6197 if (local_ptr.maybe_comptime)
6149 break6198 break
6150 else6199 else
6151 return astgen.failNodeNotes(ident, "'{s}' not accessible from inner function", .{ident_name}, &.{6200 return astgen.failNodeNotes(ident, "'{s}' not accessible from inner function", .{ident_name}, &.{
6152 try astgen.errNoteTok(local_ptr.token_src, "declared here", .{}),6201 try astgen.errNoteTok(local_ptr.token_src, "declared here", .{}),
6153 // TODO add crossed function definition here note.6202 // 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
6154 });6205 });
6155 }6206 }
6156 switch (rl) {6207 switch (rl) {
6157 .ref, .none_or_ref => return local_ptr.ptr,6208 .ref, .none_or_ref => return local_ptr.ptr,
6158 else => {6209 else => {
6159 const loaded = try gz.addUnNode(.load, local_ptr.ptr, ident);6210 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);
6161 },6212 },
6162 }6213 }
6163 }6214 }
...@@ -6191,14 +6242,13 @@ fn identifier(...@@ -6191,14 +6242,13 @@ fn identifier(
6191 .ref, .none_or_ref => return gz.addStrTok(.decl_ref, name_str_index, ident_token),6242 .ref, .none_or_ref => return gz.addStrTok(.decl_ref, name_str_index, ident_token),
6192 else => {6243 else => {
6193 const result = try gz.addStrTok(.decl_val, name_str_index, ident_token);6244 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);
6195 },6246 },
6196 }6247 }
6197}6248}
61986249
6199fn stringLiteral(6250fn stringLiteral(
6200 gz: *GenZir,6251 gz: *GenZir,
6201 scope: *Scope,
6202 rl: ResultLoc,6252 rl: ResultLoc,
6203 node: ast.Node.Index,6253 node: ast.Node.Index,
6204) InnerError!Zir.Inst.Ref {6254) InnerError!Zir.Inst.Ref {
...@@ -6214,19 +6264,17 @@ fn stringLiteral(...@@ -6214,19 +6264,17 @@ fn stringLiteral(
6214 .len = str.len,6264 .len = str.len,
6215 } },6265 } },
6216 });6266 });
6217 return rvalue(gz, scope, rl, result, node);6267 return rvalue(gz, rl, result, node);
6218}6268}
62196269
6220fn multilineStringLiteral(6270fn multilineStringLiteral(
6221 gz: *GenZir,6271 gz: *GenZir,
6222 scope: *Scope,
6223 rl: ResultLoc,6272 rl: ResultLoc,
6224 node: ast.Node.Index,6273 node: ast.Node.Index,
6225) InnerError!Zir.Inst.Ref {6274) InnerError!Zir.Inst.Ref {
6226 const astgen = gz.astgen;6275 const astgen = gz.astgen;
6227 const tree = astgen.tree;6276 const tree = astgen.tree;
6228 const node_datas = tree.nodes.items(.data);6277 const node_datas = tree.nodes.items(.data);
6229 const main_tokens = tree.nodes.items(.main_token);
62306278
6231 const start = node_datas[node].lhs;6279 const start = node_datas[node].lhs;
6232 const end = node_datas[node].rhs;6280 const end = node_datas[node].rhs;
...@@ -6258,10 +6306,10 @@ fn multilineStringLiteral(...@@ -6258,10 +6306,10 @@ fn multilineStringLiteral(
6258 .len = @intCast(u32, string_bytes.items.len - str_index),6306 .len = @intCast(u32, string_bytes.items.len - str_index),
6259 } },6307 } },
6260 });6308 });
6261 return rvalue(gz, scope, rl, result, node);6309 return rvalue(gz, rl, result, node);
6262}6310}
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 {
6265 const astgen = gz.astgen;6313 const astgen = gz.astgen;
6266 const tree = astgen.tree;6314 const tree = astgen.tree;
6267 const main_tokens = tree.nodes.items(.main_token);6315 const main_tokens = tree.nodes.items(.main_token);
...@@ -6281,15 +6329,10 @@ fn charLiteral(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index)...@@ -6281,15 +6329,10 @@ fn charLiteral(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index)
6281 },6329 },
6282 };6330 };
6283 const result = try gz.addInt(value);6331 const result = try gz.addInt(value);
6284 return rvalue(gz, scope, rl, result, node);6332 return rvalue(gz, rl, result, node);
6285}6333}
62866334
6287fn integerLiteral(6335fn integerLiteral(gz: *GenZir, rl: ResultLoc, node: ast.Node.Index) InnerError!Zir.Inst.Ref {
6288 gz: *GenZir,
6289 scope: *Scope,
6290 rl: ResultLoc,
6291 node: ast.Node.Index,
6292) InnerError!Zir.Inst.Ref {
6293 const astgen = gz.astgen;6336 const astgen = gz.astgen;
6294 const tree = astgen.tree;6337 const tree = astgen.tree;
6295 const main_tokens = tree.nodes.items(.main_token);6338 const main_tokens = tree.nodes.items(.main_token);
...@@ -6301,7 +6344,7 @@ fn integerLiteral(...@@ -6301,7 +6344,7 @@ fn integerLiteral(
6301 1 => .one,6344 1 => .one,
6302 else => try gz.addInt(small_int),6345 else => try gz.addInt(small_int),
6303 };6346 };
6304 return rvalue(gz, scope, rl, result, node);6347 return rvalue(gz, rl, result, node);
6305 } else |err| switch (err) {6348 } else |err| switch (err) {
6306 error.InvalidCharacter => unreachable, // Caught by the parser.6349 error.InvalidCharacter => unreachable, // Caught by the parser.
6307 error.Overflow => {},6350 error.Overflow => {},
...@@ -6332,17 +6375,11 @@ fn integerLiteral(...@@ -6332,17 +6375,11 @@ fn integerLiteral(
6332 const limbs = big_int.limbs[0..big_int.len()];6375 const limbs = big_int.limbs[0..big_int.len()];
6333 assert(big_int.isPositive());6376 assert(big_int.isPositive());
6334 const result = try gz.addIntBig(limbs);6377 const result = try gz.addIntBig(limbs);
6335 return rvalue(gz, scope, rl, result, node);6378 return rvalue(gz, rl, result, node);
6336}6379}
63376380
6338fn floatLiteral(6381fn floatLiteral(gz: *GenZir, rl: ResultLoc, node: ast.Node.Index) InnerError!Zir.Inst.Ref {
6339 gz: *GenZir,
6340 scope: *Scope,
6341 rl: ResultLoc,
6342 node: ast.Node.Index,
6343) InnerError!Zir.Inst.Ref {
6344 const astgen = gz.astgen;6382 const astgen = gz.astgen;
6345 const arena = astgen.arena;
6346 const tree = astgen.tree;6383 const tree = astgen.tree;
6347 const main_tokens = tree.nodes.items(.main_token);6384 const main_tokens = tree.nodes.items(.main_token);
63486385
...@@ -6363,7 +6400,7 @@ fn floatLiteral(...@@ -6363,7 +6400,7 @@ fn floatLiteral(
6363 const bigger_again: f128 = smaller_float;6400 const bigger_again: f128 = smaller_float;
6364 if (bigger_again == float_number) {6401 if (bigger_again == float_number) {
6365 const result = try gz.addFloat(smaller_float, node);6402 const result = try gz.addFloat(smaller_float, node);
6366 return rvalue(gz, scope, rl, result, node);6403 return rvalue(gz, rl, result, node);
6367 }6404 }
6368 // We need to use 128 bits. Break the float into 4 u32 values so we can6405 // We need to use 128 bits. Break the float into 4 u32 values so we can
6369 // put it into the `extra` array.6406 // put it into the `extra` array.
...@@ -6374,7 +6411,7 @@ fn floatLiteral(...@@ -6374,7 +6411,7 @@ fn floatLiteral(
6374 .piece2 = @truncate(u32, int_bits >> 64),6411 .piece2 = @truncate(u32, int_bits >> 64),
6375 .piece3 = @truncate(u32, int_bits >> 96),6412 .piece3 = @truncate(u32, int_bits >> 96),
6376 });6413 });
6377 return rvalue(gz, scope, rl, result, node);6414 return rvalue(gz, rl, result, node);
6378}6415}
63796416
6380fn asmExpr(6417fn asmExpr(
...@@ -6385,7 +6422,6 @@ fn asmExpr(...@@ -6385,7 +6422,6 @@ fn asmExpr(
6385 full: ast.full.Asm,6422 full: ast.full.Asm,
6386) InnerError!Zir.Inst.Ref {6423) InnerError!Zir.Inst.Ref {
6387 const astgen = gz.astgen;6424 const astgen = gz.astgen;
6388 const arena = astgen.arena;
6389 const tree = astgen.tree;6425 const tree = astgen.tree;
6390 const main_tokens = tree.nodes.items(.main_token);6426 const main_tokens = tree.nodes.items(.main_token);
6391 const node_datas = tree.nodes.items(.data);6427 const node_datas = tree.nodes.items(.data);
...@@ -6427,6 +6463,33 @@ fn asmExpr(...@@ -6427,6 +6463,33 @@ fn asmExpr(
6427 // issues and decide how to handle outputs. Do we want this to be identifiers?6463 // issues and decide how to handle outputs. Do we want this to be identifiers?
6428 // Or maybe we want to force this to be expressions with a pointer type.6464 // Or maybe we want to force this to be expressions with a pointer type.
6429 // Until that is figured out this is only hooked up for referencing Decls.6465 // 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 }
6430 const operand = try gz.addStrTok(.decl_ref, str_index, ident_token);6493 const operand = try gz.addStrTok(.decl_ref, str_index, ident_token);
6431 outputs[i] = .{6494 outputs[i] = .{
6432 .name = name,6495 .name = name,
...@@ -6447,7 +6510,6 @@ fn asmExpr(...@@ -6447,7 +6510,6 @@ fn asmExpr(
6447 const name = try astgen.identAsString(symbolic_name);6510 const name = try astgen.identAsString(symbolic_name);
6448 const constraint_token = symbolic_name + 2;6511 const constraint_token = symbolic_name + 2;
6449 const constraint = (try astgen.strLitAsString(constraint_token)).index;6512 const constraint = (try astgen.strLitAsString(constraint_token)).index;
6450 const has_arrow = token_tags[symbolic_name + 4] == .arrow;
6451 const operand = try expr(gz, scope, .{ .ty = .usize_type }, node_datas[input_node].lhs);6513 const operand = try expr(gz, scope, .{ .ty = .usize_type }, node_datas[input_node].lhs);
6452 inputs[i] = .{6514 inputs[i] = .{
6453 .name = name,6515 .name = name,
...@@ -6492,7 +6554,7 @@ fn asmExpr(...@@ -6492,7 +6554,7 @@ fn asmExpr(
6492 .inputs = inputs,6554 .inputs = inputs,
6493 .clobbers = clobbers_buffer[0..clobber_i],6555 .clobbers = clobbers_buffer[0..clobber_i],
6494 });6556 });
6495 return rvalue(gz, scope, rl, result, node);6557 return rvalue(gz, rl, result, node);
6496}6558}
64976559
6498fn as(6560fn as(
...@@ -6507,7 +6569,7 @@ fn as(...@@ -6507,7 +6569,7 @@ fn as(
6507 switch (rl) {6569 switch (rl) {
6508 .none, .none_or_ref, .discard, .ref, .ty => {6570 .none, .none_or_ref, .discard, .ref, .ty => {
6509 const result = try expr(gz, scope, .{ .ty = dest_type }, rhs);6571 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);
6511 },6573 },
6512 .ptr, .inferred_ptr => |result_ptr| {6574 .ptr, .inferred_ptr => |result_ptr| {
6513 return asRlPtr(gz, scope, rl, result_ptr, rhs, dest_type);6575 return asRlPtr(gz, scope, rl, result_ptr, rhs, dest_type);
...@@ -6529,18 +6591,18 @@ fn unionInit(...@@ -6529,18 +6591,18 @@ fn unionInit(
6529 const field_name = try comptimeExpr(gz, scope, .{ .ty = .const_slice_u8_type }, params[1]);6591 const field_name = try comptimeExpr(gz, scope, .{ .ty = .const_slice_u8_type }, params[1]);
6530 switch (rl) {6592 switch (rl) {
6531 .none, .none_or_ref, .discard, .ref, .ty, .inferred_ptr => {6593 .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{
6533 .container_type = union_type,6595 .container_type = union_type,
6534 .field_name = field_name,6596 .field_name = field_name,
6535 });6597 });
6536 const result = try expr(gz, scope, .{ .ty = union_type }, params[2]);6598 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);
6538 },6600 },
6539 .ptr => |result_ptr| {6601 .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);
6541 },6603 },
6542 .block_ptr => |block_scope| {6604 .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);
6544 },6606 },
6545 }6607 }
6546}6608}
...@@ -6548,7 +6610,6 @@ fn unionInit(...@@ -6548,7 +6610,6 @@ fn unionInit(
6548fn unionInitRlPtr(6610fn unionInitRlPtr(
6549 parent_gz: *GenZir,6611 parent_gz: *GenZir,
6550 scope: *Scope,6612 scope: *Scope,
6551 rl: ResultLoc,
6552 node: ast.Node.Index,6613 node: ast.Node.Index,
6553 result_ptr: Zir.Inst.Ref,6614 result_ptr: Zir.Inst.Ref,
6554 expr_node: ast.Node.Index,6615 expr_node: ast.Node.Index,
...@@ -6596,7 +6657,7 @@ fn asRlPtr(...@@ -6596,7 +6657,7 @@ fn asRlPtr(
6596 parent_zir.appendAssumeCapacity(src_inst);6657 parent_zir.appendAssumeCapacity(src_inst);
6597 }6658 }
6598 const casted_result = try parent_gz.addBin(.as, dest_type, result);6659 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);
6600 } else {6661 } else {
6601 try parent_zir.appendSlice(astgen.gpa, as_scope.instructions.items);6662 try parent_zir.appendSlice(astgen.gpa, as_scope.instructions.items);
6602 return result;6663 return result;
...@@ -6620,16 +6681,16 @@ fn bitCast(...@@ -6620,16 +6681,16 @@ fn bitCast(
6620 .lhs = dest_type,6681 .lhs = dest_type,
6621 .rhs = operand,6682 .rhs = operand,
6622 });6683 });
6623 return rvalue(gz, scope, rl, result, node);6684 return rvalue(gz, rl, result, node);
6624 },6685 },
6625 .ref => {6686 .ref => {
6626 return astgen.failNode(node, "cannot take address of `@bitCast` result", .{});6687 return astgen.failNode(node, "cannot take address of `@bitCast` result", .{});
6627 },6688 },
6628 .ptr, .inferred_ptr => |result_ptr| {6689 .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);
6630 },6691 },
6631 .block_ptr => |block| {6692 .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);
6633 },6694 },
6634 }6695 }
6635}6696}
...@@ -6637,7 +6698,6 @@ fn bitCast(...@@ -6637,7 +6698,6 @@ fn bitCast(
6637fn bitCastRlPtr(6698fn bitCastRlPtr(
6638 gz: *GenZir,6699 gz: *GenZir,
6639 scope: *Scope,6700 scope: *Scope,
6640 rl: ResultLoc,
6641 node: ast.Node.Index,6701 node: ast.Node.Index,
6642 dest_type: Zir.Inst.Ref,6702 dest_type: Zir.Inst.Ref,
6643 result_ptr: Zir.Inst.Ref,6703 result_ptr: Zir.Inst.Ref,
...@@ -6662,7 +6722,7 @@ fn typeOf(...@@ -6662,7 +6722,7 @@ fn typeOf(
6662 }6722 }
6663 if (params.len == 1) {6723 if (params.len == 1) {
6664 const result = try gz.addUnNode(.typeof, try expr(gz, scope, .none, params[0]), node);6724 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);
6666 }6726 }
6667 const arena = gz.astgen.arena;6727 const arena = gz.astgen.arena;
6668 var items = try arena.alloc(Zir.Inst.Ref, params.len);6728 var items = try arena.alloc(Zir.Inst.Ref, params.len);
...@@ -6671,7 +6731,7 @@ fn typeOf(...@@ -6671,7 +6731,7 @@ fn typeOf(
6671 }6731 }
66726732
6673 const result = try gz.addExtendedMultiOp(.typeof_peer, node, items);6733 const result = try gz.addExtendedMultiOp(.typeof_peer, node, items);
6674 return rvalue(gz, scope, rl, result, node);6734 return rvalue(gz, rl, result, node);
6675}6735}
66766736
6677fn builtinCall(6737fn builtinCall(
...@@ -6711,7 +6771,6 @@ fn builtinCall(...@@ -6711,7 +6771,6 @@ fn builtinCall(
6711 switch (info.tag) {6771 switch (info.tag) {
6712 .import => {6772 .import => {
6713 const node_tags = tree.nodes.items(.tag);6773 const node_tags = tree.nodes.items(.tag);
6714 const node_datas = tree.nodes.items(.data);
6715 const operand_node = params[0];6774 const operand_node = params[0];
67166775
6717 if (node_tags[operand_node] != .string_literal) {6776 if (node_tags[operand_node] != .string_literal) {
...@@ -6722,7 +6781,7 @@ fn builtinCall(...@@ -6722,7 +6781,7 @@ fn builtinCall(
6722 const str = try astgen.strLitAsString(str_lit_token);6781 const str = try astgen.strLitAsString(str_lit_token);
6723 try astgen.imports.put(astgen.gpa, str.index, {});6782 try astgen.imports.put(astgen.gpa, str.index, {});
6724 const result = try gz.addStrTok(.import, str.index, str_lit_token);6783 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);
6726 },6785 },
6727 .compile_log => {6786 .compile_log => {
6728 const arg_refs = try astgen.gpa.alloc(Zir.Inst.Ref, params.len);6787 const arg_refs = try astgen.gpa.alloc(Zir.Inst.Ref, params.len);
...@@ -6731,7 +6790,7 @@ fn builtinCall(...@@ -6731,7 +6790,7 @@ fn builtinCall(
6731 for (params) |param, i| arg_refs[i] = try expr(gz, scope, .none, param);6790 for (params) |param, i| arg_refs[i] = try expr(gz, scope, .none, param);
67326791
6733 const result = try gz.addExtendedMultiOp(.compile_log, node, arg_refs);6792 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);
6735 },6794 },
6736 .field => {6795 .field => {
6737 const field_name = try comptimeExpr(gz, scope, .{ .ty = .const_slice_u8_type }, params[1]);6796 const field_name = try comptimeExpr(gz, scope, .{ .ty = .const_slice_u8_type }, params[1]);
...@@ -6745,7 +6804,7 @@ fn builtinCall(...@@ -6745,7 +6804,7 @@ fn builtinCall(
6745 .lhs = try expr(gz, scope, .none, params[0]),6804 .lhs = try expr(gz, scope, .none, params[0]),
6746 .field_name = field_name,6805 .field_name = field_name,
6747 });6806 });
6748 return rvalue(gz, scope, rl, result, node);6807 return rvalue(gz, rl, result, node);
6749 },6808 },
6750 .as => return as( gz, scope, rl, node, params[0], params[1]),6809 .as => return as( gz, scope, rl, node, params[0], params[1]),
6751 .bit_cast => return bitCast( gz, scope, rl, node, params[0], params[1]),6810 .bit_cast => return bitCast( gz, scope, rl, node, params[0], params[1]),
...@@ -6764,9 +6823,32 @@ fn builtinCall(...@@ -6764,9 +6823,32 @@ fn builtinCall(
6764 .identifier => {6823 .identifier => {
6765 const ident_token = main_tokens[params[0]];6824 const ident_token = main_tokens[params[0]];
6766 decl_name = try astgen.identAsString(ident_token);6825 decl_name = try astgen.identAsString(ident_token);
6767 // TODO look for local variables in scope matching `decl_name` and emit a compile6826 {
6768 // error. Only top-level declarations can be exported. Until this is done, the6827 var s = scope;
6769 // compile error will end up being "use of undeclared identifier" in Sema.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 }
6770 },6852 },
6771 .field_access => {6853 .field_access => {
6772 const namespace_node = node_datas[params[0]].lhs;6854 const namespace_node = node_datas[params[0]].lhs;
...@@ -6776,7 +6858,7 @@ fn builtinCall(...@@ -6776,7 +6858,7 @@ fn builtinCall(
6776 decl_name = try astgen.identAsString(field_ident);6858 decl_name = try astgen.identAsString(field_ident);
6777 },6859 },
6778 else => return astgen.failNode(6860 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", .{},
6780 ),6862 ),
6781 }6863 }
6782 const options = try comptimeExpr(gz, scope, .{ .ty = .export_options_type }, params[1]);6864 const options = try comptimeExpr(gz, scope, .{ .ty = .export_options_type }, params[1]);
...@@ -6785,7 +6867,7 @@ fn builtinCall(...@@ -6785,7 +6867,7 @@ fn builtinCall(
6785 .decl_name = decl_name,6867 .decl_name = decl_name,
6786 .options = options,6868 .options = options,
6787 });6869 });
6788 return rvalue(gz, scope, rl, .void_value, node);6870 return rvalue(gz, rl, .void_value, node);
6789 },6871 },
6790 .@"extern" => {6872 .@"extern" => {
6791 const type_inst = try typeExpr(gz, scope, params[0]);6873 const type_inst = try typeExpr(gz, scope, params[0]);
...@@ -6795,18 +6877,18 @@ fn builtinCall(...@@ -6795,18 +6877,18 @@ fn builtinCall(
6795 .lhs = type_inst,6877 .lhs = type_inst,
6796 .rhs = options,6878 .rhs = options,
6797 });6879 });
6798 return rvalue(gz, scope, rl, result, node);6880 return rvalue(gz, rl, result, node);
6799 },6881 },
68006882
6801 .breakpoint => return simpleNoOpVoid(gz, scope, rl, node, .breakpoint),6883 .breakpoint => return simpleNoOpVoid(gz, rl, node, .breakpoint),
6802 .fence => return simpleNoOpVoid(gz, scope, rl, node, .fence),6884 .fence => return simpleNoOpVoid(gz, rl, node, .fence),
68036885
6804 .This => return rvalue(gz, scope, rl, try gz.addNodeExtended(.this, node), node),6886 .This => return rvalue(gz, rl, try gz.addNodeExtended(.this, node), node),
6805 .return_address => return rvalue(gz, scope, rl, try gz.addNodeExtended(.ret_addr, node), node),6887 .return_address => return rvalue(gz, rl, try gz.addNodeExtended(.ret_addr, node), node),
6806 .src => return rvalue(gz, scope, rl, try gz.addNodeExtended(.builtin_src, node), node),6888 .src => return rvalue(gz, 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),6889 .error_return_trace => return rvalue(gz, rl, try gz.addNodeExtended(.error_return_trace, node), node),
6808 .frame => return rvalue(gz, scope, rl, try gz.addNodeExtended(.frame, node), node),6890 .frame => return rvalue(gz, rl, try gz.addNodeExtended(.frame, node), node),
6809 .frame_address => return rvalue(gz, scope, rl, try gz.addNodeExtended(.frame_address, node), node),6891 .frame_address => return rvalue(gz, rl, try gz.addNodeExtended(.frame_address, node), node),
68106892
6811 .type_info => return simpleUnOpType(gz, scope, rl, node, params[0], .type_info),6893 .type_info => return simpleUnOpType(gz, scope, rl, node, params[0], .type_info),
6812 .size_of => return simpleUnOpType(gz, scope, rl, node, params[0], .size_of),6894 .size_of => return simpleUnOpType(gz, scope, rl, node, params[0], .size_of),
...@@ -6862,7 +6944,7 @@ fn builtinCall(...@@ -6862,7 +6944,7 @@ fn builtinCall(
6862 .lhs = dest_align,6944 .lhs = dest_align,
6863 .rhs = rhs,6945 .rhs = rhs,
6864 });6946 });
6865 return rvalue(gz, scope, rl, result, node);6947 return rvalue(gz, rl, result, node);
6866 },6948 },
68676949
6868 .has_decl => return hasDeclOrField(gz, scope, rl, node, params[0], params[1], .has_decl),6950 .has_decl => return hasDeclOrField(gz, scope, rl, node, params[0], params[1], .has_decl),
...@@ -6898,7 +6980,7 @@ fn builtinCall(...@@ -6898,7 +6980,7 @@ fn builtinCall(
6898 .node = gz.nodeIndexToRelative(node),6980 .node = gz.nodeIndexToRelative(node),
6899 .operand = operand,6981 .operand = operand,
6900 });6982 });
6901 return rvalue(gz, scope, rl, result, node);6983 return rvalue(gz, rl, result, node);
6902 },6984 },
6903 .wasm_memory_grow => {6985 .wasm_memory_grow => {
6904 const index_arg = try expr(gz, scope, .{ .ty = .u32_type }, params[0]);6986 const index_arg = try expr(gz, scope, .{ .ty = .u32_type }, params[0]);
...@@ -6908,7 +6990,7 @@ fn builtinCall(...@@ -6908,7 +6990,7 @@ fn builtinCall(
6908 .lhs = index_arg,6990 .lhs = index_arg,
6909 .rhs = delta_arg,6991 .rhs = delta_arg,
6910 });6992 });
6911 return rvalue(gz, scope, rl, result, node);6993 return rvalue(gz, rl, result, node);
6912 },6994 },
6913 .c_define => {6995 .c_define => {
6914 const name = try comptimeExpr(gz, scope, .{ .ty = .const_slice_u8_type }, params[0]);6996 const name = try comptimeExpr(gz, scope, .{ .ty = .const_slice_u8_type }, params[0]);
...@@ -6918,7 +7000,7 @@ fn builtinCall(...@@ -6918,7 +7000,7 @@ fn builtinCall(
6918 .lhs = name,7000 .lhs = name,
6919 .rhs = value,7001 .rhs = value,
6920 });7002 });
6921 return rvalue(gz, scope, rl, result, node);7003 return rvalue(gz, rl, result, node);
6922 },7004 },
69237005
6924 .splat => {7006 .splat => {
...@@ -6928,7 +7010,7 @@ fn builtinCall(...@@ -6928,7 +7010,7 @@ fn builtinCall(
6928 .lhs = len,7010 .lhs = len,
6929 .rhs = scalar,7011 .rhs = scalar,
6930 });7012 });
6931 return rvalue(gz, scope, rl, result, node);7013 return rvalue(gz, rl, result, node);
6932 },7014 },
6933 .reduce => {7015 .reduce => {
6934 const op = try expr(gz, scope, .{ .ty = .reduce_op_type }, params[0]);7016 const op = try expr(gz, scope, .{ .ty = .reduce_op_type }, params[0]);
...@@ -6937,7 +7019,7 @@ fn builtinCall(...@@ -6937,7 +7019,7 @@ fn builtinCall(
6937 .lhs = op,7019 .lhs = op,
6938 .rhs = scalar,7020 .rhs = scalar,
6939 });7021 });
6940 return rvalue(gz, scope, rl, result, node);7022 return rvalue(gz, rl, result, node);
6941 },7023 },
69427024
6943 .add_with_overflow => return overflowArithmetic(gz, scope, rl, node, params, .add_with_overflow),7025 .add_with_overflow => return overflowArithmetic(gz, scope, rl, node, params, .add_with_overflow),
...@@ -6964,7 +7046,7 @@ fn builtinCall(...@@ -6964,7 +7046,7 @@ fn builtinCall(
6964 .rhs = rhs,7046 .rhs = rhs,
6965 .ptr = ptr,7047 .ptr = ptr,
6966 });7048 });
6967 return rvalue(gz, scope, rl, result, node);7049 return rvalue(gz, rl, result, node);
6968 },7050 },
69697051
6970 .atomic_load => {7052 .atomic_load => {
...@@ -6984,7 +7066,7 @@ fn builtinCall(...@@ -6984,7 +7066,7 @@ fn builtinCall(
6984 .lhs = ptr,7066 .lhs = ptr,
6985 .rhs = ordering,7067 .rhs = ordering,
6986 });7068 });
6987 return rvalue(gz, scope, rl, result, node);7069 return rvalue(gz, rl, result, node);
6988 },7070 },
6989 .atomic_rmw => {7071 .atomic_rmw => {
6990 const int_type = try typeExpr(gz, scope, params[0]);7072 const int_type = try typeExpr(gz, scope, params[0]);
...@@ -7007,7 +7089,7 @@ fn builtinCall(...@@ -7007,7 +7089,7 @@ fn builtinCall(
7007 .operand = operand,7089 .operand = operand,
7008 .ordering = ordering,7090 .ordering = ordering,
7009 });7091 });
7010 return rvalue(gz, scope, rl, result, node);7092 return rvalue(gz, rl, result, node);
7011 },7093 },
7012 .atomic_store => {7094 .atomic_store => {
7013 const int_type = try typeExpr(gz, scope, params[0]);7095 const int_type = try typeExpr(gz, scope, params[0]);
...@@ -7028,7 +7110,7 @@ fn builtinCall(...@@ -7028,7 +7110,7 @@ fn builtinCall(
7028 .operand = operand,7110 .operand = operand,
7029 .ordering = ordering,7111 .ordering = ordering,
7030 });7112 });
7031 return rvalue(gz, scope, rl, result, node);7113 return rvalue(gz, rl, result, node);
7032 },7114 },
7033 .mul_add => {7115 .mul_add => {
7034 const float_type = try typeExpr(gz, scope, params[0]);7116 const float_type = try typeExpr(gz, scope, params[0]);
...@@ -7040,7 +7122,7 @@ fn builtinCall(...@@ -7040,7 +7122,7 @@ fn builtinCall(
7040 .mulend2 = mulend2,7122 .mulend2 = mulend2,
7041 .addend = addend,7123 .addend = addend,
7042 });7124 });
7043 return rvalue(gz, scope, rl, result, node);7125 return rvalue(gz, rl, result, node);
7044 },7126 },
7045 .call => {7127 .call => {
7046 const options = try comptimeExpr(gz, scope, .{ .ty = .call_options_type }, params[0]);7128 const options = try comptimeExpr(gz, scope, .{ .ty = .call_options_type }, params[0]);
...@@ -7051,7 +7133,7 @@ fn builtinCall(...@@ -7051,7 +7133,7 @@ fn builtinCall(
7051 .callee = callee,7133 .callee = callee,
7052 .args = args,7134 .args = args,
7053 });7135 });
7054 return rvalue(gz, scope, rl, result, node);7136 return rvalue(gz, rl, result, node);
7055 },7137 },
7056 .field_parent_ptr => {7138 .field_parent_ptr => {
7057 const parent_type = try typeExpr(gz, scope, params[0]);7139 const parent_type = try typeExpr(gz, scope, params[0]);
...@@ -7062,7 +7144,7 @@ fn builtinCall(...@@ -7062,7 +7144,7 @@ fn builtinCall(
7062 .field_name = field_name,7144 .field_name = field_name,
7063 .field_ptr = try expr(gz, scope, .{ .ty = field_ptr_type }, params[2]),7145 .field_ptr = try expr(gz, scope, .{ .ty = field_ptr_type }, params[2]),
7064 });7146 });
7065 return rvalue(gz, scope, rl, result, node);7147 return rvalue(gz, rl, result, node);
7066 },7148 },
7067 .memcpy => {7149 .memcpy => {
7068 const result = try gz.addPlNode(.memcpy, node, Zir.Inst.Memcpy{7150 const result = try gz.addPlNode(.memcpy, node, Zir.Inst.Memcpy{
...@@ -7070,7 +7152,7 @@ fn builtinCall(...@@ -7070,7 +7152,7 @@ fn builtinCall(
7070 .source = try expr(gz, scope, .{ .ty = .manyptr_const_u8_type }, params[1]),7152 .source = try expr(gz, scope, .{ .ty = .manyptr_const_u8_type }, params[1]),
7071 .byte_count = try expr(gz, scope, .{ .ty = .usize_type }, params[2]),7153 .byte_count = try expr(gz, scope, .{ .ty = .usize_type }, params[2]),
7072 });7154 });
7073 return rvalue(gz, scope, rl, result, node);7155 return rvalue(gz, rl, result, node);
7074 },7156 },
7075 .memset => {7157 .memset => {
7076 const result = try gz.addPlNode(.memset, node, Zir.Inst.Memset{7158 const result = try gz.addPlNode(.memset, node, Zir.Inst.Memset{
...@@ -7078,7 +7160,7 @@ fn builtinCall(...@@ -7078,7 +7160,7 @@ fn builtinCall(
7078 .byte = try expr(gz, scope, .{ .ty = .u8_type }, params[1]),7160 .byte = try expr(gz, scope, .{ .ty = .u8_type }, params[1]),
7079 .byte_count = try expr(gz, scope, .{ .ty = .usize_type }, params[2]),7161 .byte_count = try expr(gz, scope, .{ .ty = .usize_type }, params[2]),
7080 });7162 });
7081 return rvalue(gz, scope, rl, result, node);7163 return rvalue(gz, rl, result, node);
7082 },7164 },
7083 .shuffle => {7165 .shuffle => {
7084 const result = try gz.addPlNode(.shuffle, node, Zir.Inst.Shuffle{7166 const result = try gz.addPlNode(.shuffle, node, Zir.Inst.Shuffle{
...@@ -7087,7 +7169,7 @@ fn builtinCall(...@@ -7087,7 +7169,7 @@ fn builtinCall(
7087 .b = try expr(gz, scope, .none, params[2]),7169 .b = try expr(gz, scope, .none, params[2]),
7088 .mask = try comptimeExpr(gz, scope, .none, params[3]),7170 .mask = try comptimeExpr(gz, scope, .none, params[3]),
7089 });7171 });
7090 return rvalue(gz, scope, rl, result, node);7172 return rvalue(gz, rl, result, node);
7091 },7173 },
7092 .async_call => {7174 .async_call => {
7093 const result = try gz.addPlNode(.builtin_async_call, node, Zir.Inst.AsyncCall{7175 const result = try gz.addPlNode(.builtin_async_call, node, Zir.Inst.AsyncCall{
...@@ -7096,14 +7178,14 @@ fn builtinCall(...@@ -7096,14 +7178,14 @@ fn builtinCall(
7096 .fn_ptr = try expr(gz, scope, .none, params[2]),7178 .fn_ptr = try expr(gz, scope, .none, params[2]),
7097 .args = try expr(gz, scope, .none, params[3]),7179 .args = try expr(gz, scope, .none, params[3]),
7098 });7180 });
7099 return rvalue(gz, scope, rl, result, node);7181 return rvalue(gz, rl, result, node);
7100 },7182 },
7101 .Vector => {7183 .Vector => {
7102 const result = try gz.addPlNode(.vector_type, node, Zir.Inst.Bin{7184 const result = try gz.addPlNode(.vector_type, node, Zir.Inst.Bin{
7103 .lhs = try comptimeExpr(gz, scope, .{.ty = .u32_type}, params[0]),7185 .lhs = try comptimeExpr(gz, scope, .{.ty = .u32_type}, params[0]),
7104 .rhs = try typeExpr(gz, scope, params[1]),7186 .rhs = try typeExpr(gz, scope, params[1]),
7105 });7187 });
7106 return rvalue(gz, scope, rl, result, node);7188 return rvalue(gz, rl, result, node);
7107 },7189 },
71087190
7109 }7191 }
...@@ -7112,13 +7194,12 @@ fn builtinCall(...@@ -7112,13 +7194,12 @@ fn builtinCall(
71127194
7113fn simpleNoOpVoid(7195fn simpleNoOpVoid(
7114 gz: *GenZir,7196 gz: *GenZir,
7115 scope: *Scope,
7116 rl: ResultLoc,7197 rl: ResultLoc,
7117 node: ast.Node.Index,7198 node: ast.Node.Index,
7118 tag: Zir.Inst.Tag,7199 tag: Zir.Inst.Tag,
7119) InnerError!Zir.Inst.Ref {7200) InnerError!Zir.Inst.Ref {
7120 _ = try gz.addNode(tag, node);7201 _ = try gz.addNode(tag, node);
7121 return rvalue(gz, scope, rl, .void_value, node);7202 return rvalue(gz, rl, .void_value, node);
7122}7203}
71237204
7124fn hasDeclOrField(7205fn hasDeclOrField(
...@@ -7136,7 +7217,7 @@ fn hasDeclOrField(...@@ -7136,7 +7217,7 @@ fn hasDeclOrField(
7136 .lhs = container_type,7217 .lhs = container_type,
7137 .rhs = name,7218 .rhs = name,
7138 });7219 });
7139 return rvalue(gz, scope, rl, result, node);7220 return rvalue(gz, rl, result, node);
7140}7221}
71417222
7142fn typeCast(7223fn typeCast(
...@@ -7152,7 +7233,7 @@ fn typeCast(...@@ -7152,7 +7233,7 @@ fn typeCast(
7152 .lhs = try typeExpr(gz, scope, lhs_node),7233 .lhs = try typeExpr(gz, scope, lhs_node),
7153 .rhs = try expr(gz, scope, .none, rhs_node),7234 .rhs = try expr(gz, scope, .none, rhs_node),
7154 });7235 });
7155 return rvalue(gz, scope, rl, result, node);7236 return rvalue(gz, rl, result, node);
7156}7237}
71577238
7158fn simpleUnOpType(7239fn simpleUnOpType(
...@@ -7165,7 +7246,7 @@ fn simpleUnOpType(...@@ -7165,7 +7246,7 @@ fn simpleUnOpType(
7165) InnerError!Zir.Inst.Ref {7246) InnerError!Zir.Inst.Ref {
7166 const operand = try typeExpr(gz, scope, operand_node);7247 const operand = try typeExpr(gz, scope, operand_node);
7167 const result = try gz.addUnNode(tag, operand, node);7248 const result = try gz.addUnNode(tag, operand, node);
7168 return rvalue(gz, scope, rl, result, node);7249 return rvalue(gz, rl, result, node);
7169}7250}
71707251
7171fn simpleUnOp(7252fn simpleUnOp(
...@@ -7179,7 +7260,7 @@ fn simpleUnOp(...@@ -7179,7 +7260,7 @@ fn simpleUnOp(
7179) InnerError!Zir.Inst.Ref {7260) InnerError!Zir.Inst.Ref {
7180 const operand = try expr(gz, scope, operand_rl, operand_node);7261 const operand = try expr(gz, scope, operand_rl, operand_node);
7181 const result = try gz.addUnNode(tag, operand, node);7262 const result = try gz.addUnNode(tag, operand, node);
7182 return rvalue(gz, scope, rl, result, node);7263 return rvalue(gz, rl, result, node);
7183}7264}
71847265
7185fn cmpxchg(7266fn cmpxchg(
...@@ -7209,7 +7290,7 @@ fn cmpxchg(...@@ -7209,7 +7290,7 @@ fn cmpxchg(
7209 .fail_order = try expr(gz, scope, .{ .ty = .atomic_ordering_type }, params[5]),7290 .fail_order = try expr(gz, scope, .{ .ty = .atomic_ordering_type }, params[5]),
7210 // zig fmt: on7291 // zig fmt: on
7211 });7292 });
7212 return rvalue(gz, scope, rl, result, node);7293 return rvalue(gz, rl, result, node);
7213}7294}
72147295
7215fn bitBuiltin(7296fn bitBuiltin(
...@@ -7224,7 +7305,7 @@ fn bitBuiltin(...@@ -7224,7 +7305,7 @@ fn bitBuiltin(
7224 const int_type = try typeExpr(gz, scope, int_type_node);7305 const int_type = try typeExpr(gz, scope, int_type_node);
7225 const operand = try expr(gz, scope, .{ .ty = int_type }, operand_node);7306 const operand = try expr(gz, scope, .{ .ty = int_type }, operand_node);
7226 const result = try gz.addUnNode(tag, operand, node);7307 const result = try gz.addUnNode(tag, operand, node);
7227 return rvalue(gz, scope, rl, result, node);7308 return rvalue(gz, rl, result, node);
7228}7309}
72297310
7230fn divBuiltin(7311fn divBuiltin(
...@@ -7240,7 +7321,7 @@ fn divBuiltin(...@@ -7240,7 +7321,7 @@ fn divBuiltin(
7240 .lhs = try expr(gz, scope, .none, lhs_node),7321 .lhs = try expr(gz, scope, .none, lhs_node),
7241 .rhs = try expr(gz, scope, .none, rhs_node),7322 .rhs = try expr(gz, scope, .none, rhs_node),
7242 });7323 });
7243 return rvalue(gz, scope, rl, result, node);7324 return rvalue(gz, rl, result, node);
7244}7325}
72457326
7246fn simpleCBuiltin(7327fn simpleCBuiltin(
...@@ -7256,7 +7337,7 @@ fn simpleCBuiltin(...@@ -7256,7 +7337,7 @@ fn simpleCBuiltin(
7256 .node = gz.nodeIndexToRelative(node),7337 .node = gz.nodeIndexToRelative(node),
7257 .operand = operand,7338 .operand = operand,
7258 });7339 });
7259 return rvalue(gz, scope, rl, .void_value, node);7340 return rvalue(gz, rl, .void_value, node);
7260}7341}
72617342
7262fn offsetOf(7343fn offsetOf(
...@@ -7274,7 +7355,7 @@ fn offsetOf(...@@ -7274,7 +7355,7 @@ fn offsetOf(
7274 .lhs = type_inst,7355 .lhs = type_inst,
7275 .rhs = field_name,7356 .rhs = field_name,
7276 });7357 });
7277 return rvalue(gz, scope, rl, result, node);7358 return rvalue(gz, rl, result, node);
7278}7359}
72797360
7280fn shiftOp(7361fn shiftOp(
...@@ -7293,7 +7374,7 @@ fn shiftOp(...@@ -7293,7 +7374,7 @@ fn shiftOp(
7293 .lhs = lhs,7374 .lhs = lhs,
7294 .rhs = rhs,7375 .rhs = rhs,
7295 });7376 });
7296 return rvalue(gz, scope, rl, result, node);7377 return rvalue(gz, rl, result, node);
7297}7378}
72987379
7299fn cImport(7380fn cImport(
...@@ -7318,7 +7399,7 @@ fn cImport(...@@ -7318,7 +7399,7 @@ fn cImport(
7318 try block_scope.setBlockBody(block_inst);7399 try block_scope.setBlockBody(block_inst);
7319 try gz.instructions.append(gpa, block_inst);7400 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);
7322}7403}
73237404
7324fn overflowArithmetic(7405fn overflowArithmetic(
...@@ -7348,7 +7429,7 @@ fn overflowArithmetic(...@@ -7348,7 +7429,7 @@ fn overflowArithmetic(
7348 .rhs = rhs,7429 .rhs = rhs,
7349 .ptr = ptr,7430 .ptr = ptr,
7350 });7431 });
7351 return rvalue(gz, scope, rl, result, node);7432 return rvalue(gz, rl, result, node);
7352}7433}
73537434
7354fn callExpr(7435fn callExpr(
...@@ -7400,7 +7481,7 @@ fn callExpr(...@@ -7400,7 +7481,7 @@ fn callExpr(
7400 };7481 };
7401 break :res try gz.addCall(tag, lhs, args, node);7482 break :res try gz.addCall(tag, lhs, args, node);
7402 };7483 };
7403 return rvalue(gz, scope, rl, result, node); // TODO function call with result location7484 return rvalue(gz, rl, result, node); // TODO function call with result location
7404}7485}
74057486
7406pub const simple_types = std.ComptimeStringMap(Zir.Inst.Ref, .{7487pub const simple_types = std.ComptimeStringMap(Zir.Inst.Ref, .{
...@@ -7876,7 +7957,6 @@ fn nodeMayEvalToError(tree: *const ast.Tree, start_node: ast.Node.Index) enum {...@@ -7876,7 +7957,6 @@ fn nodeMayEvalToError(tree: *const ast.Tree, start_node: ast.Node.Index) enum {
7876/// If the `ResultLoc` is `ty`, it will coerce the result to the type.7957/// If the `ResultLoc` is `ty`, it will coerce the result to the type.
7877fn rvalue(7958fn rvalue(
7878 gz: *GenZir,7959 gz: *GenZir,
7879 scope: *Scope,
7880 rl: ResultLoc,7960 rl: ResultLoc,
7881 result: Zir.Inst.Ref,7961 result: Zir.Inst.Ref,
7882 src_node: ast.Node.Index,7962 src_node: ast.Node.Index,
...@@ -8024,7 +8104,6 @@ fn parseStrLit(...@@ -8024,7 +8104,6 @@ fn parseStrLit(
8024 bytes: []const u8,8104 bytes: []const u8,
8025 offset: u32,8105 offset: u32,
8026) InnerError!void {8106) InnerError!void {
8027 const tree = astgen.tree;
8028 const raw_string = bytes[offset..];8107 const raw_string = bytes[offset..];
8029 var buf_managed = buf.toManaged(astgen.gpa);8108 var buf_managed = buf.toManaged(astgen.gpa);
8030 const result = std.zig.string_literal.parseAppend(&buf_managed, raw_string);8109 const result = std.zig.string_literal.parseAppend(&buf_managed, raw_string);
...@@ -8327,6 +8406,15 @@ const Scope = struct {...@@ -8327,6 +8406,15 @@ const Scope = struct {
8327 top,8406 top,
8328 };8407 };
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 };
8330 /// This is always a `const` local and importantly the `inst` is a value type, not a pointer.8418 /// This is always a `const` local and importantly the `inst` is a value type, not a pointer.
8331 /// This structure lives as long as the AST generation of the Block8419 /// This structure lives as long as the AST generation of the Block
8332 /// node that contains the variable.8420 /// node that contains the variable.
...@@ -8341,6 +8429,8 @@ const Scope = struct {...@@ -8341,6 +8429,8 @@ const Scope = struct {
8341 token_src: ast.TokenIndex,8429 token_src: ast.TokenIndex,
8342 /// String table index.8430 /// String table index.
8343 name: u32,8431 name: u32,
8432 /// has this variable been referenced?
8433 used: Used,
8344 };8434 };
83458435
8346 /// This could be a `const` or `var` local. It has a pointer instead of a value.8436 /// This could be a `const` or `var` local. It has a pointer instead of a value.
...@@ -8357,7 +8447,10 @@ const Scope = struct {...@@ -8357,7 +8447,10 @@ const Scope = struct {
8357 token_src: ast.TokenIndex,8447 token_src: ast.TokenIndex,
8358 /// String table index.8448 /// String table index.
8359 name: u32,8449 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,
8361 };8454 };
83628455
8363 const Defer = struct {8456 const Defer = struct {
...@@ -8467,7 +8560,6 @@ const GenZir = struct {...@@ -8467,7 +8560,6 @@ const GenZir = struct {
8467 fn calcLine(gz: GenZir, node: ast.Node.Index) u32 {8560 fn calcLine(gz: GenZir, node: ast.Node.Index) u32 {
8468 const astgen = gz.astgen;8561 const astgen = gz.astgen;
8469 const tree = astgen.tree;8562 const tree = astgen.tree;
8470 const node_tags = tree.nodes.items(.tag);
8471 const token_starts = tree.tokens.items(.start);8563 const token_starts = tree.tokens.items(.start);
8472 const decl_start = token_starts[tree.firstToken(gz.decl_node_index)];8564 const decl_start = token_starts[tree.firstToken(gz.decl_node_index)];
8473 const node_start = token_starts[tree.firstToken(node)];8565 const node_start = token_starts[tree.firstToken(node)];
src/Compilation.zig+8-4
...@@ -325,7 +325,6 @@ pub const AllErrors = struct {...@@ -325,7 +325,6 @@ pub const AllErrors = struct {
325 },325 },
326326
327 pub fn renderToStdErr(msg: Message, ttyconf: std.debug.TTY.Config) void {327 pub fn renderToStdErr(msg: Message, ttyconf: std.debug.TTY.Config) void {
328 const stderr_mutex = std.debug.getStderrMutex();
329 const held = std.debug.getStderrMutex().acquire();328 const held = std.debug.getStderrMutex().acquire();
330 defer held.release();329 defer held.release();
331 const stderr = std.io.getStdErr();330 const stderr = std.io.getStdErr();
...@@ -524,6 +523,7 @@ pub const AllErrors = struct {...@@ -524,6 +523,7 @@ pub const AllErrors = struct {
524 errors: *std.ArrayList(Message),523 errors: *std.ArrayList(Message),
525 msg: []const u8,524 msg: []const u8,
526 ) !void {525 ) !void {
526 _ = arena;
527 try errors.append(.{ .plain = .{ .msg = msg } });527 try errors.append(.{ .plain = .{ .msg = msg } });
528 }528 }
529529
...@@ -1639,7 +1639,7 @@ pub fn update(self: *Compilation) !void {...@@ -1639,7 +1639,7 @@ pub fn update(self: *Compilation) !void {
1639 // Make sure std.zig is inside the import_table. We unconditionally need1639 // Make sure std.zig is inside the import_table. We unconditionally need
1640 // it for start.zig.1640 // it for start.zig.
1641 const std_pkg = module.root_pkg.table.get("std").?;1641 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
1644 // Put a work item in for every known source file to detect if1644 // Put a work item in for every known source file to detect if
1645 // it changed, and, if so, re-compute ZIR and then queue the job1645 // it changed, and, if so, re-compute ZIR and then queue the job
...@@ -2283,8 +2283,12 @@ fn workerAstGenFile(...@@ -2283,8 +2283,12 @@ fn workerAstGenFile(
2283) void {2283) void {
2284 defer wg.finish();2284 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
2286 const mod = comp.bin_file.options.module.?;2290 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) {
2288 error.AnalysisFail => return,2292 error.AnalysisFail => return,
2289 else => {2293 else => {
2290 file.status = .retryable_failure;2294 file.status = .retryable_failure;
...@@ -2373,7 +2377,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {...@@ -2373,7 +2377,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
2373 // We need to "unhit" in this case, to keep the digests matching.2377 // We need to "unhit" in this case, to keep the digests matching.
2374 const prev_hash_state = man.hash.peekBin();2378 const prev_hash_state = man.hash.peekBin();
2375 const actual_hit = hit: {2379 const actual_hit = hit: {
2376 const is_hit = try man.hit();2380 _ = try man.hit();
2377 if (man.files.items.len == 0) {2381 if (man.files.items.len == 0) {
2378 man.unhit(prev_hash_state, 0);2382 man.unhit(prev_hash_state, 0);
2379 break :hit false;2383 break :hit false;
src/DepTokenizer.zig+2-3
...@@ -944,7 +944,7 @@ fn printLabel(out: anytype, label: []const u8, bytes: []const u8) !void {...@@ -944,7 +944,7 @@ fn printLabel(out: anytype, label: []const u8, bytes: []const u8) !void {
944 try out.writeAll(text);944 try out.writeAll(text);
945 var i: usize = text.len;945 var i: usize = text.len;
946 const end = 79;946 const end = 79;
947 while (i < 79) : (i += 1) {947 while (i < end) : (i += 1) {
948 try out.writeAll(&[_]u8{label[0]});948 try out.writeAll(&[_]u8{label[0]});
949 }949 }
950 try out.writeAll("\n");950 try out.writeAll("\n");
...@@ -953,7 +953,7 @@ fn printLabel(out: anytype, label: []const u8, bytes: []const u8) !void {...@@ -953,7 +953,7 @@ fn printLabel(out: anytype, label: []const u8, bytes: []const u8) !void {
953fn printRuler(out: anytype) !void {953fn printRuler(out: anytype) !void {
954 var i: usize = 0;954 var i: usize = 0;
955 const end = 79;955 const end = 79;
956 while (i < 79) : (i += 1) {956 while (i < end) : (i += 1) {
957 try out.writeAll("-");957 try out.writeAll("-");
958 }958 }
959 try out.writeAll("\n");959 try out.writeAll("\n");
...@@ -1057,4 +1057,3 @@ const printable_char_tab: [256]u8 = (...@@ -1057,4 +1057,3 @@ const printable_char_tab: [256]u8 = (
1057 "................................................................" ++1057 "................................................................" ++
1058 "................................................................"1058 "................................................................"
1059).*;1059).*;
1060
src/Module.zig+24-25
...@@ -774,7 +774,10 @@ pub const Fn = struct {...@@ -774,7 +774,10 @@ pub const Fn = struct {
774 ir.dumpFn(mod, func);774 ir.dumpFn(mod, func);
775 }775 }
776776
777 pub fn deinit(func: *Fn, gpa: *Allocator) void {}777 pub fn deinit(func: *Fn, gpa: *Allocator) void {
778 _ = func;
779 _ = gpa;
780 }
778};781};
779782
780pub const Var = struct {783pub const Var = struct {
...@@ -1561,7 +1564,6 @@ pub const SrcLoc = struct {...@@ -1561,7 +1564,6 @@ pub const SrcLoc = struct {
1561 .node_offset_array_access_index => |node_off| {1564 .node_offset_array_access_index => |node_off| {
1562 const tree = try src_loc.file_scope.getTree(gpa);1565 const tree = try src_loc.file_scope.getTree(gpa);
1563 const node_datas = tree.nodes.items(.data);1566 const node_datas = tree.nodes.items(.data);
1564 const node_tags = tree.nodes.items(.tag);
1565 const node = src_loc.declRelativeToNodeIndex(node_off);1567 const node = src_loc.declRelativeToNodeIndex(node_off);
1566 const main_tokens = tree.nodes.items(.main_token);1568 const main_tokens = tree.nodes.items(.main_token);
1567 const tok_index = main_tokens[node_datas[node].rhs];1569 const tok_index = main_tokens[node_datas[node].rhs];
...@@ -1570,7 +1572,6 @@ pub const SrcLoc = struct {...@@ -1570,7 +1572,6 @@ pub const SrcLoc = struct {
1570 },1572 },
1571 .node_offset_slice_sentinel => |node_off| {1573 .node_offset_slice_sentinel => |node_off| {
1572 const tree = try src_loc.file_scope.getTree(gpa);1574 const tree = try src_loc.file_scope.getTree(gpa);
1573 const node_datas = tree.nodes.items(.data);
1574 const node_tags = tree.nodes.items(.tag);1575 const node_tags = tree.nodes.items(.tag);
1575 const node = src_loc.declRelativeToNodeIndex(node_off);1576 const node = src_loc.declRelativeToNodeIndex(node_off);
1576 const full = switch (node_tags[node]) {1577 const full = switch (node_tags[node]) {
...@@ -1586,7 +1587,6 @@ pub const SrcLoc = struct {...@@ -1586,7 +1587,6 @@ pub const SrcLoc = struct {
1586 },1587 },
1587 .node_offset_call_func => |node_off| {1588 .node_offset_call_func => |node_off| {
1588 const tree = try src_loc.file_scope.getTree(gpa);1589 const tree = try src_loc.file_scope.getTree(gpa);
1589 const node_datas = tree.nodes.items(.data);
1590 const node_tags = tree.nodes.items(.tag);1590 const node_tags = tree.nodes.items(.tag);
1591 const node = src_loc.declRelativeToNodeIndex(node_off);1591 const node = src_loc.declRelativeToNodeIndex(node_off);
1592 var params: [1]ast.Node.Index = undefined;1592 var params: [1]ast.Node.Index = undefined;
...@@ -1625,7 +1625,6 @@ pub const SrcLoc = struct {...@@ -1625,7 +1625,6 @@ pub const SrcLoc = struct {
1625 .node_offset_deref_ptr => |node_off| {1625 .node_offset_deref_ptr => |node_off| {
1626 const tree = try src_loc.file_scope.getTree(gpa);1626 const tree = try src_loc.file_scope.getTree(gpa);
1627 const node_datas = tree.nodes.items(.data);1627 const node_datas = tree.nodes.items(.data);
1628 const node_tags = tree.nodes.items(.tag);
1629 const node = src_loc.declRelativeToNodeIndex(node_off);1628 const node = src_loc.declRelativeToNodeIndex(node_off);
1630 const tok_index = node_datas[node].lhs;1629 const tok_index = node_datas[node].lhs;
1631 const token_starts = tree.tokens.items(.start);1630 const token_starts = tree.tokens.items(.start);
...@@ -1633,7 +1632,6 @@ pub const SrcLoc = struct {...@@ -1633,7 +1632,6 @@ pub const SrcLoc = struct {
1633 },1632 },
1634 .node_offset_asm_source => |node_off| {1633 .node_offset_asm_source => |node_off| {
1635 const tree = try src_loc.file_scope.getTree(gpa);1634 const tree = try src_loc.file_scope.getTree(gpa);
1636 const node_datas = tree.nodes.items(.data);
1637 const node_tags = tree.nodes.items(.tag);1635 const node_tags = tree.nodes.items(.tag);
1638 const node = src_loc.declRelativeToNodeIndex(node_off);1636 const node = src_loc.declRelativeToNodeIndex(node_off);
1639 const full = switch (node_tags[node]) {1637 const full = switch (node_tags[node]) {
...@@ -1648,7 +1646,6 @@ pub const SrcLoc = struct {...@@ -1648,7 +1646,6 @@ pub const SrcLoc = struct {
1648 },1646 },
1649 .node_offset_asm_ret_ty => |node_off| {1647 .node_offset_asm_ret_ty => |node_off| {
1650 const tree = try src_loc.file_scope.getTree(gpa);1648 const tree = try src_loc.file_scope.getTree(gpa);
1651 const node_datas = tree.nodes.items(.data);
1652 const node_tags = tree.nodes.items(.tag);1649 const node_tags = tree.nodes.items(.tag);
1653 const node = src_loc.declRelativeToNodeIndex(node_off);1650 const node = src_loc.declRelativeToNodeIndex(node_off);
1654 const full = switch (node_tags[node]) {1651 const full = switch (node_tags[node]) {
...@@ -1771,7 +1768,6 @@ pub const SrcLoc = struct {...@@ -1771,7 +1768,6 @@ pub const SrcLoc = struct {
17711768
1772 .node_offset_fn_type_cc => |node_off| {1769 .node_offset_fn_type_cc => |node_off| {
1773 const tree = try src_loc.file_scope.getTree(gpa);1770 const tree = try src_loc.file_scope.getTree(gpa);
1774 const node_datas = tree.nodes.items(.data);
1775 const node_tags = tree.nodes.items(.tag);1771 const node_tags = tree.nodes.items(.tag);
1776 const node = src_loc.declRelativeToNodeIndex(node_off);1772 const node = src_loc.declRelativeToNodeIndex(node_off);
1777 var params: [1]ast.Node.Index = undefined;1773 var params: [1]ast.Node.Index = undefined;
...@@ -1790,7 +1786,6 @@ pub const SrcLoc = struct {...@@ -1790,7 +1786,6 @@ pub const SrcLoc = struct {
17901786
1791 .node_offset_fn_type_ret_ty => |node_off| {1787 .node_offset_fn_type_ret_ty => |node_off| {
1792 const tree = try src_loc.file_scope.getTree(gpa);1788 const tree = try src_loc.file_scope.getTree(gpa);
1793 const node_datas = tree.nodes.items(.data);
1794 const node_tags = tree.nodes.items(.tag);1789 const node_tags = tree.nodes.items(.tag);
1795 const node = src_loc.declRelativeToNodeIndex(node_off);1790 const node = src_loc.declRelativeToNodeIndex(node_off);
1796 var params: [1]ast.Node.Index = undefined;1791 var params: [1]ast.Node.Index = undefined;
...@@ -1810,7 +1805,6 @@ pub const SrcLoc = struct {...@@ -1810,7 +1805,6 @@ pub const SrcLoc = struct {
1810 .node_offset_anyframe_type => |node_off| {1805 .node_offset_anyframe_type => |node_off| {
1811 const tree = try src_loc.file_scope.getTree(gpa);1806 const tree = try src_loc.file_scope.getTree(gpa);
1812 const node_datas = tree.nodes.items(.data);1807 const node_datas = tree.nodes.items(.data);
1813 const node_tags = tree.nodes.items(.tag);
1814 const parent_node = src_loc.declRelativeToNodeIndex(node_off);1808 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1815 const node = node_datas[parent_node].rhs;1809 const node = node_datas[parent_node].rhs;
1816 const main_tokens = tree.nodes.items(.main_token);1810 const main_tokens = tree.nodes.items(.main_token);
...@@ -2217,7 +2211,7 @@ comptime {...@@ -2217,7 +2211,7 @@ comptime {
2217 }2211 }
2218}2212}
22192213
2220pub fn astGenFile(mod: *Module, file: *Scope.File, prog_node: *std.Progress.Node) !void {2214pub fn astGenFile(mod: *Module, file: *Scope.File) !void {
2221 const tracy = trace(@src());2215 const tracy = trace(@src());
2222 defer tracy.end();2216 defer tracy.end();
22232217
...@@ -2502,7 +2496,6 @@ pub fn astGenFile(mod: *Module, file: *Scope.File, prog_node: *std.Progress.Node...@@ -2502,7 +2496,6 @@ pub fn astGenFile(mod: *Module, file: *Scope.File, prog_node: *std.Progress.Node
2502 @ptrCast([*]const u8, file.zir.instructions.items(.data).ptr);2496 @ptrCast([*]const u8, file.zir.instructions.items(.data).ptr);
2503 if (data_has_safety_tag) {2497 if (data_has_safety_tag) {
2504 // The `Data` union has a safety tag but in the file format we store it without.2498 // The `Data` union has a safety tag but in the file format we store it without.
2505 const tags = file.zir.instructions.items(.tag);
2506 for (file.zir.instructions.items(.data)) |*data, i| {2499 for (file.zir.instructions.items(.data)) |*data, i| {
2507 const as_struct = @ptrCast(*const Stage1DataLayout, data);2500 const as_struct = @ptrCast(*const Stage1DataLayout, data);
2508 safety_buffer[i] = as_struct.data;2501 safety_buffer[i] = as_struct.data;
...@@ -2838,7 +2831,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl: *Decl) InnerError!void {...@@ -2838,7 +2831,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl: *Decl) InnerError!void {
2838}2831}
28392832
2840pub fn semaPkg(mod: *Module, pkg: *Package) !void {2833pub 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;
2842 return mod.semaFile(file);2835 return mod.semaFile(file);
2843}2836}
28442837
...@@ -3137,7 +3130,7 @@ pub const ImportFileResult = struct {...@@ -3137,7 +3130,7 @@ pub const ImportFileResult = struct {
3137 is_new: bool,3130 is_new: bool,
3138};3131};
31393132
3140pub fn importPkg(mod: *Module, cur_pkg: *Package, pkg: *Package) !ImportFileResult {3133pub fn importPkg(mod: *Module, pkg: *Package) !ImportFileResult {
3141 const gpa = mod.gpa;3134 const gpa = mod.gpa;
31423135
3143 // The resolved path is used as the key in the import table, to detect if3136 // The resolved path is used as the key in the import table, to detect if
...@@ -3190,7 +3183,7 @@ pub fn importFile(...@@ -3190,7 +3183,7 @@ pub fn importFile(
3190 import_string: []const u8,3183 import_string: []const u8,
3191) !ImportFileResult {3184) !ImportFileResult {
3192 if (cur_file.pkg.table.get(import_string)) |pkg| {3185 if (cur_file.pkg.table.get(import_string)) |pkg| {
3193 return mod.importPkg(cur_file.pkg, pkg);3186 return mod.importPkg(pkg);
3194 }3187 }
3195 const gpa = mod.gpa;3188 const gpa = mod.gpa;
31963189
...@@ -3386,7 +3379,6 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) InnerError!vo...@@ -3386,7 +3379,6 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) InnerError!vo
3386 log.debug("scan existing {*} ({s}) of {*}", .{ decl, decl.name, namespace });3379 log.debug("scan existing {*} ({s}) of {*}", .{ decl, decl.name, namespace });
3387 // Update the AST node of the decl; even if its contents are unchanged, it may3380 // Update the AST node of the decl; even if its contents are unchanged, it may
3388 // have been re-ordered.3381 // have been re-ordered.
3389 const prev_src_node = decl.src_node;
3390 decl.src_node = decl_node;3382 decl.src_node = decl_node;
3391 decl.src_line = line;3383 decl.src_line = line;
33923384
...@@ -3395,7 +3387,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) InnerError!vo...@@ -3395,7 +3387,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) InnerError!vo
3395 decl.has_align = has_align;3387 decl.has_align = has_align;
3396 decl.has_linksection = has_linksection;3388 decl.has_linksection = has_linksection;
3397 decl.zir_decl_index = @intCast(u32, decl_sub_index);3389 decl.zir_decl_index = @intCast(u32, decl_sub_index);
3398 if (decl.getFunction()) |func| {3390 if (decl.getFunction()) |_| {
3399 switch (mod.comp.bin_file.tag) {3391 switch (mod.comp.bin_file.tag) {
3400 .coff => {3392 .coff => {
3401 // TODO Implement for COFF3393 // TODO Implement for COFF
...@@ -3764,6 +3756,7 @@ pub fn analyzeExport(...@@ -3764,6 +3756,7 @@ pub fn analyzeExport(
3764 errdefer de_gop.value_ptr.* = mod.gpa.shrink(de_gop.value_ptr.*, de_gop.value_ptr.len - 1);3756 errdefer de_gop.value_ptr.* = mod.gpa.shrink(de_gop.value_ptr.*, de_gop.value_ptr.len - 1);
3765}3757}
3766pub fn constInst(mod: *Module, arena: *Allocator, src: LazySrcLoc, typed_value: TypedValue) !*ir.Inst {3758pub fn constInst(mod: *Module, arena: *Allocator, src: LazySrcLoc, typed_value: TypedValue) !*ir.Inst {
3759 _ = mod;
3767 const const_inst = try arena.create(ir.Inst.Constant);3760 const const_inst = try arena.create(ir.Inst.Constant);
3768 const_inst.* = .{3761 const_inst.* = .{
3769 .base = .{3762 .base = .{
...@@ -4132,6 +4125,7 @@ pub fn floatAdd(...@@ -4132,6 +4125,7 @@ pub fn floatAdd(
4132 lhs: Value,4125 lhs: Value,
4133 rhs: Value,4126 rhs: Value,
4134) !Value {4127) !Value {
4128 _ = src;
4135 switch (float_type.tag()) {4129 switch (float_type.tag()) {
4136 .f16 => {4130 .f16 => {
4137 @panic("TODO add __trunctfhf2 to compiler-rt");4131 @panic("TODO add __trunctfhf2 to compiler-rt");
...@@ -4165,6 +4159,7 @@ pub fn floatSub(...@@ -4165,6 +4159,7 @@ pub fn floatSub(
4165 lhs: Value,4159 lhs: Value,
4166 rhs: Value,4160 rhs: Value,
4167) !Value {4161) !Value {
4162 _ = src;
4168 switch (float_type.tag()) {4163 switch (float_type.tag()) {
4169 .f16 => {4164 .f16 => {
4170 @panic("TODO add __trunctfhf2 to compiler-rt");4165 @panic("TODO add __trunctfhf2 to compiler-rt");
...@@ -4198,6 +4193,7 @@ pub fn floatDiv(...@@ -4198,6 +4193,7 @@ pub fn floatDiv(
4198 lhs: Value,4193 lhs: Value,
4199 rhs: Value,4194 rhs: Value,
4200) !Value {4195) !Value {
4196 _ = src;
4201 switch (float_type.tag()) {4197 switch (float_type.tag()) {
4202 .f16 => {4198 .f16 => {
4203 @panic("TODO add __trunctfhf2 to compiler-rt");4199 @panic("TODO add __trunctfhf2 to compiler-rt");
...@@ -4231,6 +4227,7 @@ pub fn floatMul(...@@ -4231,6 +4227,7 @@ pub fn floatMul(
4231 lhs: Value,4227 lhs: Value,
4232 rhs: Value,4228 rhs: Value,
4233) !Value {4229) !Value {
4230 _ = src;
4234 switch (float_type.tag()) {4231 switch (float_type.tag()) {
4235 .f16 => {4232 .f16 => {
4236 @panic("TODO add __trunctfhf2 to compiler-rt");4233 @panic("TODO add __trunctfhf2 to compiler-rt");
...@@ -4264,6 +4261,7 @@ pub fn simplePtrType(...@@ -4264,6 +4261,7 @@ pub fn simplePtrType(
4264 mutable: bool,4261 mutable: bool,
4265 size: std.builtin.TypeInfo.Pointer.Size,4262 size: std.builtin.TypeInfo.Pointer.Size,
4266) Allocator.Error!Type {4263) Allocator.Error!Type {
4264 _ = mod;
4267 if (!mutable and size == .Slice and elem_ty.eql(Type.initTag(.u8))) {4265 if (!mutable and size == .Slice and elem_ty.eql(Type.initTag(.u8))) {
4268 return Type.initTag(.const_slice_u8);4266 return Type.initTag(.const_slice_u8);
4269 }4267 }
...@@ -4298,6 +4296,7 @@ pub fn ptrType(...@@ -4298,6 +4296,7 @@ pub fn ptrType(
4298 @"volatile": bool,4296 @"volatile": bool,
4299 size: std.builtin.TypeInfo.Pointer.Size,4297 size: std.builtin.TypeInfo.Pointer.Size,
4300) Allocator.Error!Type {4298) Allocator.Error!Type {
4299 _ = mod;
4301 assert(host_size == 0 or bit_offset < host_size * 8);4300 assert(host_size == 0 or bit_offset < host_size * 8);
43024301
4303 // TODO check if type can be represented by simplePtrType4302 // TODO check if type can be represented by simplePtrType
...@@ -4315,6 +4314,7 @@ pub fn ptrType(...@@ -4315,6 +4314,7 @@ pub fn ptrType(
4315}4314}
43164315
4317pub fn optionalType(mod: *Module, arena: *Allocator, child_type: Type) Allocator.Error!Type {4316pub fn optionalType(mod: *Module, arena: *Allocator, child_type: Type) Allocator.Error!Type {
4317 _ = mod;
4318 switch (child_type.tag()) {4318 switch (child_type.tag()) {
4319 .single_const_pointer => return Type.Tag.optional_single_const_pointer.create(4319 .single_const_pointer => return Type.Tag.optional_single_const_pointer.create(
4320 arena,4320 arena,
...@@ -4335,6 +4335,7 @@ pub fn arrayType(...@@ -4335,6 +4335,7 @@ pub fn arrayType(
4335 sentinel: ?Value,4335 sentinel: ?Value,
4336 elem_type: Type,4336 elem_type: Type,
4337) Allocator.Error!Type {4337) Allocator.Error!Type {
4338 _ = mod;
4338 if (elem_type.eql(Type.initTag(.u8))) {4339 if (elem_type.eql(Type.initTag(.u8))) {
4339 if (sentinel) |some| {4340 if (sentinel) |some| {
4340 if (some.eql(Value.initTag(.zero))) {4341 if (some.eql(Value.initTag(.zero))) {
...@@ -4365,6 +4366,7 @@ pub fn errorUnionType(...@@ -4365,6 +4366,7 @@ pub fn errorUnionType(
4365 error_set: Type,4366 error_set: Type,
4366 payload: Type,4367 payload: Type,
4367) Allocator.Error!Type {4368) Allocator.Error!Type {
4369 _ = mod;
4368 assert(error_set.zigTypeTag() == .ErrorSet);4370 assert(error_set.zigTypeTag() == .ErrorSet);
4369 if (error_set.eql(Type.initTag(.anyerror)) and payload.eql(Type.initTag(.void))) {4371 if (error_set.eql(Type.initTag(.anyerror)) and payload.eql(Type.initTag(.void))) {
4370 return Type.initTag(.anyerror_void_error_union);4372 return Type.initTag(.anyerror_void_error_union);
...@@ -4692,11 +4694,9 @@ pub fn analyzeUnionFields(mod: *Module, union_obj: *Union) InnerError!void {...@@ -4692,11 +4694,9 @@ pub fn analyzeUnionFields(mod: *Module, union_obj: *Union) InnerError!void {
4692 const src: LazySrcLoc = .{ .node_offset = union_obj.node_offset };4694 const src: LazySrcLoc = .{ .node_offset = union_obj.node_offset };
4693 extra_index += @boolToInt(small.has_src_node);4695 extra_index += @boolToInt(small.has_src_node);
46944696
4695 const tag_type_ref = if (small.has_tag_type) blk: {4697 if (small.has_tag_type) {
4696 const tag_type_ref = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);
4697 extra_index += 1;4698 extra_index += 1;
4698 break :blk tag_type_ref;4699 }
4699 } else .none;
47004700
4701 const body_len = if (small.has_body_len) blk: {4701 const body_len = if (small.has_body_len) blk: {
4702 const body_len = zir.extra[extra_index];4702 const body_len = zir.extra[extra_index];
...@@ -4784,6 +4784,7 @@ pub fn analyzeUnionFields(mod: *Module, union_obj: *Union) InnerError!void {...@@ -4784,6 +4784,7 @@ pub fn analyzeUnionFields(mod: *Module, union_obj: *Union) InnerError!void {
4784 cur_bit_bag >>= 1;4784 cur_bit_bag >>= 1;
4785 const unused = @truncate(u1, cur_bit_bag) != 0;4785 const unused = @truncate(u1, cur_bit_bag) != 0;
4786 cur_bit_bag >>= 1;4786 cur_bit_bag >>= 1;
4787 _ = unused;
47874788
4788 const field_name_zir = zir.nullTerminatedString(zir.extra[extra_index]);4789 const field_name_zir = zir.nullTerminatedString(zir.extra[extra_index]);
4789 extra_index += 1;4790 extra_index += 1;
...@@ -4800,11 +4801,9 @@ pub fn analyzeUnionFields(mod: *Module, union_obj: *Union) InnerError!void {...@@ -4800,11 +4801,9 @@ pub fn analyzeUnionFields(mod: *Module, union_obj: *Union) InnerError!void {
4800 break :blk align_ref;4801 break :blk align_ref;
4801 } else .none;4802 } else .none;
48024803
4803 const tag_ref: Zir.Inst.Ref = if (has_tag) blk: {4804 if (has_tag) {
4804 const tag_ref = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);
4805 extra_index += 1;4805 extra_index += 1;
4806 break :blk tag_ref;4806 }
4807 } else .none;
48084807
4809 // This string needs to outlive the ZIR code.4808 // This string needs to outlive the ZIR code.
4810 const field_name = try decl_arena.allocator.dupe(u8, field_name_zir);4809 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...@@ -702,6 +702,7 @@ fn zirBitcastResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) I
702}702}
703703
704fn zirCoerceResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {704fn zirCoerceResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
705 _ = inst;
705 const tracy = trace(@src());706 const tracy = trace(@src());
706 defer tracy.end();707 defer tracy.end();
707 return sema.mod.fail(&block.base, sema.src, "TODO implement zirCoerceResultPtr", .{});708 return sema.mod.fail(&block.base, sema.src, "TODO implement zirCoerceResultPtr", .{});
...@@ -776,6 +777,7 @@ fn zirStructDecl(...@@ -776,6 +777,7 @@ fn zirStructDecl(
776}777}
777778
778fn createTypeName(sema: *Sema, block: *Scope.Block, name_strategy: Zir.Inst.NameStrategy) ![:0]u8 {779fn createTypeName(sema: *Sema, block: *Scope.Block, name_strategy: Zir.Inst.NameStrategy) ![:0]u8 {
780 _ = block;
779 switch (name_strategy) {781 switch (name_strategy) {
780 .anon => {782 .anon => {
781 // It would be neat to have "struct:line:column" but this name has783 // It would be neat to have "struct:line:column" but this name has
...@@ -1074,6 +1076,10 @@ fn zirOpaqueDecl(...@@ -1074,6 +1076,10 @@ fn zirOpaqueDecl(
1074 const src = inst_data.src();1076 const src = inst_data.src();
1075 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);1077 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);
10761078
1079 _ = name_strategy;
1080 _ = inst_data;
1081 _ = src;
1082 _ = extra;
1077 return sema.mod.fail(&block.base, sema.src, "TODO implement zirOpaqueDecl", .{});1083 return sema.mod.fail(&block.base, sema.src, "TODO implement zirOpaqueDecl", .{});
1078}1084}
10791085
...@@ -1230,14 +1236,13 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) In...@@ -1230,14 +1236,13 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) In
12301236
1231fn zirArg(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {1237fn zirArg(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1232 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;1238 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
1233 const src = inst_data.src();
1234 const arg_name = inst_data.get(sema.code);1239 const arg_name = inst_data.get(sema.code);
1235 const arg_index = sema.next_arg_index;1240 const arg_index = sema.next_arg_index;
1236 sema.next_arg_index += 1;1241 sema.next_arg_index += 1;
12371242
1238 // TODO check if arg_name shadows a Decl1243 // TODO check if arg_name shadows a Decl
12391244
1240 if (block.inlining) |inlining| {1245 if (block.inlining) |_| {
1241 return sema.param_inst_list[arg_index];1246 return sema.param_inst_list[arg_index];
1242 }1247 }
12431248
...@@ -1636,6 +1641,7 @@ fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*In...@@ -1636,6 +1641,7 @@ fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*In
1636}1641}
16371642
1638fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {1643fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1644 _ = block;
1639 const tracy = trace(@src());1645 const tracy = trace(@src());
1640 defer tracy.end();1646 defer tracy.end();
16411647
...@@ -1644,6 +1650,7 @@ fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*In...@@ -1644,6 +1650,7 @@ fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*In
1644}1650}
16451651
1646fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {1652fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1653 _ = block;
1647 const tracy = trace(@src());1654 const tracy = trace(@src());
1648 defer tracy.end();1655 defer tracy.end();
16491656
...@@ -1661,6 +1668,7 @@ fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!...@@ -1661,6 +1668,7 @@ fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
1661}1668}
16621669
1663fn zirFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {1670fn zirFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1671 _ = block;
1664 const arena = sema.arena;1672 const arena = sema.arena;
1665 const inst_data = sema.code.instructions.items(.data)[inst].float;1673 const inst_data = sema.code.instructions.items(.data)[inst].float;
1666 const src = inst_data.src();1674 const src = inst_data.src();
...@@ -1673,6 +1681,7 @@ fn zirFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*...@@ -1673,6 +1681,7 @@ fn zirFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*
1673}1681}
16741682
1675fn zirFloat128(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {1683fn zirFloat128(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1684 _ = block;
1676 const arena = sema.arena;1685 const arena = sema.arena;
1677 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;1686 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1678 const extra = sema.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data;1687 const extra = sema.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data;
...@@ -2354,6 +2363,7 @@ fn analyzeCall(...@@ -2354,6 +2363,7 @@ fn analyzeCall(
2354}2363}
23552364
2356fn zirIntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {2365fn zirIntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2366 _ = block;
2357 const tracy = trace(@src());2367 const tracy = trace(@src());
2358 defer tracy.end();2368 defer tracy.end();
23592369
...@@ -2462,6 +2472,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn...@@ -2462,6 +2472,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn
2462}2472}
24632473
2464fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {2474fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2475 _ = block;
2465 const tracy = trace(@src());2476 const tracy = trace(@src());
2466 defer tracy.end();2477 defer tracy.end();
24672478
...@@ -2622,6 +2633,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn...@@ -2622,6 +2633,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn
2622}2633}
26232634
2624fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {2635fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2636 _ = block;
2625 const tracy = trace(@src());2637 const tracy = trace(@src());
2626 defer tracy.end();2638 defer tracy.end();
26272639
...@@ -3005,7 +3017,6 @@ fn zirFunc(...@@ -3005,7 +3017,6 @@ fn zirFunc(
3005 defer tracy.end();3017 defer tracy.end();
30063018
3007 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;3019 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
3008 const src = inst_data.src();
3009 const extra = sema.code.extraData(Zir.Inst.Func, inst_data.payload_index);3020 const extra = sema.code.extraData(Zir.Inst.Func, inst_data.payload_index);
3010 const param_types = sema.code.refSlice(extra.end, extra.data.param_types_len);3021 const param_types = sema.code.refSlice(extra.end, extra.data.param_types_len);
30113022
...@@ -3061,7 +3072,9 @@ fn funcCommon(...@@ -3061,7 +3072,9 @@ fn funcCommon(
30613072
3062 const fn_ty: Type = fn_ty: {3073 const fn_ty: Type = fn_ty: {
3063 // Hot path for some common function types.3074 // 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 {
3065 if (return_type.zigTypeTag() == .NoReturn and cc == .Unspecified) {3078 if (return_type.zigTypeTag() == .NoReturn and cc == .Unspecified) {
3066 break :fn_ty Type.initTag(.fn_noreturn_no_args);3079 break :fn_ty Type.initTag(.fn_noreturn_no_args);
3067 }3080 }
...@@ -3092,6 +3105,10 @@ fn funcCommon(...@@ -3092,6 +3105,10 @@ fn funcCommon(
3092 return mod.fail(&block.base, src, "TODO implement support for function prototypes to have alignment specified", .{});3105 return mod.fail(&block.base, src, "TODO implement support for function prototypes to have alignment specified", .{});
3093 }3106 }
30943107
3108 if (inferred_error_set) {
3109 return mod.fail(&block.base, src, "TODO implement functions with inferred error sets", .{});
3110 }
3111
3095 break :fn_ty try Type.Tag.function.create(sema.arena, .{3112 break :fn_ty try Type.Tag.function.create(sema.arena, .{
3096 .param_types = param_types,3113 .param_types = param_types,
3097 .return_type = return_type,3114 .return_type = return_type,
...@@ -3332,9 +3349,7 @@ fn zirBitcast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError...@@ -3332,9 +3349,7 @@ fn zirBitcast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
3332 defer tracy.end();3349 defer tracy.end();
33333350
3334 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;3351 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
3335 const src = inst_data.src();
3336 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };3352 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 };
3338 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;3353 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
33393354
3340 const dest_type = try sema.resolveType(block, dest_ty_src, extra.lhs);3355 const dest_type = try sema.resolveType(block, dest_ty_src, extra.lhs);
...@@ -3499,6 +3514,8 @@ fn zirSwitchCapture(...@@ -3499,6 +3514,8 @@ fn zirSwitchCapture(
3499 const switch_info = zir_datas[capture_info.switch_inst].pl_node;3514 const switch_info = zir_datas[capture_info.switch_inst].pl_node;
3500 const src = switch_info.src();3515 const src = switch_info.src();
35013516
3517 _ = is_ref;
3518 _ = is_multi;
3502 return sema.mod.fail(&block.base, src, "TODO implement Sema for zirSwitchCapture", .{});3519 return sema.mod.fail(&block.base, src, "TODO implement Sema for zirSwitchCapture", .{});
3503}3520}
35043521
...@@ -3516,6 +3533,7 @@ fn zirSwitchCaptureElse(...@@ -3516,6 +3533,7 @@ fn zirSwitchCaptureElse(
3516 const switch_info = zir_datas[capture_info.switch_inst].pl_node;3533 const switch_info = zir_datas[capture_info.switch_inst].pl_node;
3517 const src = switch_info.src();3534 const src = switch_info.src();
35183535
3536 _ = is_ref;
3519 return sema.mod.fail(&block.base, src, "TODO implement Sema for zirSwitchCaptureElse", .{});3537 return sema.mod.fail(&block.base, src, "TODO implement Sema for zirSwitchCaptureElse", .{});
3520}3538}
35213539
...@@ -3653,7 +3671,6 @@ fn analyzeSwitch(...@@ -3653,7 +3671,6 @@ fn analyzeSwitch(
3653 extra_index += 1;3671 extra_index += 1;
3654 const body_len = sema.code.extra[extra_index];3672 const body_len = sema.code.extra[extra_index];
3655 extra_index += 1;3673 extra_index += 1;
3656 const body = sema.code.extra[extra_index..][0..body_len];
3657 extra_index += body_len;3674 extra_index += body_len;
36583675
3659 try sema.validateSwitchItemEnum(3676 try sema.validateSwitchItemEnum(
...@@ -3763,7 +3780,6 @@ fn analyzeSwitch(...@@ -3763,7 +3780,6 @@ fn analyzeSwitch(
3763 extra_index += 1;3780 extra_index += 1;
3764 const body_len = sema.code.extra[extra_index];3781 const body_len = sema.code.extra[extra_index];
3765 extra_index += 1;3782 extra_index += 1;
3766 const body = sema.code.extra[extra_index..][0..body_len];
3767 extra_index += body_len;3783 extra_index += body_len;
37683784
3769 try sema.validateSwitchItem(3785 try sema.validateSwitchItem(
...@@ -3859,7 +3875,6 @@ fn analyzeSwitch(...@@ -3859,7 +3875,6 @@ fn analyzeSwitch(
3859 extra_index += 1;3875 extra_index += 1;
3860 const body_len = sema.code.extra[extra_index];3876 const body_len = sema.code.extra[extra_index];
3861 extra_index += 1;3877 extra_index += 1;
3862 const body = sema.code.extra[extra_index..][0..body_len];
3863 extra_index += body_len;3878 extra_index += body_len;
38643879
3865 try sema.validateSwitchItemBool(3880 try sema.validateSwitchItemBool(
...@@ -3942,7 +3957,6 @@ fn analyzeSwitch(...@@ -3942,7 +3957,6 @@ fn analyzeSwitch(
3942 extra_index += 1;3957 extra_index += 1;
3943 const body_len = sema.code.extra[extra_index];3958 const body_len = sema.code.extra[extra_index];
3944 extra_index += 1;3959 extra_index += 1;
3945 const body = sema.code.extra[extra_index..][0..body_len];
3946 extra_index += body_len;3960 extra_index += body_len;
39473961
3948 try sema.validateSwitchItemSparse(3962 try sema.validateSwitchItemSparse(
...@@ -4457,6 +4471,7 @@ fn validateSwitchNoRange(...@@ -4457,6 +4471,7 @@ fn validateSwitchNoRange(
4457fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {4471fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4458 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;4472 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
4459 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;4473 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
4474 _ = extra;
4460 const src = inst_data.src();4475 const src = inst_data.src();
44614476
4462 return sema.mod.fail(&block.base, src, "TODO implement zirHasField", .{});4477 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!...@@ -4515,12 +4530,17 @@ fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
4515fn zirShl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {4530fn zirShl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4516 const tracy = trace(@src());4531 const tracy = trace(@src());
4517 defer tracy.end();4532 defer tracy.end();
4533
4534 _ = block;
4535 _ = inst;
4518 return sema.mod.fail(&block.base, sema.src, "TODO implement zirShl", .{});4536 return sema.mod.fail(&block.base, sema.src, "TODO implement zirShl", .{});
4519}4537}
45204538
4521fn zirShr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {4539fn zirShr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4522 const tracy = trace(@src());4540 const tracy = trace(@src());
4523 defer tracy.end();4541 defer tracy.end();
4542
4543 _ = inst;
4524 return sema.mod.fail(&block.base, sema.src, "TODO implement zirShr", .{});4544 return sema.mod.fail(&block.base, sema.src, "TODO implement zirShr", .{});
4525}4545}
45264546
...@@ -4590,18 +4610,24 @@ fn zirBitwise(...@@ -4590,18 +4610,24 @@ fn zirBitwise(
4590fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {4610fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4591 const tracy = trace(@src());4611 const tracy = trace(@src());
4592 defer tracy.end();4612 defer tracy.end();
4613
4614 _ = inst;
4593 return sema.mod.fail(&block.base, sema.src, "TODO implement zirBitNot", .{});4615 return sema.mod.fail(&block.base, sema.src, "TODO implement zirBitNot", .{});
4594}4616}
45954617
4596fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {4618fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4597 const tracy = trace(@src());4619 const tracy = trace(@src());
4598 defer tracy.end();4620 defer tracy.end();
4621
4622 _ = inst;
4599 return sema.mod.fail(&block.base, sema.src, "TODO implement zirArrayCat", .{});4623 return sema.mod.fail(&block.base, sema.src, "TODO implement zirArrayCat", .{});
4600}4624}
46014625
4602fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {4626fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
4603 const tracy = trace(@src());4627 const tracy = trace(@src());
4604 defer tracy.end();4628 defer tracy.end();
4629
4630 _ = inst;
4605 return sema.mod.fail(&block.base, sema.src, "TODO implement zirArrayMul", .{});4631 return sema.mod.fail(&block.base, sema.src, "TODO implement zirArrayMul", .{});
4606}4632}
46074633
...@@ -5061,6 +5087,7 @@ fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro...@@ -5061,6 +5087,7 @@ fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
5061}5087}
50625088
5063fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {5089fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5090 _ = block;
5064 const zir_datas = sema.code.instructions.items(.data);5091 const zir_datas = sema.code.instructions.items(.data);
5065 const inst_data = zir_datas[inst].un_node;5092 const inst_data = zir_datas[inst].un_node;
5066 const src = inst_data.src();5093 const src = inst_data.src();
...@@ -5069,6 +5096,7 @@ fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!...@@ -5069,6 +5096,7 @@ fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
5069}5096}
50705097
5071fn zirTypeofElem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {5098fn zirTypeofElem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5099 _ = block;
5072 const inst_data = sema.code.instructions.items(.data)[inst].un_node;5100 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5073 const src = inst_data.src();5101 const src = inst_data.src();
5074 const operand_ptr = try sema.resolveInst(inst_data.operand);5102 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:...@@ -5594,6 +5622,10 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
5594 return mod.failWithOwnedErrorMsg(&block.base, msg);5622 return mod.failWithOwnedErrorMsg(&block.base, msg);
5595 }5623 }
55965624
5625 if (is_ref) {
5626 return mod.fail(&block.base, src, "TODO: Sema.zirStructInit is_ref=true", .{});
5627 }
5628
5597 const is_comptime = for (field_inits) |field_init| {5629 const is_comptime = for (field_inits) |field_init| {
5598 if (field_init.value() == null) {5630 if (field_init.value() == null) {
5599 break false;5631 break false;
...@@ -5617,18 +5649,24 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:...@@ -5617,18 +5649,24 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
5617fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!*Inst {5649fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!*Inst {
5618 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5650 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5619 const src = inst_data.src();5651 const src = inst_data.src();
5652
5653 _ = is_ref;
5620 return sema.mod.fail(&block.base, src, "TODO: Sema.zirStructInitAnon", .{});5654 return sema.mod.fail(&block.base, src, "TODO: Sema.zirStructInitAnon", .{});
5621}5655}
56225656
5623fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!*Inst {5657fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!*Inst {
5624 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5658 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5625 const src = inst_data.src();5659 const src = inst_data.src();
5660
5661 _ = is_ref;
5626 return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInit", .{});5662 return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInit", .{});
5627}5663}
56285664
5629fn zirArrayInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!*Inst {5665fn zirArrayInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!*Inst {
5630 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;5666 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5631 const src = inst_data.src();5667 const src = inst_data.src();
5668
5669 _ = is_ref;
5632 return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInitAnon", .{});5670 return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInitAnon", .{});
5633}5671}
56345672
...@@ -5771,7 +5809,6 @@ fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro...@@ -5771,7 +5809,6 @@ fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
5771 return sema.mod.fail(&block.base, type_src, "expected pointer, found '{}'", .{type_res});5809 return sema.mod.fail(&block.base, type_src, "expected pointer, found '{}'", .{type_res});
5772 const ptr_align = type_res.ptrAlignment(sema.mod.getTarget());5810 const ptr_align = type_res.ptrAlignment(sema.mod.getTarget());
57735811
5774 const uncasted_operand = try sema.resolveInst(extra.rhs);
5775 if (try sema.resolveDefinedValue(block, operand_src, operand_coerced)) |val| {5812 if (try sema.resolveDefinedValue(block, operand_src, operand_coerced)) |val| {
5776 const addr = val.toUnsignedInt();5813 const addr = val.toUnsignedInt();
5777 if (!type_res.isAllowzeroPtr() and addr == 0)5814 if (!type_res.isAllowzeroPtr() and addr == 0)
...@@ -6025,6 +6062,8 @@ fn zirAwait(...@@ -6025,6 +6062,8 @@ fn zirAwait(
6025) InnerError!*Inst {6062) InnerError!*Inst {
6026 const inst_data = sema.code.instructions.items(.data)[inst].un_node;6063 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
6027 const src = inst_data.src();6064 const src = inst_data.src();
6065
6066 _ = is_nosuspend;
6028 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAwait", .{});6067 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAwait", .{});
6029}6068}
60306069
...@@ -6035,7 +6074,6 @@ fn zirVarExtended(...@@ -6035,7 +6074,6 @@ fn zirVarExtended(
6035) InnerError!*Inst {6074) InnerError!*Inst {
6036 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);6075 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);
6037 const src = sema.src;6076 const src = sema.src;
6038 const align_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at align
6039 const ty_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at type6077 const ty_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at type
6040 const mut_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at mut token6078 const mut_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at mut token
6041 const init_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at init expr6079 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:...@@ -6305,6 +6343,8 @@ fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: *Inst, panic_id:
6305}6343}
63066344
6307fn safetyPanic(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, panic_id: PanicId) !Zir.Inst.Index {6345fn safetyPanic(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, panic_id: PanicId) !Zir.Inst.Index {
6346 _ = sema;
6347 _ = panic_id;
6308 // TODO Once we have a panic function to call, call it here instead of breakpoint.6348 // TODO Once we have a panic function to call, call it here instead of breakpoint.
6309 _ = try block.addNoOp(src, Type.initTag(.void), .breakpoint);6349 _ = try block.addNoOp(src, Type.initTag(.void), .breakpoint);
6310 _ = try block.addNoOp(src, Type.initTag(.noreturn), .unreach);6350 _ = try block.addNoOp(src, Type.initTag(.noreturn), .unreach);
...@@ -6618,6 +6658,8 @@ fn elemPtrArray(...@@ -6618,6 +6658,8 @@ fn elemPtrArray(
6618 });6658 });
6619 }6659 }
6620 }6660 }
6661 _ = elem_index;
6662 _ = elem_index_src;
6621 return sema.mod.fail(&block.base, src, "TODO implement more analyze elemptr for arrays", .{});6663 return sema.mod.fail(&block.base, src, "TODO implement more analyze elemptr for arrays", .{});
6622}6664}
66236665
...@@ -7131,6 +7173,7 @@ fn analyzeSlice(...@@ -7131,6 +7173,7 @@ fn analyzeSlice(
7131 ptr_child.isVolatilePtr(),7173 ptr_child.isVolatilePtr(),
7132 return_ptr_size,7174 return_ptr_size,
7133 );7175 );
7176 _ = return_type;
71347177
7135 return sema.mod.fail(&block.base, src, "TODO implement analysis of slice", .{});7178 return sema.mod.fail(&block.base, src, "TODO implement analysis of slice", .{});
7136}7179}
...@@ -7476,14 +7519,14 @@ fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type...@@ -7476,14 +7519,14 @@ fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type
7476 struct_obj.status = .have_field_types;7519 struct_obj.status = .have_field_types;
7477 return ty;7520 return ty;
7478 },7521 },
7479 .extern_options => return sema.resolveBuiltinTypeFields(block, src, ty, "ExternOptions"),7522 .extern_options => return sema.resolveBuiltinTypeFields(block, src, "ExternOptions"),
7480 .export_options => return sema.resolveBuiltinTypeFields(block, src, ty, "ExportOptions"),7523 .export_options => return sema.resolveBuiltinTypeFields(block, src, "ExportOptions"),
7481 .atomic_ordering => return sema.resolveBuiltinTypeFields(block, src, ty, "AtomicOrdering"),7524 .atomic_ordering => return sema.resolveBuiltinTypeFields(block, src, "AtomicOrdering"),
7482 .atomic_rmw_op => return sema.resolveBuiltinTypeFields(block, src, ty, "AtomicRmwOp"),7525 .atomic_rmw_op => return sema.resolveBuiltinTypeFields(block, src, "AtomicRmwOp"),
7483 .calling_convention => return sema.resolveBuiltinTypeFields(block, src, ty, "CallingConvention"),7526 .calling_convention => return sema.resolveBuiltinTypeFields(block, src, "CallingConvention"),
7484 .float_mode => return sema.resolveBuiltinTypeFields(block, src, ty, "FloatMode"),7527 .float_mode => return sema.resolveBuiltinTypeFields(block, src, "FloatMode"),
7485 .reduce_op => return sema.resolveBuiltinTypeFields(block, src, ty, "ReduceOp"),7528 .reduce_op => return sema.resolveBuiltinTypeFields(block, src, "ReduceOp"),
7486 .call_options => return sema.resolveBuiltinTypeFields(block, src, ty, "CallOptions"),7529 .call_options => return sema.resolveBuiltinTypeFields(block, src, "CallOptions"),
74877530
7488 .@"union", .union_tagged => {7531 .@"union", .union_tagged => {
7489 const union_obj = ty.cast(Type.Payload.Union).?.data;7532 const union_obj = ty.cast(Type.Payload.Union).?.data;
...@@ -7509,7 +7552,6 @@ fn resolveBuiltinTypeFields(...@@ -7509,7 +7552,6 @@ fn resolveBuiltinTypeFields(
7509 sema: *Sema,7552 sema: *Sema,
7510 block: *Scope.Block,7553 block: *Scope.Block,
7511 src: LazySrcLoc,7554 src: LazySrcLoc,
7512 ty: Type,
7513 name: []const u8,7555 name: []const u8,
7514) InnerError!Type {7556) InnerError!Type {
7515 const resolved_ty = try sema.getBuiltinType(block, src, name);7557 const resolved_ty = try sema.getBuiltinType(block, src, name);
...@@ -7524,7 +7566,7 @@ fn getBuiltinType(...@@ -7524,7 +7566,7 @@ fn getBuiltinType(
7524) InnerError!Type {7566) InnerError!Type {
7525 const mod = sema.mod;7567 const mod = sema.mod;
7526 const std_pkg = mod.root_pkg.table.get("std").?;7568 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;
7528 const opt_builtin_inst = try sema.analyzeNamespaceLookup(7570 const opt_builtin_inst = try sema.analyzeNamespaceLookup(
7529 block,7571 block,
7530 src,7572 src,
src/ThreadPool.zig+2-2
...@@ -101,7 +101,7 @@ pub fn deinit(self: *ThreadPool) void {...@@ -101,7 +101,7 @@ pub fn deinit(self: *ThreadPool) void {
101101
102pub fn spawn(self: *ThreadPool, comptime func: anytype, args: anytype) !void {102pub fn spawn(self: *ThreadPool, comptime func: anytype, args: anytype) !void {
103 if (std.builtin.single_threaded) {103 if (std.builtin.single_threaded) {
104 const result = @call(.{}, func, args);104 @call(.{}, func, args);
105 return;105 return;
106 }106 }
107107
...@@ -114,7 +114,7 @@ pub fn spawn(self: *ThreadPool, comptime func: anytype, args: anytype) !void {...@@ -114,7 +114,7 @@ pub fn spawn(self: *ThreadPool, comptime func: anytype, args: anytype) !void {
114 fn runFn(runnable: *Runnable) void {114 fn runFn(runnable: *Runnable) void {
115 const run_node = @fieldParentPtr(RunQueue.Node, "data", runnable);115 const run_node = @fieldParentPtr(RunQueue.Node, "data", runnable);
116 const closure = @fieldParentPtr(@This(), "run_node", run_node);116 const closure = @fieldParentPtr(@This(), "run_node", run_node);
117 const result = @call(.{}, func, closure.arguments);117 @call(.{}, func, closure.arguments);
118118
119 const held = closure.pool.lock.acquire();119 const held = closure.pool.lock.acquire();
120 defer held.release();120 defer held.release();
src/Zir.zig+14-4
...@@ -3176,6 +3176,7 @@ const Writer = struct {...@@ -3176,6 +3176,7 @@ const Writer = struct {
3176 inst: Inst.Index,3176 inst: Inst.Index,
3177 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {3177 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
3178 const inst_data = self.code.instructions.items(.data)[inst].array_type_sentinel;3178 const inst_data = self.code.instructions.items(.data)[inst].array_type_sentinel;
3179 _ = inst_data;
3179 try stream.writeAll("TODO)");3180 try stream.writeAll("TODO)");
3180 }3181 }
31813182
...@@ -3213,6 +3214,7 @@ const Writer = struct {...@@ -3213,6 +3214,7 @@ const Writer = struct {
3213 inst: Inst.Index,3214 inst: Inst.Index,
3214 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {3215 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
3215 const inst_data = self.code.instructions.items(.data)[inst].ptr_type;3216 const inst_data = self.code.instructions.items(.data)[inst].ptr_type;
3217 _ = inst_data;
3216 try stream.writeAll("TODO)");3218 try stream.writeAll("TODO)");
3217 }3219 }
32183220
...@@ -3559,6 +3561,8 @@ const Writer = struct {...@@ -3559,6 +3561,8 @@ const Writer = struct {
3559 assert(body.len == 0);3561 assert(body.len == 0);
3560 try stream.writeAll("{}, {})");3562 try stream.writeAll("{}, {})");
3561 } else {3563 } else {
3564 const prev_parent_decl_node = self.parent_decl_node;
3565 if (src_node) |off| self.parent_decl_node = self.relativeToNodeIndex(off);
3562 self.indent += 2;3566 self.indent += 2;
3563 if (body.len == 0) {3567 if (body.len == 0) {
3564 try stream.writeAll("{}, {\n");3568 try stream.writeAll("{}, {\n");
...@@ -3621,6 +3625,7 @@ const Writer = struct {...@@ -3621,6 +3625,7 @@ const Writer = struct {
3621 try stream.writeAll(",\n");3625 try stream.writeAll(",\n");
3622 }3626 }
36233627
3628 self.parent_decl_node = prev_parent_decl_node;
3624 self.indent -= 2;3629 self.indent -= 2;
3625 try stream.writeByteNTimes(' ', self.indent);3630 try stream.writeByteNTimes(' ', self.indent);
3626 try stream.writeAll("})");3631 try stream.writeAll("})");
...@@ -3689,6 +3694,8 @@ const Writer = struct {...@@ -3689,6 +3694,8 @@ const Writer = struct {
3689 const body = self.code.extra[extra_index..][0..body_len];3694 const body = self.code.extra[extra_index..][0..body_len];
3690 extra_index += body.len;3695 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);
3692 self.indent += 2;3699 self.indent += 2;
3693 if (body.len == 0) {3700 if (body.len == 0) {
3694 try stream.writeAll("{}, {\n");3701 try stream.writeAll("{}, {\n");
...@@ -3754,6 +3761,7 @@ const Writer = struct {...@@ -3754,6 +3761,7 @@ const Writer = struct {
3754 try stream.writeAll(",\n");3761 try stream.writeAll(",\n");
3755 }3762 }
37563763
3764 self.parent_decl_node = prev_parent_decl_node;
3757 self.indent -= 2;3765 self.indent -= 2;
3758 try stream.writeByteNTimes(' ', self.indent);3766 try stream.writeByteNTimes(' ', self.indent);
3759 try stream.writeAll("})");3767 try stream.writeAll("})");
...@@ -3909,6 +3917,8 @@ const Writer = struct {...@@ -3909,6 +3917,8 @@ const Writer = struct {
3909 assert(body.len == 0);3917 assert(body.len == 0);
3910 try stream.writeAll("{}, {})");3918 try stream.writeAll("{}, {})");
3911 } else {3919 } else {
3920 const prev_parent_decl_node = self.parent_decl_node;
3921 if (src_node) |off| self.parent_decl_node = self.relativeToNodeIndex(off);
3912 self.indent += 2;3922 self.indent += 2;
3913 if (body.len == 0) {3923 if (body.len == 0) {
3914 try stream.writeAll("{}, {\n");3924 try stream.writeAll("{}, {\n");
...@@ -3949,6 +3959,7 @@ const Writer = struct {...@@ -3949,6 +3959,7 @@ const Writer = struct {
3949 }3959 }
3950 try stream.writeAll(",\n");3960 try stream.writeAll(",\n");
3951 }3961 }
3962 self.parent_decl_node = prev_parent_decl_node;
3952 self.indent -= 2;3963 self.indent -= 2;
3953 try stream.writeByteNTimes(' ', self.indent);3964 try stream.writeByteNTimes(' ', self.indent);
3954 try stream.writeAll("})");3965 try stream.writeAll("})");
...@@ -4431,6 +4442,7 @@ const Writer = struct {...@@ -4431,6 +4442,7 @@ const Writer = struct {
4431 }4442 }
44324443
4433 fn writeInstIndex(self: *Writer, stream: anytype, inst: Inst.Index) !void {4444 fn writeInstIndex(self: *Writer, stream: anytype, inst: Inst.Index) !void {
4445 _ = self;
4434 return stream.print("%{d}", .{inst});4446 return stream.print("%{d}", .{inst});
4435 }4447 }
44364448
...@@ -4451,6 +4463,7 @@ const Writer = struct {...@@ -4451,6 +4463,7 @@ const Writer = struct {
4451 name: []const u8,4463 name: []const u8,
4452 flag: bool,4464 flag: bool,
4453 ) !void {4465 ) !void {
4466 _ = self;
4454 if (!flag) return;4467 if (!flag) return;
4455 try stream.writeAll(name);4468 try stream.writeAll(name);
4456 }4469 }
...@@ -4739,7 +4752,6 @@ fn findDeclsSwitch(...@@ -4739,7 +4752,6 @@ fn findDeclsSwitch(
4739 var extra_index: usize = special.end;4752 var extra_index: usize = special.end;
4740 var scalar_i: usize = 0;4753 var scalar_i: usize = 0;
4741 while (scalar_i < extra.data.cases_len) : (scalar_i += 1) {4754 while (scalar_i < extra.data.cases_len) : (scalar_i += 1) {
4742 const item_ref = @intToEnum(Inst.Ref, zir.extra[extra_index]);
4743 extra_index += 1;4755 extra_index += 1;
4744 const body_len = zir.extra[extra_index];4756 const body_len = zir.extra[extra_index];
4745 extra_index += 1;4757 extra_index += 1;
...@@ -4779,7 +4791,6 @@ fn findDeclsSwitchMulti(...@@ -4779,7 +4791,6 @@ fn findDeclsSwitchMulti(
4779 {4791 {
4780 var scalar_i: usize = 0;4792 var scalar_i: usize = 0;
4781 while (scalar_i < extra.data.scalar_cases_len) : (scalar_i += 1) {4793 while (scalar_i < extra.data.scalar_cases_len) : (scalar_i += 1) {
4782 const item_ref = @intToEnum(Inst.Ref, zir.extra[extra_index]);
4783 extra_index += 1;4794 extra_index += 1;
4784 const body_len = zir.extra[extra_index];4795 const body_len = zir.extra[extra_index];
4785 extra_index += 1;4796 extra_index += 1;
...@@ -4800,12 +4811,11 @@ fn findDeclsSwitchMulti(...@@ -4800,12 +4811,11 @@ fn findDeclsSwitchMulti(
4800 extra_index += 1;4811 extra_index += 1;
4801 const items = zir.refSlice(extra_index, items_len);4812 const items = zir.refSlice(extra_index, items_len);
4802 extra_index += items_len;4813 extra_index += items_len;
4814 _ = items;
48034815
4804 var range_i: usize = 0;4816 var range_i: usize = 0;
4805 while (range_i < ranges_len) : (range_i += 1) {4817 while (range_i < ranges_len) : (range_i += 1) {
4806 const item_first = @intToEnum(Inst.Ref, zir.extra[extra_index]);
4807 extra_index += 1;4818 extra_index += 1;
4808 const item_last = @intToEnum(Inst.Ref, zir.extra[extra_index]);
4809 extra_index += 1;4819 extra_index += 1;
4810 }4820 }
48114821
src/air.zig+36
...@@ -304,9 +304,12 @@ pub const Inst = struct {...@@ -304,9 +304,12 @@ pub const Inst = struct {
304 base: Inst,304 base: Inst,
305305
306 pub fn operandCount(self: *const NoOp) usize {306 pub fn operandCount(self: *const NoOp) usize {
307 _ = self;
307 return 0;308 return 0;
308 }309 }
309 pub fn getOperand(self: *const NoOp, index: usize) ?*Inst {310 pub fn getOperand(self: *const NoOp, index: usize) ?*Inst {
311 _ = self;
312 _ = index;
310 return null;313 return null;
311 }314 }
312 };315 };
...@@ -316,6 +319,7 @@ pub const Inst = struct {...@@ -316,6 +319,7 @@ pub const Inst = struct {
316 operand: *Inst,319 operand: *Inst,
317320
318 pub fn operandCount(self: *const UnOp) usize {321 pub fn operandCount(self: *const UnOp) usize {
322 _ = self;
319 return 1;323 return 1;
320 }324 }
321 pub fn getOperand(self: *const UnOp, index: usize) ?*Inst {325 pub fn getOperand(self: *const UnOp, index: usize) ?*Inst {
...@@ -331,6 +335,7 @@ pub const Inst = struct {...@@ -331,6 +335,7 @@ pub const Inst = struct {
331 rhs: *Inst,335 rhs: *Inst,
332336
333 pub fn operandCount(self: *const BinOp) usize {337 pub fn operandCount(self: *const BinOp) usize {
338 _ = self;
334 return 2;339 return 2;
335 }340 }
336 pub fn getOperand(self: *const BinOp, index: usize) ?*Inst {341 pub fn getOperand(self: *const BinOp, index: usize) ?*Inst {
...@@ -356,9 +361,12 @@ pub const Inst = struct {...@@ -356,9 +361,12 @@ pub const Inst = struct {
356 name: [*:0]const u8,361 name: [*:0]const u8,
357362
358 pub fn operandCount(self: *const Arg) usize {363 pub fn operandCount(self: *const Arg) usize {
364 _ = self;
359 return 0;365 return 0;
360 }366 }
361 pub fn getOperand(self: *const Arg, index: usize) ?*Inst {367 pub fn getOperand(self: *const Arg, index: usize) ?*Inst {
368 _ = self;
369 _ = index;
362 return null;370 return null;
363 }371 }
364 };372 };
...@@ -391,9 +399,12 @@ pub const Inst = struct {...@@ -391,9 +399,12 @@ pub const Inst = struct {
391 body: Body,399 body: Body,
392400
393 pub fn operandCount(self: *const Block) usize {401 pub fn operandCount(self: *const Block) usize {
402 _ = self;
394 return 0;403 return 0;
395 }404 }
396 pub fn getOperand(self: *const Block, index: usize) ?*Inst {405 pub fn getOperand(self: *const Block, index: usize) ?*Inst {
406 _ = self;
407 _ = index;
397 return null;408 return null;
398 }409 }
399 };410 };
...@@ -412,9 +423,12 @@ pub const Inst = struct {...@@ -412,9 +423,12 @@ pub const Inst = struct {
412 body: Body,423 body: Body,
413424
414 pub fn operandCount(self: *const BrBlockFlat) usize {425 pub fn operandCount(self: *const BrBlockFlat) usize {
426 _ = self;
415 return 0;427 return 0;
416 }428 }
417 pub fn getOperand(self: *const BrBlockFlat, index: usize) ?*Inst {429 pub fn getOperand(self: *const BrBlockFlat, index: usize) ?*Inst {
430 _ = self;
431 _ = index;
418 return null;432 return null;
419 }433 }
420 };434 };
...@@ -427,9 +441,11 @@ pub const Inst = struct {...@@ -427,9 +441,11 @@ pub const Inst = struct {
427 operand: *Inst,441 operand: *Inst,
428442
429 pub fn operandCount(self: *const Br) usize {443 pub fn operandCount(self: *const Br) usize {
444 _ = self;
430 return 1;445 return 1;
431 }446 }
432 pub fn getOperand(self: *const Br, index: usize) ?*Inst {447 pub fn getOperand(self: *const Br, index: usize) ?*Inst {
448 _ = self;
433 if (index == 0)449 if (index == 0)
434 return self.operand;450 return self.operand;
435 return null;451 return null;
...@@ -443,9 +459,12 @@ pub const Inst = struct {...@@ -443,9 +459,12 @@ pub const Inst = struct {
443 block: *Block,459 block: *Block,
444460
445 pub fn operandCount(self: *const BrVoid) usize {461 pub fn operandCount(self: *const BrVoid) usize {
462 _ = self;
446 return 0;463 return 0;
447 }464 }
448 pub fn getOperand(self: *const BrVoid, index: usize) ?*Inst {465 pub fn getOperand(self: *const BrVoid, index: usize) ?*Inst {
466 _ = self;
467 _ = index;
449 return null;468 return null;
450 }469 }
451 };470 };
...@@ -490,6 +509,7 @@ pub const Inst = struct {...@@ -490,6 +509,7 @@ pub const Inst = struct {
490 else_death_count: u32 = 0,509 else_death_count: u32 = 0,
491510
492 pub fn operandCount(self: *const CondBr) usize {511 pub fn operandCount(self: *const CondBr) usize {
512 _ = self;
493 return 1;513 return 1;
494 }514 }
495 pub fn getOperand(self: *const CondBr, index: usize) ?*Inst {515 pub fn getOperand(self: *const CondBr, index: usize) ?*Inst {
...@@ -516,9 +536,12 @@ pub const Inst = struct {...@@ -516,9 +536,12 @@ pub const Inst = struct {
516 val: Value,536 val: Value,
517537
518 pub fn operandCount(self: *const Constant) usize {538 pub fn operandCount(self: *const Constant) usize {
539 _ = self;
519 return 0;540 return 0;
520 }541 }
521 pub fn getOperand(self: *const Constant, index: usize) ?*Inst {542 pub fn getOperand(self: *const Constant, index: usize) ?*Inst {
543 _ = self;
544 _ = index;
522 return null;545 return null;
523 }546 }
524 };547 };
...@@ -530,9 +553,12 @@ pub const Inst = struct {...@@ -530,9 +553,12 @@ pub const Inst = struct {
530 body: Body,553 body: Body,
531554
532 pub fn operandCount(self: *const Loop) usize {555 pub fn operandCount(self: *const Loop) usize {
556 _ = self;
533 return 0;557 return 0;
534 }558 }
535 pub fn getOperand(self: *const Loop, index: usize) ?*Inst {559 pub fn getOperand(self: *const Loop, index: usize) ?*Inst {
560 _ = self;
561 _ = index;
536 return null;562 return null;
537 }563 }
538 };564 };
...@@ -544,9 +570,12 @@ pub const Inst = struct {...@@ -544,9 +570,12 @@ pub const Inst = struct {
544 variable: *Module.Var,570 variable: *Module.Var,
545571
546 pub fn operandCount(self: *const VarPtr) usize {572 pub fn operandCount(self: *const VarPtr) usize {
573 _ = self;
547 return 0;574 return 0;
548 }575 }
549 pub fn getOperand(self: *const VarPtr, index: usize) ?*Inst {576 pub fn getOperand(self: *const VarPtr, index: usize) ?*Inst {
577 _ = self;
578 _ = index;
550 return null;579 return null;
551 }580 }
552 };581 };
...@@ -559,9 +588,12 @@ pub const Inst = struct {...@@ -559,9 +588,12 @@ pub const Inst = struct {
559 field_index: usize,588 field_index: usize,
560589
561 pub fn operandCount(self: *const StructFieldPtr) usize {590 pub fn operandCount(self: *const StructFieldPtr) usize {
591 _ = self;
562 return 1;592 return 1;
563 }593 }
564 pub fn getOperand(self: *const StructFieldPtr, index: usize) ?*Inst {594 pub fn getOperand(self: *const StructFieldPtr, index: usize) ?*Inst {
595 _ = self;
596 _ = index;
565 var i = index;597 var i = index;
566598
567 if (i < 1)599 if (i < 1)
...@@ -593,6 +625,7 @@ pub const Inst = struct {...@@ -593,6 +625,7 @@ pub const Inst = struct {
593 };625 };
594626
595 pub fn operandCount(self: *const SwitchBr) usize {627 pub fn operandCount(self: *const SwitchBr) usize {
628 _ = self;
596 return 1;629 return 1;
597 }630 }
598 pub fn getOperand(self: *const SwitchBr, index: usize) ?*Inst {631 pub fn getOperand(self: *const SwitchBr, index: usize) ?*Inst {
...@@ -621,9 +654,12 @@ pub const Inst = struct {...@@ -621,9 +654,12 @@ pub const Inst = struct {
621 column: u32,654 column: u32,
622655
623 pub fn operandCount(self: *const DbgStmt) usize {656 pub fn operandCount(self: *const DbgStmt) usize {
657 _ = self;
624 return 0;658 return 0;
625 }659 }
626 pub fn getOperand(self: *const DbgStmt, index: usize) ?*Inst {660 pub fn getOperand(self: *const DbgStmt, index: usize) ?*Inst {
661 _ = self;
662 _ = index;
627 return null;663 return null;
628 }664 }
629 };665 };
src/codegen.zig+22-6
...@@ -118,7 +118,6 @@ pub fn generateSymbol(...@@ -118,7 +118,6 @@ pub fn generateSymbol(
118 if (typed_value.ty.sentinel()) |sentinel| {118 if (typed_value.ty.sentinel()) |sentinel| {
119 try code.ensureCapacity(code.items.len + payload.data.len + 1);119 try code.ensureCapacity(code.items.len + payload.data.len + 1);
120 code.appendSliceAssumeCapacity(payload.data);120 code.appendSliceAssumeCapacity(payload.data);
121 const prev_len = code.items.len;
122 switch (try generateSymbol(bin_file, src_loc, .{121 switch (try generateSymbol(bin_file, src_loc, .{
123 .ty = typed_value.ty.elemType(),122 .ty = typed_value.ty.elemType(),
124 .val = sentinel,123 .val = sentinel,
...@@ -565,7 +564,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -565,7 +564,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
565 .r11 = true, // fp564 .r11 = true, // fp
566 .r14 = true, // lr565 .r14 = true, // lr
567 };566 };
568 inline for (callee_preserved_regs) |reg, i| {567 inline for (callee_preserved_regs) |reg| {
569 if (self.register_manager.isRegAllocated(reg)) {568 if (self.register_manager.isRegAllocated(reg)) {
570 @field(saved_regs, @tagName(reg)) = true;569 @field(saved_regs, @tagName(reg)) = true;
571 }570 }
...@@ -603,7 +602,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -603,7 +602,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
603 } else {602 } else {
604 if (math.cast(i26, amt)) |offset| {603 if (math.cast(i26, amt)) |offset| {
605 writeInt(u32, self.code.items[jmp_reloc..][0..4], Instruction.b(.al, offset).toU32());604 writeInt(u32, self.code.items[jmp_reloc..][0..4], Instruction.b(.al, offset).toU32());
606 } else |err| {605 } else |_| {
607 return self.failSymbol("exitlude jump is too large", .{});606 return self.failSymbol("exitlude jump is too large", .{});
608 }607 }
609 }608 }
...@@ -676,7 +675,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -676,7 +675,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
676 } else {675 } else {
677 if (math.cast(i28, amt)) |offset| {676 if (math.cast(i28, amt)) |offset| {
678 writeInt(u32, self.code.items[jmp_reloc..][0..4], Instruction.b(offset).toU32());677 writeInt(u32, self.code.items[jmp_reloc..][0..4], Instruction.b(offset).toU32());
679 } else |err| {678 } else |_| {
680 return self.failSymbol("exitlude jump is too large", .{});679 return self.failSymbol("exitlude jump is too large", .{});
681 }680 }
682 }681 }
...@@ -1498,6 +1497,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -1498,6 +1497,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
1498 swap_lhs_and_rhs: bool,1497 swap_lhs_and_rhs: bool,
1499 op: ir.Inst.Tag,1498 op: ir.Inst.Tag,
1500 ) !void {1499 ) !void {
1500 _ = src;
1501 assert(lhs_mcv == .register or rhs_mcv == .register);1501 assert(lhs_mcv == .register or rhs_mcv == .register);
15021502
1503 const op1 = if (swap_lhs_and_rhs) rhs_mcv.register else lhs_mcv.register;1503 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 {...@@ -1906,6 +1906,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
1906 try self.genX8664ModRMRegToStack(src, dst_ty, off, src_reg, mr + 0x1);1906 try self.genX8664ModRMRegToStack(src, dst_ty, off, src_reg, mr + 0x1);
1907 },1907 },
1908 .immediate => |imm| {1908 .immediate => |imm| {
1909 _ = imm;
1909 return self.fail(src, "TODO implement x86 ADD/SUB/CMP source immediate", .{});1910 return self.fail(src, "TODO implement x86 ADD/SUB/CMP source immediate", .{});
1910 },1911 },
1911 .embedded_in_code, .memory, .stack_offset => {1912 .embedded_in_code, .memory, .stack_offset => {
...@@ -2055,6 +2056,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -2055,6 +2056,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
2055 return self.genSetStack(src, dst_ty, off, MCValue{ .register = dst_reg });2056 return self.genSetStack(src, dst_ty, off, MCValue{ .register = dst_reg });
2056 },2057 },
2057 .immediate => |imm| {2058 .immediate => |imm| {
2059 _ = imm;
2058 return self.fail(src, "TODO implement x86 multiply source immediate", .{});2060 return self.fail(src, "TODO implement x86 multiply source immediate", .{});
2059 },2061 },
2060 .embedded_in_code, .memory, .stack_offset => {2062 .embedded_in_code, .memory, .stack_offset => {
...@@ -2983,14 +2985,14 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -2983,14 +2985,14 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
2983 .arm, .armeb => {2985 .arm, .armeb => {
2984 if (math.cast(i26, @intCast(i32, index) - @intCast(i32, self.code.items.len + 8))) |delta| {2986 if (math.cast(i26, @intCast(i32, index) - @intCast(i32, self.code.items.len + 8))) |delta| {
2985 writeInt(u32, try self.code.addManyAsArray(4), Instruction.b(.al, delta).toU32());2987 writeInt(u32, try self.code.addManyAsArray(4), Instruction.b(.al, delta).toU32());
2986 } else |err| {2988 } else |_| {
2987 return self.fail(src, "TODO: enable larger branch offset", .{});2989 return self.fail(src, "TODO: enable larger branch offset", .{});
2988 }2990 }
2989 },2991 },
2990 .aarch64, .aarch64_be, .aarch64_32 => {2992 .aarch64, .aarch64_be, .aarch64_32 => {
2991 if (math.cast(i28, @intCast(i32, index) - @intCast(i32, self.code.items.len + 8))) |delta| {2993 if (math.cast(i28, @intCast(i32, index) - @intCast(i32, self.code.items.len + 8))) |delta| {
2992 writeInt(u32, try self.code.addManyAsArray(4), Instruction.b(delta).toU32());2994 writeInt(u32, try self.code.addManyAsArray(4), Instruction.b(delta).toU32());
2993 } else |err| {2995 } else |_| {
2994 return self.fail(src, "TODO: enable larger branch offset", .{});2996 return self.fail(src, "TODO: enable larger branch offset", .{});
2995 }2997 }
2996 },2998 },
...@@ -3308,9 +3310,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -3308,9 +3310,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
3308 }3310 }
3309 },3311 },
3310 .compare_flags_unsigned => |op| {3312 .compare_flags_unsigned => |op| {
3313 _ = op;
3311 return self.fail(src, "TODO implement set stack variable with compare flags value (unsigned)", .{});3314 return self.fail(src, "TODO implement set stack variable with compare flags value (unsigned)", .{});
3312 },3315 },
3313 .compare_flags_signed => |op| {3316 .compare_flags_signed => |op| {
3317 _ = op;
3314 return self.fail(src, "TODO implement set stack variable with compare flags value (signed)", .{});3318 return self.fail(src, "TODO implement set stack variable with compare flags value (signed)", .{});
3315 },3319 },
3316 .immediate => {3320 .immediate => {
...@@ -3318,6 +3322,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -3318,6 +3322,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
3318 return self.genSetStack(src, ty, stack_offset, MCValue{ .register = reg });3322 return self.genSetStack(src, ty, stack_offset, MCValue{ .register = reg });
3319 },3323 },
3320 .embedded_in_code => |code_offset| {3324 .embedded_in_code => |code_offset| {
3325 _ = code_offset;
3321 return self.fail(src, "TODO implement set stack variable from embedded_in_code", .{});3326 return self.fail(src, "TODO implement set stack variable from embedded_in_code", .{});
3322 },3327 },
3323 .register => |reg| {3328 .register => |reg| {
...@@ -3354,6 +3359,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -3354,6 +3359,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
3354 }3359 }
3355 },3360 },
3356 .memory => |vaddr| {3361 .memory => |vaddr| {
3362 _ = vaddr;
3357 return self.fail(src, "TODO implement set stack variable from memory vaddr", .{});3363 return self.fail(src, "TODO implement set stack variable from memory vaddr", .{});
3358 },3364 },
3359 .stack_offset => |off| {3365 .stack_offset => |off| {
...@@ -3382,9 +3388,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -3382,9 +3388,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
3382 }3388 }
3383 },3389 },
3384 .compare_flags_unsigned => |op| {3390 .compare_flags_unsigned => |op| {
3391 _ = op;
3385 return self.fail(src, "TODO implement set stack variable with compare flags value (unsigned)", .{});3392 return self.fail(src, "TODO implement set stack variable with compare flags value (unsigned)", .{});
3386 },3393 },
3387 .compare_flags_signed => |op| {3394 .compare_flags_signed => |op| {
3395 _ = op;
3388 return self.fail(src, "TODO implement set stack variable with compare flags value (signed)", .{});3396 return self.fail(src, "TODO implement set stack variable with compare flags value (signed)", .{});
3389 },3397 },
3390 .immediate => |x_big| {3398 .immediate => |x_big| {
...@@ -3437,12 +3445,14 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -3437,12 +3445,14 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
3437 }3445 }
3438 },3446 },
3439 .embedded_in_code => |code_offset| {3447 .embedded_in_code => |code_offset| {
3448 _ = code_offset;
3440 return self.fail(src, "TODO implement set stack variable from embedded_in_code", .{});3449 return self.fail(src, "TODO implement set stack variable from embedded_in_code", .{});
3441 },3450 },
3442 .register => |reg| {3451 .register => |reg| {
3443 try self.genX8664ModRMRegToStack(src, ty, stack_offset, reg, 0x89);3452 try self.genX8664ModRMRegToStack(src, ty, stack_offset, reg, 0x89);
3444 },3453 },
3445 .memory => |vaddr| {3454 .memory => |vaddr| {
3455 _ = vaddr;
3446 return self.fail(src, "TODO implement set stack variable from memory vaddr", .{});3456 return self.fail(src, "TODO implement set stack variable from memory vaddr", .{});
3447 },3457 },
3448 .stack_offset => |off| {3458 .stack_offset => |off| {
...@@ -3471,9 +3481,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -3471,9 +3481,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
3471 }3481 }
3472 },3482 },
3473 .compare_flags_unsigned => |op| {3483 .compare_flags_unsigned => |op| {
3484 _ = op;
3474 return self.fail(src, "TODO implement set stack variable with compare flags value (unsigned)", .{});3485 return self.fail(src, "TODO implement set stack variable with compare flags value (unsigned)", .{});
3475 },3486 },
3476 .compare_flags_signed => |op| {3487 .compare_flags_signed => |op| {
3488 _ = op;
3477 return self.fail(src, "TODO implement set stack variable with compare flags value (signed)", .{});3489 return self.fail(src, "TODO implement set stack variable with compare flags value (signed)", .{});
3478 },3490 },
3479 .immediate => {3491 .immediate => {
...@@ -3481,6 +3493,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -3481,6 +3493,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
3481 return self.genSetStack(src, ty, stack_offset, MCValue{ .register = reg });3493 return self.genSetStack(src, ty, stack_offset, MCValue{ .register = reg });
3482 },3494 },
3483 .embedded_in_code => |code_offset| {3495 .embedded_in_code => |code_offset| {
3496 _ = code_offset;
3484 return self.fail(src, "TODO implement set stack variable from embedded_in_code", .{});3497 return self.fail(src, "TODO implement set stack variable from embedded_in_code", .{});
3485 },3498 },
3486 .register => |reg| {3499 .register => |reg| {
...@@ -3513,6 +3526,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -3513,6 +3526,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
3513 }3526 }
3514 },3527 },
3515 .memory => |vaddr| {3528 .memory => |vaddr| {
3529 _ = vaddr;
3516 return self.fail(src, "TODO implement set stack variable from memory vaddr", .{});3530 return self.fail(src, "TODO implement set stack variable from memory vaddr", .{});
3517 },3531 },
3518 .stack_offset => |off| {3532 .stack_offset => |off| {
...@@ -3843,6 +3857,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -3843,6 +3857,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
3843 );3857 );
3844 },3858 },
3845 .compare_flags_signed => |op| {3859 .compare_flags_signed => |op| {
3860 _ = op;
3846 return self.fail(src, "TODO set register with compare flags value (signed)", .{});3861 return self.fail(src, "TODO set register with compare flags value (signed)", .{});
3847 },3862 },
3848 .immediate => |x| {3863 .immediate => |x| {
...@@ -4461,6 +4476,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -4461,6 +4476,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
4461 dummy,4476 dummy,
44624477
4463 pub fn allocIndex(self: Register) ?u4 {4478 pub fn allocIndex(self: Register) ?u4 {
4479 _ = self;
4464 return null;4480 return null;
4465 }4481 }
4466 };4482 };
src/codegen/arm.zig+1-1
...@@ -674,7 +674,7 @@ pub const Instruction = union(enum) {...@@ -674,7 +674,7 @@ pub const Instruction = union(enum) {
674 };674 };
675 const imm4h: u4 = switch (offset) {675 const imm4h: u4 = switch (offset) {
676 .immediate => |imm| @truncate(u4, imm >> 4),676 .immediate => |imm| @truncate(u4, imm >> 4),
677 .register => |reg| 0b0000,677 .register => 0b0000,
678 };678 };
679679
680 return Instruction{680 return Instruction{
src/codegen/c.zig+9-1
...@@ -47,6 +47,8 @@ fn formatTypeAsCIdentifier(...@@ -47,6 +47,8 @@ fn formatTypeAsCIdentifier(
47 options: std.fmt.FormatOptions,47 options: std.fmt.FormatOptions,
48 writer: anytype,48 writer: anytype,
49) !void {49) !void {
50 _ = fmt;
51 _ = options;
50 var buffer = [1]u8{0} ** 128;52 var buffer = [1]u8{0} ** 128;
51 // We don't care if it gets cut off, it's still more unique than a number53 // We don't care if it gets cut off, it's still more unique than a number
52 var buf = std.fmt.bufPrint(&buffer, "{}", .{data}) catch &buffer;54 var buf = std.fmt.bufPrint(&buffer, "{}", .{data}) catch &buffer;
...@@ -63,6 +65,8 @@ fn formatIdent(...@@ -63,6 +65,8 @@ fn formatIdent(
63 options: std.fmt.FormatOptions,65 options: std.fmt.FormatOptions,
64 writer: anytype,66 writer: anytype,
65) !void {67) !void {
68 _ = fmt;
69 _ = options;
66 for (ident) |c, i| {70 for (ident) |c, i| {
67 switch (c) {71 switch (c) {
68 'a'...'z', 'A'...'Z', '_' => try writer.writeByte(c),72 'a'...'z', 'A'...'Z', '_' => try writer.writeByte(c),
...@@ -747,6 +751,7 @@ pub fn genBody(o: *Object, body: ir.Body) error{ AnalysisFail, OutOfMemory }!voi...@@ -747,6 +751,7 @@ pub fn genBody(o: *Object, body: ir.Body) error{ AnalysisFail, OutOfMemory }!voi
747}751}
748752
749fn genVarPtr(o: *Object, inst: *Inst.VarPtr) !CValue {753fn genVarPtr(o: *Object, inst: *Inst.VarPtr) !CValue {
754 _ = o;
750 return CValue{ .decl_ref = inst.variable.owner_decl };755 return CValue{ .decl_ref = inst.variable.owner_decl };
751}756}
752757
...@@ -937,6 +942,8 @@ fn genCall(o: *Object, inst: *Inst.Call) !CValue {...@@ -937,6 +942,8 @@ fn genCall(o: *Object, inst: *Inst.Call) !CValue {
937}942}
938943
939fn genDbgStmt(o: *Object, inst: *Inst.DbgStmt) !CValue {944fn genDbgStmt(o: *Object, inst: *Inst.DbgStmt) !CValue {
945 _ = o;
946 _ = inst;
940 // TODO emit #line directive here with line number and filename947 // TODO emit #line directive here with line number and filename
941 return CValue.none;948 return CValue.none;
942}949}
...@@ -1016,11 +1023,13 @@ fn genBitcast(o: *Object, inst: *Inst.UnOp) !CValue {...@@ -1016,11 +1023,13 @@ fn genBitcast(o: *Object, inst: *Inst.UnOp) !CValue {
1016}1023}
10171024
1018fn genBreakpoint(o: *Object, inst: *Inst.NoOp) !CValue {1025fn genBreakpoint(o: *Object, inst: *Inst.NoOp) !CValue {
1026 _ = inst;
1019 try o.writer().writeAll("zig_breakpoint();\n");1027 try o.writer().writeAll("zig_breakpoint();\n");
1020 return CValue.none;1028 return CValue.none;
1021}1029}
10221030
1023fn genUnreach(o: *Object, inst: *Inst.NoOp) !CValue {1031fn genUnreach(o: *Object, inst: *Inst.NoOp) !CValue {
1032 _ = inst;
1024 try o.writer().writeAll("zig_unreachable();\n");1033 try o.writer().writeAll("zig_unreachable();\n");
1025 return CValue.none;1034 return CValue.none;
1026}1035}
...@@ -1107,7 +1116,6 @@ fn genAsm(o: *Object, as: *Inst.Assembly) !CValue {...@@ -1107,7 +1116,6 @@ fn genAsm(o: *Object, as: *Inst.Assembly) !CValue {
1107 for (as.inputs) |i, index| {1116 for (as.inputs) |i, index| {
1108 if (i[0] == '{' and i[i.len - 1] == '}') {1117 if (i[0] == '{' and i[i.len - 1] == '}') {
1109 const reg = i[1 .. i.len - 1];1118 const reg = i[1 .. i.len - 1];
1110 const arg = as.args[index];
1111 if (index > 0) {1119 if (index > 0) {
1112 try writer.writeAll(", ");1120 try writer.writeAll(", ");
1113 }1121 }
src/codegen/llvm.zig+4
...@@ -154,6 +154,7 @@ pub const Object = struct {...@@ -154,6 +154,7 @@ pub const Object = struct {
154 object_pathZ: [:0]const u8,154 object_pathZ: [:0]const u8,
155155
156 pub fn create(allocator: *Allocator, sub_path: []const u8, options: link.Options) !*Object {156 pub fn create(allocator: *Allocator, sub_path: []const u8, options: link.Options) !*Object {
157 _ = sub_path;
157 const self = try allocator.create(Object);158 const self = try allocator.create(Object);
158 errdefer allocator.destroy(self);159 errdefer allocator.destroy(self);
159160
...@@ -742,6 +743,7 @@ pub const FuncGen = struct {...@@ -742,6 +743,7 @@ pub const FuncGen = struct {
742 }743 }
743744
744 fn genRetVoid(self: *FuncGen, inst: *Inst.NoOp) ?*const llvm.Value {745 fn genRetVoid(self: *FuncGen, inst: *Inst.NoOp) ?*const llvm.Value {
746 _ = inst;
745 _ = self.builder.buildRetVoid();747 _ = self.builder.buildRetVoid();
746 return null;748 return null;
747 }749 }
...@@ -873,6 +875,7 @@ pub const FuncGen = struct {...@@ -873,6 +875,7 @@ pub const FuncGen = struct {
873 }875 }
874876
875 fn genUnreach(self: *FuncGen, inst: *Inst.NoOp) ?*const llvm.Value {877 fn genUnreach(self: *FuncGen, inst: *Inst.NoOp) ?*const llvm.Value {
878 _ = inst;
876 _ = self.builder.buildUnreachable();879 _ = self.builder.buildUnreachable();
877 return null;880 return null;
878 }881 }
...@@ -1013,6 +1016,7 @@ pub const FuncGen = struct {...@@ -1013,6 +1016,7 @@ pub const FuncGen = struct {
1013 }1016 }
10141017
1015 fn genBreakpoint(self: *FuncGen, inst: *Inst.NoOp) !?*const llvm.Value {1018 fn genBreakpoint(self: *FuncGen, inst: *Inst.NoOp) !?*const llvm.Value {
1019 _ = inst;
1016 const llvn_fn = self.getIntrinsic("llvm.debugtrap");1020 const llvn_fn = self.getIntrinsic("llvm.debugtrap");
1017 _ = self.builder.buildCall(llvn_fn, null, 0, "");1021 _ = self.builder.buildCall(llvn_fn, null, 0, "");
1018 return null;1022 return null;
src/codegen/spirv.zig+1-3
...@@ -714,7 +714,6 @@ pub const DeclGen = struct {...@@ -714,7 +714,6 @@ pub const DeclGen = struct {
714 return self.fail(inst.base.src, "TODO: SPIR-V backend: binary operations for strange integers", .{});714 return self.fail(inst.base.src, "TODO: SPIR-V backend: binary operations for strange integers", .{});
715 }715 }
716716
717 const is_bool = info.class == .bool;
718 const is_float = info.class == .float;717 const is_float = info.class == .float;
719 const is_signed = info.signedness == .signed;718 const is_signed = info.signedness == .signed;
720 // **Note**: All these operations must be valid for vectors as well!719 // **Note**: All these operations must be valid for vectors as well!
...@@ -802,8 +801,6 @@ pub const DeclGen = struct {...@@ -802,8 +801,6 @@ pub const DeclGen = struct {
802 const result_id = self.spv.allocResultId();801 const result_id = self.spv.allocResultId();
803 const result_type_id = try self.genType(inst.base.src, inst.base.ty);802 const result_type_id = try self.genType(inst.base.src, inst.base.ty);
804803
805 const info = try self.arithmeticTypeInfo(inst.operand.ty);
806
807 const opcode = switch (inst.base.tag) {804 const opcode = switch (inst.base.tag) {
808 // Bool -> bool805 // Bool -> bool
809 .not => Opcode.OpLogicalNot,806 .not => Opcode.OpLogicalNot,
...@@ -867,6 +864,7 @@ pub const DeclGen = struct {...@@ -867,6 +864,7 @@ pub const DeclGen = struct {
867 // are not allowed to be created from a phi node, and throw an error for those. For now, genType already throws864 // are not allowed to be created from a phi node, and throw an error for those. For now, genType already throws
868 // an error for pointers.865 // an error for pointers.
869 const result_type_id = try self.genType(inst.base.src, inst.base.ty);866 const result_type_id = try self.genType(inst.base.src, inst.base.ty);
867 _ = result_type_id;
870868
871 try writeOpcode(&self.code, .OpPhi, 2 + @intCast(u16, incoming_blocks.items.len * 2)); // result type + result + variable/parent...869 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 {...@@ -702,7 +702,7 @@ pub const Context = struct {
702 try writer.writeByte(wasm.valtype(.i32)); // error code is always an i32 integer.702 try writer.writeByte(wasm.valtype(.i32)); // error code is always an i32 integer.
703 try writer.writeByte(val_type);703 try writer.writeByte(val_type);
704 },704 },
705 else => |ret_type| {705 else => {
706 try leb.writeULEB128(writer, @as(u32, 1));706 try leb.writeULEB128(writer, @as(u32, 1));
707 // Can we maybe get the source index of the return type?707 // Can we maybe get the source index of the return type?
708 const val_type = try self.genValtype(.{ .node_offset = 0 }, return_type);708 const val_type = try self.genValtype(.{ .node_offset = 0 }, return_type);
...@@ -721,7 +721,7 @@ pub const Context = struct {...@@ -721,7 +721,7 @@ pub const Context = struct {
721 // TODO: check for and handle death of instructions721 // TODO: check for and handle death of instructions
722 const mod_fn = blk: {722 const mod_fn = blk: {
723 if (typed_value.val.castTag(.function)) |func| break :blk func.data;723 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 functions724 if (typed_value.val.castTag(.extern_fn)) |_| return Result.appended; // don't need code body for extern functions
725 unreachable;725 unreachable;
726 };726 };
727727
...@@ -849,7 +849,6 @@ pub const Context = struct {...@@ -849,7 +849,6 @@ pub const Context = struct {
849 }849 }
850850
851 fn genCall(self: *Context, inst: *Inst.Call) InnerError!WValue {851 fn genCall(self: *Context, inst: *Inst.Call) InnerError!WValue {
852 const func_inst = inst.func.castTag(.constant).?;
853 const func_val = inst.func.value().?;852 const func_val = inst.func.value().?;
854853
855 const target: *Decl = blk: {854 const target: *Decl = blk: {
...@@ -914,7 +913,7 @@ pub const Context = struct {...@@ -914,7 +913,7 @@ pub const Context = struct {
914 .local => |local| {913 .local => |local| {
915 try self.emitWValue(rhs);914 try self.emitWValue(rhs);
916 try writer.writeByte(wasm.opcode(.local_set));915 try writer.writeByte(wasm.opcode(.local_set));
917 try leb.writeULEB128(writer, lhs.local);916 try leb.writeULEB128(writer, local);
918 },917 },
919 else => unreachable,918 else => unreachable,
920 }919 }
...@@ -926,6 +925,7 @@ pub const Context = struct {...@@ -926,6 +925,7 @@ pub const Context = struct {
926 }925 }
927926
928 fn genArg(self: *Context, inst: *Inst.Arg) InnerError!WValue {927 fn genArg(self: *Context, inst: *Inst.Arg) InnerError!WValue {
928 _ = inst;
929 // arguments share the index with locals929 // arguments share the index with locals
930 defer self.local_index += 1;930 defer self.local_index += 1;
931 return WValue{ .local = self.local_index };931 return WValue{ .local = self.local_index };
...@@ -1146,8 +1146,6 @@ pub const Context = struct {...@@ -1146,8 +1146,6 @@ pub const Context = struct {
1146 }1146 }
11471147
1148 fn genCmp(self: *Context, inst: *Inst.BinOp, op: std.math.CompareOperator) InnerError!WValue {1148 fn genCmp(self: *Context, inst: *Inst.BinOp, op: std.math.CompareOperator) InnerError!WValue {
1149 const ty = inst.lhs.ty.tag();
1150
1151 // save offset, so potential conditions can insert blocks in front of1149 // save offset, so potential conditions can insert blocks in front of
1152 // the comparison that we can later jump back to1150 // the comparison that we can later jump back to
1153 const offset = self.code.items.len;1151 const offset = self.code.items.len;
...@@ -1216,12 +1214,15 @@ pub const Context = struct {...@@ -1216,12 +1214,15 @@ pub const Context = struct {
1216 }1214 }
12171215
1218 fn genBreakpoint(self: *Context, breakpoint: *Inst.NoOp) InnerError!WValue {1216 fn genBreakpoint(self: *Context, breakpoint: *Inst.NoOp) InnerError!WValue {
1217 _ = self;
1218 _ = breakpoint;
1219 // unsupported by wasm itself. Can be implemented once we support DWARF1219 // unsupported by wasm itself. Can be implemented once we support DWARF
1220 // for wasm1220 // for wasm
1221 return .none;1221 return .none;
1222 }1222 }
12231223
1224 fn genUnreachable(self: *Context, unreach: *Inst.NoOp) InnerError!WValue {1224 fn genUnreachable(self: *Context, unreach: *Inst.NoOp) InnerError!WValue {
1225 _ = unreach;
1225 try self.code.append(wasm.opcode(.@"unreachable"));1226 try self.code.append(wasm.opcode(.@"unreachable"));
1226 return .none;1227 return .none;
1227 }1228 }
src/glibc.zig-1
...@@ -497,7 +497,6 @@ fn add_include_dirs(comp: *Compilation, arena: *Allocator, args: *std.ArrayList(...@@ -497,7 +497,6 @@ fn add_include_dirs(comp: *Compilation, arena: *Allocator, args: *std.ArrayList(
497 const target = comp.getTarget();497 const target = comp.getTarget();
498 const arch = target.cpu.arch;498 const arch = target.cpu.arch;
499 const opt_nptl: ?[]const u8 = if (target.os.tag == .linux) "nptl" else "htl";499 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
502 const s = path.sep_str;501 const s = path.sep_str;
503502
src/link.zig+1-1
...@@ -517,7 +517,7 @@ pub const File = struct {...@@ -517,7 +517,7 @@ pub const File = struct {
517 .target = base.options.target,517 .target = base.options.target,
518 .output_mode = .Obj,518 .output_mode = .Obj,
519 });519 });
520 const o_directory = base.options.module.?.zig_cache_artifact_directory;520 const o_directory = module.zig_cache_artifact_directory;
521 const full_obj_path = try o_directory.join(arena, &[_][]const u8{obj_basename});521 const full_obj_path = try o_directory.join(arena, &[_][]const u8{obj_basename});
522 break :blk full_obj_path;522 break :blk full_obj_path;
523 }523 }
src/link/C.zig+10-2
...@@ -76,7 +76,10 @@ pub fn deinit(self: *C) void {...@@ -76,7 +76,10 @@ pub fn deinit(self: *C) void {
76 self.decl_table.deinit(self.base.allocator);76 self.decl_table.deinit(self.base.allocator);
77}77}
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
81pub fn freeDecl(self: *C, decl: *Module.Decl) void {84pub fn freeDecl(self: *C, decl: *Module.Decl) void {
82 _ = self.decl_table.swapRemove(decl);85 _ = self.decl_table.swapRemove(decl);
...@@ -307,4 +310,9 @@ pub fn updateDeclExports(...@@ -307,4 +310,9 @@ pub fn updateDeclExports(
307 module: *Module,310 module: *Module,
308 decl: *Module.Decl,311 decl: *Module.Decl,
309 exports: []const *Module.Export,312 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 {...@@ -831,7 +831,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
831 .target = self.base.options.target,831 .target = self.base.options.target,
832 .output_mode = .Obj,832 .output_mode = .Obj,
833 });833 });
834 const o_directory = self.base.options.module.?.zig_cache_artifact_directory;834 const o_directory = module.zig_cache_artifact_directory;
835 const full_obj_path = try o_directory.join(arena, &[_][]const u8{obj_basename});835 const full_obj_path = try o_directory.join(arena, &[_][]const u8{obj_basename});
836 break :blk full_obj_path;836 break :blk full_obj_path;
837 }837 }
...@@ -1340,6 +1340,9 @@ pub fn getDeclVAddr(self: *Coff, decl: *const Module.Decl) u64 {...@@ -1340,6 +1340,9 @@ pub fn getDeclVAddr(self: *Coff, decl: *const Module.Decl) u64 {
1340}1340}
13411341
1342pub fn updateDeclLineNumber(self: *Coff, module: *Module, decl: *Module.Decl) !void {1342pub fn updateDeclLineNumber(self: *Coff, module: *Module, decl: *Module.Decl) !void {
1343 _ = self;
1344 _ = module;
1345 _ = decl;
1343 // TODO Implement this1346 // TODO Implement this
1344}1347}
13451348
src/link/Elf.zig+8-3
...@@ -1262,7 +1262,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1262,7 +1262,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
1262 .target = self.base.options.target,1262 .target = self.base.options.target,
1263 .output_mode = .Obj,1263 .output_mode = .Obj,
1264 });1264 });
1265 const o_directory = self.base.options.module.?.zig_cache_artifact_directory;1265 const o_directory = module.zig_cache_artifact_directory;
1266 const full_obj_path = try o_directory.join(arena, &[_][]const u8{obj_basename});1266 const full_obj_path = try o_directory.join(arena, &[_][]const u8{obj_basename});
1267 break :blk full_obj_path;1267 break :blk full_obj_path;
1268 }1268 }
...@@ -1938,6 +1938,9 @@ fn freeTextBlock(self: *Elf, text_block: *TextBlock) void {...@@ -1938,6 +1938,9 @@ fn freeTextBlock(self: *Elf, text_block: *TextBlock) void {
1938}1938}
19391939
1940fn shrinkTextBlock(self: *Elf, text_block: *TextBlock, new_block_size: u64) void {1940fn shrinkTextBlock(self: *Elf, text_block: *TextBlock, new_block_size: u64) void {
1941 _ = self;
1942 _ = text_block;
1943 _ = new_block_size;
1941 // TODO check the new capacity, and if it crosses the size threshold into a big enough1944 // TODO check the new capacity, and if it crosses the size threshold into a big enough
1942 // capacity, insert a free list node for it.1945 // capacity, insert a free list node for it.
1943}1946}
...@@ -2706,6 +2709,7 @@ pub fn updateDeclExports(...@@ -2706,6 +2709,7 @@ pub fn updateDeclExports(
27062709
2707/// Must be called only after a successful call to `updateDecl`.2710/// Must be called only after a successful call to `updateDecl`.
2708pub fn updateDeclLineNumber(self: *Elf, module: *Module, decl: *const Module.Decl) !void {2711pub fn updateDeclLineNumber(self: *Elf, module: *Module, decl: *const Module.Decl) !void {
2712 _ = module;
2709 const tracy = trace(@src());2713 const tracy = trace(@src());
2710 defer tracy.end();2714 defer tracy.end();
27112715
...@@ -2979,6 +2983,7 @@ fn dbgLineNeededHeaderBytes(self: Elf) u32 {...@@ -2979,6 +2983,7 @@ fn dbgLineNeededHeaderBytes(self: Elf) u32 {
2979}2983}
29802984
2981fn dbgInfoNeededHeaderBytes(self: Elf) u32 {2985fn dbgInfoNeededHeaderBytes(self: Elf) u32 {
2986 _ = self;
2982 return 120;2987 return 120;
2983}2988}
29842989
...@@ -3372,7 +3377,7 @@ const CsuObjects = struct {...@@ -3372,7 +3377,7 @@ const CsuObjects = struct {
3372 if (result.crtend) |*obj| obj.* = try fs.path.join(arena, &[_][]const u8{ gcc_dir_path, obj.* });3377 if (result.crtend) |*obj| obj.* = try fs.path.join(arena, &[_][]const u8{ gcc_dir_path, obj.* });
3373 },3378 },
3374 else => {3379 else => {
3375 inline for (std.meta.fields(@TypeOf(result))) |f, i| {3380 inline for (std.meta.fields(@TypeOf(result))) |f| {
3376 if (@field(result, f.name)) |*obj| {3381 if (@field(result, f.name)) |*obj| {
3377 obj.* = try fs.path.join(arena, &[_][]const u8{ crt_dir_path, obj.* });3382 obj.* = try fs.path.join(arena, &[_][]const u8{ crt_dir_path, obj.* });
3378 }3383 }
...@@ -3380,7 +3385,7 @@ const CsuObjects = struct {...@@ -3380,7 +3385,7 @@ const CsuObjects = struct {
3380 },3385 },
3381 }3386 }
3382 } else {3387 } else {
3383 inline for (std.meta.fields(@TypeOf(result))) |f, i| {3388 inline for (std.meta.fields(@TypeOf(result))) |f| {
3384 if (@field(result, f.name)) |*obj| {3389 if (@field(result, f.name)) |*obj| {
3385 if (comp.crt_files.get(obj.*)) |crtf| {3390 if (comp.crt_files.get(obj.*)) |crtf| {
3386 obj.* = crtf.full_object_path;3391 obj.* = crtf.full_object_path;
src/link/MachO.zig+5-4
...@@ -441,6 +441,7 @@ pub fn flush(self: *MachO, comp: *Compilation) !void {...@@ -441,6 +441,7 @@ pub fn flush(self: *MachO, comp: *Compilation) !void {
441}441}
442442
443pub fn flushModule(self: *MachO, comp: *Compilation) !void {443pub fn flushModule(self: *MachO, comp: *Compilation) !void {
444 _ = comp;
444 const tracy = trace(@src());445 const tracy = trace(@src());
445 defer tracy.end();446 defer tracy.end();
446447
...@@ -533,7 +534,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {...@@ -533,7 +534,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
533 .target = self.base.options.target,534 .target = self.base.options.target,
534 .output_mode = .Obj,535 .output_mode = .Obj,
535 });536 });
536 const o_directory = self.base.options.module.?.zig_cache_artifact_directory;537 const o_directory = module.zig_cache_artifact_directory;
537 const full_obj_path = try o_directory.join(arena, &[_][]const u8{obj_basename});538 const full_obj_path = try o_directory.join(arena, &[_][]const u8{obj_basename});
538 break :blk full_obj_path;539 break :blk full_obj_path;
539 }540 }
...@@ -1254,6 +1255,9 @@ fn freeTextBlock(self: *MachO, text_block: *TextBlock) void {...@@ -1254,6 +1255,9 @@ fn freeTextBlock(self: *MachO, text_block: *TextBlock) void {
1254}1255}
12551256
1256fn shrinkTextBlock(self: *MachO, text_block: *TextBlock, new_block_size: u64) void {1257fn shrinkTextBlock(self: *MachO, text_block: *TextBlock, new_block_size: u64) void {
1258 _ = self;
1259 _ = text_block;
1260 _ = new_block_size;
1257 // TODO check the new capacity, and if it crosses the size threshold into a big enough1261 // TODO check the new capacity, and if it crosses the size threshold into a big enough
1258 // capacity, insert a free list node for it.1262 // capacity, insert a free list node for it.
1259}1263}
...@@ -2918,7 +2922,6 @@ fn relocateSymbolTable(self: *MachO) !void {...@@ -2918,7 +2922,6 @@ fn relocateSymbolTable(self: *MachO) !void {
2918 const nsyms = nlocals + nglobals + nundefs;2922 const nsyms = nlocals + nglobals + nundefs;
29192923
2920 if (symtab.nsyms < nsyms) {2924 if (symtab.nsyms < nsyms) {
2921 const linkedit_segment = self.load_commands.items[self.linkedit_segment_cmd_index.?].Segment;
2922 const needed_size = nsyms * @sizeOf(macho.nlist_64);2925 const needed_size = nsyms * @sizeOf(macho.nlist_64);
2923 if (needed_size > self.allocatedSizeLinkedit(symtab.symoff)) {2926 if (needed_size > self.allocatedSizeLinkedit(symtab.symoff)) {
2924 // Move the entire symbol table to a new location2927 // Move the entire symbol table to a new location
...@@ -3150,7 +3153,6 @@ fn writeExportTrie(self: *MachO) !void {...@@ -3150,7 +3153,6 @@ fn writeExportTrie(self: *MachO) !void {
3150 const nwritten = try trie.write(stream.writer());3153 const nwritten = try trie.write(stream.writer());
3151 assert(nwritten == trie.size);3154 assert(nwritten == trie.size);
31523155
3153 const linkedit_segment = self.load_commands.items[self.linkedit_segment_cmd_index.?].Segment;
3154 const dyld_info = &self.load_commands.items[self.dyld_info_cmd_index.?].DyldInfoOnly;3156 const dyld_info = &self.load_commands.items[self.dyld_info_cmd_index.?].DyldInfoOnly;
3155 const allocated_size = self.allocatedSizeLinkedit(dyld_info.export_off);3157 const allocated_size = self.allocatedSizeLinkedit(dyld_info.export_off);
3156 const needed_size = mem.alignForwardGeneric(u64, buffer.len, @alignOf(u64));3158 const needed_size = mem.alignForwardGeneric(u64, buffer.len, @alignOf(u64));
...@@ -3357,7 +3359,6 @@ fn populateLazyBindOffsetsInStubHelper(self: *MachO, buffer: []const u8) !void {...@@ -3357,7 +3359,6 @@ fn populateLazyBindOffsetsInStubHelper(self: *MachO, buffer: []const u8) !void {
3357 error.EndOfStream => break,3359 error.EndOfStream => break,
3358 else => return err,3360 else => return err,
3359 };3361 };
3360 const imm: u8 = inst & macho.BIND_IMMEDIATE_MASK;
3361 const opcode: u8 = inst & macho.BIND_OPCODE_MASK;3362 const opcode: u8 = inst & macho.BIND_OPCODE_MASK;
33623363
3363 switch (opcode) {3364 switch (opcode) {
src/link/MachO/DebugSymbols.zig+6-7
...@@ -500,7 +500,6 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt...@@ -500,7 +500,6 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt
500 if (self.debug_aranges_section_dirty) {500 if (self.debug_aranges_section_dirty) {
501 const dwarf_segment = &self.load_commands.items[self.dwarf_segment_cmd_index.?].Segment;501 const dwarf_segment = &self.load_commands.items[self.dwarf_segment_cmd_index.?].Segment;
502 const debug_aranges_sect = &dwarf_segment.sections.items[self.debug_aranges_section_index.?];502 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
505 var di_buf = std.ArrayList(u8).init(allocator);504 var di_buf = std.ArrayList(u8).init(allocator);
506 defer di_buf.deinit();505 defer di_buf.deinit();
...@@ -844,7 +843,6 @@ fn relocateSymbolTable(self: *DebugSymbols) !void {...@@ -844,7 +843,6 @@ fn relocateSymbolTable(self: *DebugSymbols) !void {
844 const nsyms = nlocals + nglobals;843 const nsyms = nlocals + nglobals;
845844
846 if (symtab.nsyms < nsyms) {845 if (symtab.nsyms < nsyms) {
847 const linkedit_segment = self.load_commands.items[self.linkedit_segment_cmd_index.?].Segment;
848 const needed_size = nsyms * @sizeOf(macho.nlist_64);846 const needed_size = nsyms * @sizeOf(macho.nlist_64);
849 if (needed_size > self.allocatedSizeLinkedit(symtab.symoff)) {847 if (needed_size > self.allocatedSizeLinkedit(symtab.symoff)) {
850 // Move the entire symbol table to a new location848 // Move the entire symbol table to a new location
...@@ -901,14 +899,10 @@ fn writeStringTable(self: *DebugSymbols) !void {...@@ -901,14 +899,10 @@ fn writeStringTable(self: *DebugSymbols) !void {
901}899}
902900
903pub fn updateDeclLineNumber(self: *DebugSymbols, module: *Module, decl: *const Module.Decl) !void {901pub fn updateDeclLineNumber(self: *DebugSymbols, module: *Module, decl: *const Module.Decl) !void {
902 _ = module;
904 const tracy = trace(@src());903 const tracy = trace(@src());
905 defer tracy.end();904 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
912 const func = decl.val.castTag(.function).?.data;906 const func = decl.val.castTag(.function).?.data;
913 const line_off = @intCast(u28, decl.src_line + func.lbrace_line);907 const line_off = @intCast(u28, decl.src_line + func.lbrace_line);
914908
...@@ -933,6 +927,8 @@ pub fn initDeclDebugBuffers(...@@ -933,6 +927,8 @@ pub fn initDeclDebugBuffers(
933 module: *Module,927 module: *Module,
934 decl: *Module.Decl,928 decl: *Module.Decl,
935) !DeclDebugBuffers {929) !DeclDebugBuffers {
930 _ = self;
931 _ = module;
936 const tracy = trace(@src());932 const tracy = trace(@src());
937 defer tracy.end();933 defer tracy.end();
938934
...@@ -1195,6 +1191,7 @@ fn addDbgInfoType(...@@ -1195,6 +1191,7 @@ fn addDbgInfoType(
1195 dbg_info_buffer: *std.ArrayList(u8),1191 dbg_info_buffer: *std.ArrayList(u8),
1196 target: std.Target,1192 target: std.Target,
1197) !void {1193) !void {
1194 _ = self;
1198 switch (ty.zigTypeTag()) {1195 switch (ty.zigTypeTag()) {
1199 .Void => unreachable,1196 .Void => unreachable,
1200 .NoReturn => unreachable,1197 .NoReturn => unreachable,
...@@ -1371,6 +1368,7 @@ fn getRelocDbgInfoSubprogramHighPC() u32 {...@@ -1371,6 +1368,7 @@ fn getRelocDbgInfoSubprogramHighPC() u32 {
1371}1368}
13721369
1373fn dbgLineNeededHeaderBytes(self: DebugSymbols, module: *Module) u32 {1370fn dbgLineNeededHeaderBytes(self: DebugSymbols, module: *Module) u32 {
1371 _ = self;
1374 const directory_entry_format_count = 1;1372 const directory_entry_format_count = 1;
1375 const file_name_entry_format_count = 1;1373 const file_name_entry_format_count = 1;
1376 const directory_count = 1;1374 const directory_count = 1;
...@@ -1385,6 +1383,7 @@ fn dbgLineNeededHeaderBytes(self: DebugSymbols, module: *Module) u32 {...@@ -1385,6 +1383,7 @@ fn dbgLineNeededHeaderBytes(self: DebugSymbols, module: *Module) u32 {
1385}1383}
13861384
1387fn dbgInfoNeededHeaderBytes(self: DebugSymbols) u32 {1385fn dbgInfoNeededHeaderBytes(self: DebugSymbols) u32 {
1386 _ = self;
1388 return 120;1387 return 120;
1389}1388}
13901389
src/link/MachO/Object.zig-1
...@@ -478,7 +478,6 @@ pub fn parseDebugInfo(self: *Object) !void {...@@ -478,7 +478,6 @@ pub fn parseDebugInfo(self: *Object) !void {
478478
479 self.tu_path = try std.fs.path.join(self.allocator, &[_][]const u8{ comp_dir, name });479 self.tu_path = try std.fs.path.join(self.allocator, &[_][]const u8{ comp_dir, name });
480 self.tu_mtime = mtime: {480 self.tu_mtime = mtime: {
481 var buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
482 const stat = try self.file.?.stat();481 const stat = try self.file.?.stat();
483 break :mtime @intCast(u64, @divFloor(stat.mtime, 1_000_000_000));482 break :mtime @intCast(u64, @divFloor(stat.mtime, 1_000_000_000));
484 };483 };
src/link/MachO/Zld.zig+5-8
...@@ -108,6 +108,7 @@ const TlvOffset = struct {...@@ -108,6 +108,7 @@ const TlvOffset = struct {
108 offset: u64,108 offset: u64,
109109
110 fn cmp(context: void, a: TlvOffset, b: TlvOffset) bool {110 fn cmp(context: void, a: TlvOffset, b: TlvOffset) bool {
111 _ = context;
111 return a.source_addr < b.source_addr;112 return a.source_addr < b.source_addr;
112 }113 }
113};114};
...@@ -432,13 +433,12 @@ fn mapAndUpdateSections(...@@ -432,13 +433,12 @@ fn mapAndUpdateSections(
432433
433fn updateMetadata(self: *Zld) !void {434fn updateMetadata(self: *Zld) !void {
434 for (self.objects.items) |object| {435 for (self.objects.items) |object| {
435 const object_seg = object.load_commands.items[object.segment_cmd_index.?].Segment;
436 const text_seg = &self.load_commands.items[self.text_segment_cmd_index.?].Segment;436 const text_seg = &self.load_commands.items[self.text_segment_cmd_index.?].Segment;
437 const data_const_seg = &self.load_commands.items[self.data_const_segment_cmd_index.?].Segment;437 const data_const_seg = &self.load_commands.items[self.data_const_segment_cmd_index.?].Segment;
438 const data_seg = &self.load_commands.items[self.data_segment_cmd_index.?].Segment;438 const data_seg = &self.load_commands.items[self.data_segment_cmd_index.?].Segment;
439439
440 // Create missing metadata440 // Create missing metadata
441 for (object.sections.items) |sect, sect_id| {441 for (object.sections.items) |sect| {
442 const segname = sect.segname();442 const segname = sect.segname();
443 const sectname = sect.sectname();443 const sectname = sect.sectname();
444444
...@@ -1294,7 +1294,6 @@ fn allocateLinkeditSegment(self: *Zld) void {...@@ -1294,7 +1294,6 @@ fn allocateLinkeditSegment(self: *Zld) void {
1294}1294}
12951295
1296fn allocateSegment(self: *Zld, index: u16, offset: u64) !void {1296fn allocateSegment(self: *Zld, index: u16, offset: u64) !void {
1297 const base_vmaddr = self.load_commands.items[self.pagezero_segment_cmd_index.?].Segment.inner.vmsize;
1298 const seg = &self.load_commands.items[index].Segment;1297 const seg = &self.load_commands.items[index].Segment;
12991298
1300 // Allocate the sections according to their alignment at the beginning of the segment.1299 // Allocate the sections according to their alignment at the beginning of the segment.
...@@ -1375,7 +1374,7 @@ fn allocateTentativeSymbols(self: *Zld) !void {...@@ -1375,7 +1374,7 @@ fn allocateTentativeSymbols(self: *Zld) !void {
1375 }1374 }
13761375
1377 // Convert tentative definitions into regular symbols.1376 // Convert tentative definitions into regular symbols.
1378 for (self.tentatives.values()) |sym, i| {1377 for (self.tentatives.values()) |sym| {
1379 const tent = sym.cast(Symbol.Tentative) orelse unreachable;1378 const tent = sym.cast(Symbol.Tentative) orelse unreachable;
1380 const reg = try self.allocator.create(Symbol.Regular);1379 const reg = try self.allocator.create(Symbol.Regular);
1381 errdefer self.allocator.destroy(reg);1380 errdefer self.allocator.destroy(reg);
...@@ -1427,7 +1426,6 @@ fn writeStubHelperCommon(self: *Zld) !void {...@@ -1427,7 +1426,6 @@ fn writeStubHelperCommon(self: *Zld) !void {
1427 const got = &data_const_segment.sections.items[self.got_section_index.?];1426 const got = &data_const_segment.sections.items[self.got_section_index.?];
1428 const data_segment = &self.load_commands.items[self.data_segment_cmd_index.?].Segment;1427 const data_segment = &self.load_commands.items[self.data_segment_cmd_index.?].Segment;
1429 const data = &data_segment.sections.items[self.data_section_index.?];1428 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
1432 self.stub_helper_stubs_start_off = blk: {1430 self.stub_helper_stubs_start_off = blk: {
1433 switch (self.arch.?) {1431 switch (self.arch.?) {
...@@ -1761,7 +1759,7 @@ fn resolveSymbolsInObject(self: *Zld, object: *Object) !void {...@@ -1761,7 +1759,7 @@ fn resolveSymbolsInObject(self: *Zld, object: *Object) !void {
17611759
1762 t_sym.alias = sym;1760 t_sym.alias = sym;
1763 sym_ptr.* = sym;1761 sym_ptr.* = sym;
1764 } else if (sym.cast(Symbol.Unresolved)) |und| {1762 } else if (sym.cast(Symbol.Unresolved)) |_| {
1765 if (self.globals.get(sym.name)) |g_sym| {1763 if (self.globals.get(sym.name)) |g_sym| {
1766 sym.alias = g_sym;1764 sym.alias = g_sym;
1767 continue;1765 continue;
...@@ -2654,7 +2652,6 @@ fn setEntryPoint(self: *Zld) !void {...@@ -2654,7 +2652,6 @@ fn setEntryPoint(self: *Zld) !void {
2654 // TODO we should respect the -entry flag passed in by the user to set a custom2652 // TODO we should respect the -entry flag passed in by the user to set a custom
2655 // entrypoint. For now, assume default of `_main`.2653 // entrypoint. For now, assume default of `_main`.
2656 const seg = self.load_commands.items[self.text_segment_cmd_index.?].Segment;2654 const seg = self.load_commands.items[self.text_segment_cmd_index.?].Segment;
2657 const text = seg.sections.items[self.text_section_index.?];
2658 const sym = self.globals.get("_main") orelse return error.MissingMainEntrypoint;2655 const sym = self.globals.get("_main") orelse return error.MissingMainEntrypoint;
2659 const entry_sym = sym.cast(Symbol.Regular) orelse unreachable;2656 const entry_sym = sym.cast(Symbol.Regular) orelse unreachable;
2660 const ec = &self.load_commands.items[self.main_cmd_index.?].Main;2657 const ec = &self.load_commands.items[self.main_cmd_index.?].Main;
...@@ -2862,7 +2859,6 @@ fn populateLazyBindOffsetsInStubHelper(self: *Zld, buffer: []const u8) !void {...@@ -2862,7 +2859,6 @@ fn populateLazyBindOffsetsInStubHelper(self: *Zld, buffer: []const u8) !void {
2862 error.EndOfStream => break,2859 error.EndOfStream => break,
2863 else => return err,2860 else => return err,
2864 };2861 };
2865 const imm: u8 = inst & macho.BIND_IMMEDIATE_MASK;
2866 const opcode: u8 = inst & macho.BIND_OPCODE_MASK;2862 const opcode: u8 = inst & macho.BIND_OPCODE_MASK;
28672863
2868 switch (opcode) {2864 switch (opcode) {
...@@ -2959,6 +2955,7 @@ fn writeDebugInfo(self: *Zld) !void {...@@ -2959,6 +2955,7 @@ fn writeDebugInfo(self: *Zld) !void {
2959 for (self.objects.items) |object| {2955 for (self.objects.items) |object| {
2960 const tu_path = object.tu_path orelse continue;2956 const tu_path = object.tu_path orelse continue;
2961 const tu_mtime = object.tu_mtime orelse continue;2957 const tu_mtime = object.tu_mtime orelse continue;
2958 _ = tu_mtime;
2962 const dirname = std.fs.path.dirname(tu_path) orelse "./";2959 const dirname = std.fs.path.dirname(tu_path) orelse "./";
2963 // Current dir2960 // Current dir
2964 try stabs.append(.{2961 try stabs.append(.{
src/link/MachO/bind.zig+1
...@@ -10,6 +10,7 @@ pub const Pointer = struct {...@@ -10,6 +10,7 @@ pub const Pointer = struct {
10};10};
1111
12pub fn pointerCmp(context: void, a: Pointer, b: Pointer) bool {12pub fn pointerCmp(context: void, a: Pointer, b: Pointer) bool {
13 _ = context;
13 if (a.segment_id < b.segment_id) return true;14 if (a.segment_id < b.segment_id) return true;
14 if (a.segment_id == b.segment_id) {15 if (a.segment_id == b.segment_id) {
15 return a.offset < b.offset;16 return a.offset < b.offset;
src/link/MachO/reloc/x86_64.zig-1
...@@ -175,7 +175,6 @@ pub const Parser = struct {...@@ -175,7 +175,6 @@ pub const Parser = struct {
175175
176 const rel_type = @intToEnum(macho.reloc_type_x86_64, rel.r_type);176 const rel_type = @intToEnum(macho.reloc_type_x86_64, rel.r_type);
177 const target = Relocation.Target.from_reloc(rel, parser.symbols);177 const target = Relocation.Target.from_reloc(rel, parser.symbols);
178 const is_extern = rel.r_extern == 1;
179178
180 const offset = @intCast(u32, rel.r_address);179 const offset = @intCast(u32, rel.r_address);
181 const inst = parser.code[offset..][0..4];180 const inst = parser.code[offset..][0..4];
src/link/SpirV.zig+7-1
...@@ -102,6 +102,7 @@ pub fn deinit(self: *SpirV) void {...@@ -102,6 +102,7 @@ pub fn deinit(self: *SpirV) void {
102}102}
103103
104pub fn updateDecl(self: *SpirV, module: *Module, decl: *Module.Decl) !void {104pub fn updateDecl(self: *SpirV, module: *Module, decl: *Module.Decl) !void {
105 _ = module;
105 // Keep track of all decls so we can iterate over them on flush().106 // Keep track of all decls so we can iterate over them on flush().
106 _ = try self.decl_table.getOrPut(self.base.allocator, decl);107 _ = try self.decl_table.getOrPut(self.base.allocator, decl);
107}108}
...@@ -111,7 +112,12 @@ pub fn updateDeclExports(...@@ -111,7 +112,12 @@ pub fn updateDeclExports(
111 module: *Module,112 module: *Module,
112 decl: *const Module.Decl,113 decl: *const Module.Decl,
113 exports: []const *Module.Export,114 exports: []const *Module.Export,
114) !void {}115) !void {
116 _ = self;
117 _ = module;
118 _ = decl;
119 _ = exports;
120}
115121
116pub fn freeDecl(self: *SpirV, decl: *Module.Decl) void {122pub fn freeDecl(self: *SpirV, decl: *Module.Decl) void {
117 assert(self.decl_table.swapRemove(decl));123 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 {...@@ -216,7 +216,7 @@ pub fn updateDecl(self: *Wasm, module: *Module, decl: *Module.Decl) !void {
216 try module.failed_decls.put(module.gpa, decl, context.err_msg);216 try module.failed_decls.put(module.gpa, decl, context.err_msg);
217 return;217 return;
218 },218 },
219 else => |e| return err,219 else => |e| return e,
220 };220 };
221221
222 const code: []const u8 = switch (result) {222 const code: []const u8 = switch (result) {
...@@ -258,7 +258,12 @@ pub fn updateDeclExports(...@@ -258,7 +258,12 @@ pub fn updateDeclExports(
258 module: *Module,258 module: *Module,
259 decl: *const Module.Decl,259 decl: *const Module.Decl,
260 exports: []const *Module.Export,260 exports: []const *Module.Export,
261) !void {}261) !void {
262 _ = self;
263 _ = module;
264 _ = decl;
265 _ = exports;
266}
262267
263pub fn freeDecl(self: *Wasm, decl: *Module.Decl) void {268pub fn freeDecl(self: *Wasm, decl: *Module.Decl) void {
264 if (self.getFuncidx(decl)) |func_idx| {269 if (self.getFuncidx(decl)) |func_idx| {
...@@ -300,6 +305,7 @@ pub fn flush(self: *Wasm, comp: *Compilation) !void {...@@ -300,6 +305,7 @@ pub fn flush(self: *Wasm, comp: *Compilation) !void {
300}305}
301306
302pub fn flushModule(self: *Wasm, comp: *Compilation) !void {307pub fn flushModule(self: *Wasm, comp: *Compilation) !void {
308 _ = comp;
303 const tracy = trace(@src());309 const tracy = trace(@src());
304 defer tracy.end();310 defer tracy.end();
305311
...@@ -496,7 +502,6 @@ pub fn flushModule(self: *Wasm, comp: *Compilation) !void {...@@ -496,7 +502,6 @@ pub fn flushModule(self: *Wasm, comp: *Compilation) !void {
496 if (data_size != 0) {502 if (data_size != 0) {
497 const header_offset = try reserveVecSectionHeader(file);503 const header_offset = try reserveVecSectionHeader(file);
498 const writer = file.writer();504 const writer = file.writer();
499 var len: u32 = 0;
500 // index to memory section (currently, there can only be 1 memory section in wasm)505 // index to memory section (currently, there can only be 1 memory section in wasm)
501 try leb.writeULEB128(writer, @as(u32, 0));506 try leb.writeULEB128(writer, @as(u32, 0));
502507
...@@ -558,7 +563,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {...@@ -558,7 +563,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
558 .target = self.base.options.target,563 .target = self.base.options.target,
559 .output_mode = .Obj,564 .output_mode = .Obj,
560 });565 });
561 const o_directory = self.base.options.module.?.zig_cache_artifact_directory;566 const o_directory = module.zig_cache_artifact_directory;
562 const full_obj_path = try o_directory.join(arena, &[_][]const u8{obj_basename});567 const full_obj_path = try o_directory.join(arena, &[_][]const u8{obj_basename});
563 break :blk full_obj_path;568 break :blk full_obj_path;
564 }569 }
src/main.zig+2-2
...@@ -500,7 +500,7 @@ const Emit = union(enum) {...@@ -500,7 +500,7 @@ const Emit = union(enum) {
500};500};
501501
502fn optionalBoolEnvVar(arena: *Allocator, name: []const u8) !bool {502fn optionalBoolEnvVar(arena: *Allocator, name: []const u8) !bool {
503 if (std.process.getEnvVarOwned(arena, name)) |value| {503 if (std.process.getEnvVarOwned(arena, name)) |_| {
504 return true;504 return true;
505 } else |err| switch (err) {505 } else |err| switch (err) {
506 error.EnvironmentVariableNotFound => return false,506 error.EnvironmentVariableNotFound => return false,
...@@ -2565,6 +2565,7 @@ pub fn cmdInit(...@@ -2565,6 +2565,7 @@ pub fn cmdInit(
2565 args: []const []const u8,2565 args: []const []const u8,
2566 output_mode: std.builtin.OutputMode,2566 output_mode: std.builtin.OutputMode,
2567) !void {2567) !void {
2568 _ = gpa;
2568 {2569 {
2569 var i: usize = 0;2570 var i: usize = 0;
2570 while (i < args.len) : (i += 1) {2571 while (i < args.len) : (i += 1) {
...@@ -3749,7 +3750,6 @@ pub fn cmdAstCheck(...@@ -3749,7 +3750,6 @@ pub fn cmdAstCheck(
37493750
3750 var color: Color = .auto;3751 var color: Color = .auto;
3751 var want_output_text = false;3752 var want_output_text = false;
3752 var have_zig_source_file = false;
3753 var zig_source_file: ?[]const u8 = null;3753 var zig_source_file: ?[]const u8 = null;
37543754
3755 var i: usize = 0;3755 var i: usize = 0;
src/mingw.zig-2
...@@ -372,11 +372,9 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {...@@ -372,11 +372,9 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
372372
373 try child.spawn();373 try child.spawn();
374374
375 const stdout_reader = child.stdout.?.reader();
376 const stderr_reader = child.stderr.?.reader();375 const stderr_reader = child.stderr.?.reader();
377376
378 // TODO https://github.com/ziglang/zig/issues/6343377 // TODO https://github.com/ziglang/zig/issues/6343
379 const stdout = try stdout_reader.readAllAlloc(arena, std.math.maxInt(u32));
380 const stderr = try stderr_reader.readAllAlloc(arena, 10 * 1024 * 1024);378 const stderr = try stderr_reader.readAllAlloc(arena, 10 * 1024 * 1024);
381379
382 const term = child.wait() catch |err| {380 const term = child.wait() catch |err| {
src/musl.zig-1
...@@ -143,7 +143,6 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {...@@ -143,7 +143,6 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
143 const dirname = path.dirname(src_file).?;143 const dirname = path.dirname(src_file).?;
144 const basename = path.basename(src_file);144 const basename = path.basename(src_file);
145 const noextbasename = basename[0 .. basename.len - std.fs.path.extension(basename).len];145 const noextbasename = basename[0 .. basename.len - std.fs.path.extension(basename).len];
146 const before_arch_dir = path.dirname(dirname).?;
147 const dirbasename = path.basename(dirname);146 const dirbasename = path.basename(dirname);
148147
149 var is_arch_specific = false;148 var is_arch_specific = false;
src/print_env.zig+1
...@@ -5,6 +5,7 @@ const Allocator = std.mem.Allocator;...@@ -5,6 +5,7 @@ const Allocator = std.mem.Allocator;
5const fatal = @import("main.zig").fatal;5const fatal = @import("main.zig").fatal;
66
7pub fn cmdEnv(gpa: *Allocator, args: []const []const u8, stdout: std.fs.File.Writer) !void {7pub fn cmdEnv(gpa: *Allocator, args: []const []const u8, stdout: std.fs.File.Writer) !void {
8 _ = args;
8 const self_exe_path = try std.fs.selfExePathAlloc(gpa);9 const self_exe_path = try std.fs.selfExePathAlloc(gpa);
9 defer gpa.free(self_exe_path);10 defer gpa.free(self_exe_path);
1011
src/print_targets.zig+1
...@@ -17,6 +17,7 @@ pub fn cmdTargets(...@@ -17,6 +17,7 @@ pub fn cmdTargets(
17 stdout: anytype,17 stdout: anytype,
18 native_target: Target,18 native_target: Target,
19) !void {19) !void {
20 _ = args;
20 var zig_lib_directory = introspect.findZigLibDir(allocator) catch |err| {21 var zig_lib_directory = introspect.findZigLibDir(allocator) catch |err| {
21 fatal("unable to find zig installation directory: {s}\n", .{@errorName(err)});22 fatal("unable to find zig installation directory: {s}\n", .{@errorName(err)});
22 };23 };
src/register_manager.zig+2-12
...@@ -265,6 +265,8 @@ fn MockFunction(comptime Register: type) type {...@@ -265,6 +265,8 @@ fn MockFunction(comptime Register: type) type {
265 }265 }
266266
267 pub fn spillInstruction(self: *Self, src: LazySrcLoc, reg: Register, inst: *ir.Inst) !void {267 pub fn spillInstruction(self: *Self, src: LazySrcLoc, reg: Register, inst: *ir.Inst) !void {
268 _ = src;
269 _ = inst;
268 try self.spilled.append(self.allocator, reg);270 try self.spilled.append(self.allocator, reg);
269 }271 }
270 };272 };
...@@ -281,12 +283,6 @@ test "default state" {...@@ -281,12 +283,6 @@ test "default state" {
281 };283 };
282 defer function.deinit();284 defer function.deinit();
283285
284 var mock_instruction = ir.Inst{
285 .tag = .breakpoint,
286 .ty = Type.initTag(.void),
287 .src = .unneeded,
288 };
289
290 try expect(!function.register_manager.isRegAllocated(.r2));286 try expect(!function.register_manager.isRegAllocated(.r2));
291 try expect(!function.register_manager.isRegAllocated(.r3));287 try expect(!function.register_manager.isRegAllocated(.r3));
292 try expect(function.register_manager.isRegFree(.r2));288 try expect(function.register_manager.isRegFree(.r2));
...@@ -365,12 +361,6 @@ test "tryAllocRegs" {...@@ -365,12 +361,6 @@ test "tryAllocRegs" {
365 };361 };
366 defer function.deinit();362 defer function.deinit();
367363
368 var mock_instruction = ir.Inst{
369 .tag = .breakpoint,
370 .ty = Type.initTag(.void),
371 .src = .unneeded,
372 };
373
374 try expectEqual([_]MockRegister2{ .r0, .r1, .r2 }, function.register_manager.tryAllocRegs(3, .{ null, null, null }, &.{}).?);364 try expectEqual([_]MockRegister2{ .r0, .r1, .r2 }, function.register_manager.tryAllocRegs(3, .{ null, null, null }, &.{}).?);
375365
376 // Exceptions366 // Exceptions
src/stage1.zig+2
...@@ -407,6 +407,8 @@ export fn stage2_add_link_lib(...@@ -407,6 +407,8 @@ export fn stage2_add_link_lib(
407 symbol_name_ptr: [*c]const u8,407 symbol_name_ptr: [*c]const u8,
408 symbol_name_len: usize,408 symbol_name_len: usize,
409) ?[*:0]const u8 {409) ?[*:0]const u8 {
410 _ = symbol_name_len;
411 _ = symbol_name_ptr;
410 const comp = @intToPtr(*Compilation, stage1.userdata);412 const comp = @intToPtr(*Compilation, stage1.userdata);
411 const lib_name = std.ascii.allocLowerString(comp.gpa, lib_name_ptr[0..lib_name_len]) catch return "out of memory";413 const lib_name = std.ascii.allocLowerString(comp.gpa, lib_name_ptr[0..lib_name_len]) catch return "out of memory";
412 const target = comp.getTarget();414 const target = comp.getTarget();
src/test.zig+3
...@@ -70,6 +70,8 @@ const ErrorMsg = union(enum) {...@@ -70,6 +70,8 @@ const ErrorMsg = union(enum) {
70 options: std.fmt.FormatOptions,70 options: std.fmt.FormatOptions,
71 writer: anytype,71 writer: anytype,
72 ) !void {72 ) !void {
73 _ = fmt;
74 _ = options;
73 switch (self) {75 switch (self) {
74 .src => |src| {76 .src => |src| {
75 return writer.print("{s}:{d}:{d}: {s}: {s}", .{77 return writer.print("{s}:{d}:{d}: {s}: {s}", .{
...@@ -592,6 +594,7 @@ pub const TestContext = struct {...@@ -592,6 +594,7 @@ pub const TestContext = struct {
592 thread_pool: *ThreadPool,594 thread_pool: *ThreadPool,
593 global_cache_directory: Compilation.Directory,595 global_cache_directory: Compilation.Directory,
594 ) !void {596 ) !void {
597 _ = self;
595 const target_info = try std.zig.system.NativeTargetInfo.detect(allocator, case.target);598 const target_info = try std.zig.system.NativeTargetInfo.detect(allocator, case.target);
596 const target = target_info.target;599 const target = target_info.target;
597600
src/tracy.zig+3-1
...@@ -28,7 +28,9 @@ pub const ___tracy_c_zone_context = extern struct {...@@ -28,7 +28,9 @@ pub const ___tracy_c_zone_context = extern struct {
28};28};
2929
30pub const Ctx = if (enable) ___tracy_c_zone_context else struct {30pub 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 }
32};34};
3335
34pub inline fn trace(comptime src: std.builtin.SourceLocation) Ctx {36pub inline fn trace(comptime src: std.builtin.SourceLocation) Ctx {
src/translate_c.zig+15-9
...@@ -206,6 +206,7 @@ const Scope = struct {...@@ -206,6 +206,7 @@ const Scope = struct {
206 }206 }
207207
208 fn findBlockReturnType(inner: *Scope, c: *Context) clang.QualType {208 fn findBlockReturnType(inner: *Scope, c: *Context) clang.QualType {
209 _ = c;
209 var scope = inner;210 var scope = inner;
210 while (true) {211 while (true) {
211 switch (scope.id) {212 switch (scope.id) {
...@@ -601,7 +602,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void {...@@ -601,7 +602,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void {
601 var scope = &block_scope.base;602 var scope = &block_scope.base;
602603
603 var param_id: c_uint = 0;604 var param_id: c_uint = 0;
604 for (proto_node.data.params) |*param, i| {605 for (proto_node.data.params) |*param| {
605 const param_name = param.name orelse {606 const param_name = param.name orelse {
606 proto_node.data.is_extern = true;607 proto_node.data.is_extern = true;
607 proto_node.data.is_export = false;608 proto_node.data.is_export = false;
...@@ -785,7 +786,7 @@ const builtin_typedef_map = std.ComptimeStringMap([]const u8, .{...@@ -785,7 +786,7 @@ const builtin_typedef_map = std.ComptimeStringMap([]const u8, .{
785});786});
786787
787fn transTypeDef(c: *Context, scope: *Scope, typedef_decl: *const clang.TypedefNameDecl) Error!void {788fn 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()))) |_|
789 return; // Avoid processing this decl twice790 return; // Avoid processing this decl twice
790 const toplevel = scope.id == .root;791 const toplevel = scope.id == .root;
791 const bs: *Scope.Block = if (!toplevel) try scope.findBlockScope(c) else undefined;792 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...@@ -935,7 +936,7 @@ fn hasFlexibleArrayField(c: *Context, record_def: *const clang.RecordDecl) bool
935}936}
936937
937fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordDecl) Error!void {938fn 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()))) |_|
939 return; // Avoid processing this decl twice940 return; // Avoid processing this decl twice
940 const record_loc = record_decl.getLocation();941 const record_loc = record_decl.getLocation();
941 const toplevel = scope.id == .root;942 const toplevel = scope.id == .root;
...@@ -1080,7 +1081,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD...@@ -1080,7 +1081,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD
1080}1081}
10811082
1082fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: *const clang.EnumDecl) Error!void {1083fn 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()))) |_|
1084 return; // Avoid processing this decl twice1085 return; // Avoid processing this decl twice
1085 const enum_loc = enum_decl.getLocation();1086 const enum_loc = enum_decl.getLocation();
1086 const toplevel = scope.id == .root;1087 const toplevel = scope.id == .root;
...@@ -1312,6 +1313,7 @@ fn transConvertVectorExpr(...@@ -1312,6 +1313,7 @@ fn transConvertVectorExpr(
1312 source_loc: clang.SourceLocation,1313 source_loc: clang.SourceLocation,
1313 expr: *const clang.ConvertVectorExpr,1314 expr: *const clang.ConvertVectorExpr,
1314) TransError!Node {1315) TransError!Node {
1316 _ = source_loc;
1315 const base_stmt = @ptrCast(*const clang.Stmt, expr);1317 const base_stmt = @ptrCast(*const clang.Stmt, expr);
13161318
1317 var block_scope = try Scope.Block.init(c, scope, true);1319 var block_scope = try Scope.Block.init(c, scope, true);
...@@ -1321,7 +1323,6 @@ fn transConvertVectorExpr(...@@ -1321,7 +1323,6 @@ fn transConvertVectorExpr(
1321 const src_type = qualTypeCanon(src_expr.getType());1323 const src_type = qualTypeCanon(src_expr.getType());
1322 const src_vector_ty = @ptrCast(*const clang.VectorType, src_type);1324 const src_vector_ty = @ptrCast(*const clang.VectorType, src_type);
1323 const src_element_qt = src_vector_ty.getElementType();1325 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
1326 const src_expr_node = try transExpr(c, &block_scope.base, src_expr, .used);1327 const src_expr_node = try transExpr(c, &block_scope.base, src_expr, .used);
13271328
...@@ -1434,6 +1435,7 @@ fn transSimpleOffsetOfExpr(...@@ -1434,6 +1435,7 @@ fn transSimpleOffsetOfExpr(
1434 scope: *Scope,1435 scope: *Scope,
1435 expr: *const clang.OffsetOfExpr,1436 expr: *const clang.OffsetOfExpr,
1436) TransError!Node {1437) TransError!Node {
1438 _ = scope;
1437 assert(expr.getNumComponents() == 1);1439 assert(expr.getNumComponents() == 1);
1438 const component = expr.getComponent(0);1440 const component = expr.getComponent(0);
1439 if (component.getKind() == .Field) {1441 if (component.getKind() == .Field) {
...@@ -2270,6 +2272,7 @@ fn transStringLiteralInitializer(...@@ -2270,6 +2272,7 @@ fn transStringLiteralInitializer(
2270/// both operands resolve to addresses. The C standard requires that both operands2272/// both operands resolve to addresses. The C standard requires that both operands
2271/// point to elements of the same array object, but we do not verify that here.2273/// point to elements of the same array object, but we do not verify that here.
2272fn cIsPointerDiffExpr(c: *Context, stmt: *const clang.BinaryOperator) bool {2274fn cIsPointerDiffExpr(c: *Context, stmt: *const clang.BinaryOperator) bool {
2275 _ = c;
2273 const lhs = @ptrCast(*const clang.Stmt, stmt.getLHS());2276 const lhs = @ptrCast(*const clang.Stmt, stmt.getLHS());
2274 const rhs = @ptrCast(*const clang.Stmt, stmt.getRHS());2277 const rhs = @ptrCast(*const clang.Stmt, stmt.getRHS());
2275 return stmt.getOpcode() == .Sub and2278 return stmt.getOpcode() == .Sub and
...@@ -2573,6 +2576,7 @@ fn transInitListExprVector(...@@ -2573,6 +2576,7 @@ fn transInitListExprVector(
2573 expr: *const clang.InitListExpr,2576 expr: *const clang.InitListExpr,
2574 ty: *const clang.Type,2577 ty: *const clang.Type,
2575) TransError!Node {2578) TransError!Node {
2579 _ = ty;
2576 const qt = getExprQualType(c, @ptrCast(*const clang.Expr, expr));2580 const qt = getExprQualType(c, @ptrCast(*const clang.Expr, expr));
2577 const vector_type = try transQualType(c, scope, qt, loc);2581 const vector_type = try transQualType(c, scope, qt, loc);
2578 const init_count = expr.getNumInits();2582 const init_count = expr.getNumInits();
...@@ -2722,6 +2726,7 @@ fn transImplicitValueInitExpr(...@@ -2722,6 +2726,7 @@ fn transImplicitValueInitExpr(
2722 expr: *const clang.Expr,2726 expr: *const clang.Expr,
2723 used: ResultUsed,2727 used: ResultUsed,
2724) TransError!Node {2728) TransError!Node {
2729 _ = used;
2725 const source_loc = expr.getBeginLoc();2730 const source_loc = expr.getBeginLoc();
2726 const qt = getExprQualType(c, expr);2731 const qt = getExprQualType(c, expr);
2727 const ty = qt.getTypePtr();2732 const ty = qt.getTypePtr();
...@@ -3408,6 +3413,7 @@ fn transUnaryExprOrTypeTraitExpr(...@@ -3408,6 +3413,7 @@ fn transUnaryExprOrTypeTraitExpr(
3408 stmt: *const clang.UnaryExprOrTypeTraitExpr,3413 stmt: *const clang.UnaryExprOrTypeTraitExpr,
3409 result_used: ResultUsed,3414 result_used: ResultUsed,
3410) TransError!Node {3415) TransError!Node {
3416 _ = result_used;
3411 const loc = stmt.getBeginLoc();3417 const loc = stmt.getBeginLoc();
3412 const type_node = try transQualType(c, scope, stmt.getTypeOfArgument(), loc);3418 const type_node = try transQualType(c, scope, stmt.getTypeOfArgument(), loc);
34133419
...@@ -3802,7 +3808,6 @@ fn transBinaryConditionalOperator(c: *Context, scope: *Scope, stmt: *const clang...@@ -3802,7 +3808,6 @@ fn transBinaryConditionalOperator(c: *Context, scope: *Scope, stmt: *const clang
3802 const res_is_bool = qualTypeIsBoolean(qt);3808 const res_is_bool = qualTypeIsBoolean(qt);
3803 const casted_stmt = @ptrCast(*const clang.AbstractConditionalOperator, stmt);3809 const casted_stmt = @ptrCast(*const clang.AbstractConditionalOperator, stmt);
3804 const cond_expr = casted_stmt.getCond();3810 const cond_expr = casted_stmt.getCond();
3805 const true_expr = casted_stmt.getTrueExpr();
3806 const false_expr = casted_stmt.getFalseExpr();3811 const false_expr = casted_stmt.getFalseExpr();
38073812
3808 // c: (cond_expr)?:(false_expr)3813 // c: (cond_expr)?:(false_expr)
...@@ -3895,6 +3900,7 @@ fn maybeSuppressResult(...@@ -3895,6 +3900,7 @@ fn maybeSuppressResult(
3895 used: ResultUsed,3900 used: ResultUsed,
3896 result: Node,3901 result: Node,
3897) TransError!Node {3902) TransError!Node {
3903 _ = scope;
3898 if (used == .used) return result;3904 if (used == .used) return result;
3899 return Tag.discard.create(c.arena, result);3905 return Tag.discard.create(c.arena, result);
3900}3906}
...@@ -4336,12 +4342,10 @@ fn transCreateNodeNumber(c: *Context, num: anytype, num_kind: enum { int, float...@@ -4336,12 +4342,10 @@ fn transCreateNodeNumber(c: *Context, num: anytype, num_kind: enum { int, float
4336}4342}
43374343
4338fn transCreateNodeMacroFn(c: *Context, name: []const u8, ref: Node, proto_alias: *ast.Payload.Func) !Node {4344fn transCreateNodeMacroFn(c: *Context, name: []const u8, ref: Node, proto_alias: *ast.Payload.Func) !Node {
4339 const scope = &c.global_scope.base;
4340
4341 var fn_params = std.ArrayList(ast.Payload.Param).init(c.gpa);4345 var fn_params = std.ArrayList(ast.Payload.Param).init(c.gpa);
4342 defer fn_params.deinit();4346 defer fn_params.deinit();
43434347
4344 for (proto_alias.data.params) |param, i| {4348 for (proto_alias.data.params) |param| {
4345 const param_name = param.name orelse4349 const param_name = param.name orelse
4346 try std.fmt.allocPrint(c.arena, "arg_{d}", .{c.getMangle()});4350 try std.fmt.allocPrint(c.arena, "arg_{d}", .{c.getMangle()});
43474351
...@@ -5657,6 +5661,7 @@ fn parseCSpecifierQualifierList(c: *Context, m: *MacroCtx, scope: *Scope, allow_...@@ -5657,6 +5661,7 @@ fn parseCSpecifierQualifierList(c: *Context, m: *MacroCtx, scope: *Scope, allow_
5657}5661}
56585662
5659fn parseCNumericType(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node {5663fn parseCNumericType(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node {
5664 _ = scope;
5660 const KwCounter = struct {5665 const KwCounter = struct {
5661 double: u8 = 0,5666 double: u8 = 0,
5662 long: u8 = 0,5667 long: u8 = 0,
...@@ -5758,6 +5763,7 @@ fn parseCNumericType(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node {...@@ -5758,6 +5763,7 @@ fn parseCNumericType(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node {
5758}5763}
57595764
5760fn parseCAbstractDeclarator(c: *Context, m: *MacroCtx, scope: *Scope, node: Node) ParseError!Node {5765fn parseCAbstractDeclarator(c: *Context, m: *MacroCtx, scope: *Scope, node: Node) ParseError!Node {
5766 _ = scope;
5761 switch (m.next().?) {5767 switch (m.next().?) {
5762 .Asterisk => {5768 .Asterisk => {
5763 // last token of `node`5769 // last token of `node`
src/type.zig+4-2
...@@ -600,9 +600,11 @@ pub const Type = extern union {...@@ -600,9 +600,11 @@ pub const Type = extern union {
600600
601 pub const HashContext = struct {601 pub const HashContext = struct {
602 pub fn hash(self: @This(), t: Type) u64 {602 pub fn hash(self: @This(), t: Type) u64 {
603 _ = self;
603 return t.hash();604 return t.hash();
604 }605 }
605 pub fn eql(self: @This(), a: Type, b: Type) bool {606 pub fn eql(self: @This(), a: Type, b: Type) bool {
607 _ = self;
606 return a.eql(b);608 return a.eql(b);
607 }609 }
608 };610 };
...@@ -777,6 +779,7 @@ pub const Type = extern union {...@@ -777,6 +779,7 @@ pub const Type = extern union {
777 options: std.fmt.FormatOptions,779 options: std.fmt.FormatOptions,
778 writer: anytype,780 writer: anytype,
779 ) @TypeOf(writer).Error!void {781 ) @TypeOf(writer).Error!void {
782 _ = options;
780 comptime assert(fmt.len == 0);783 comptime assert(fmt.len == 0);
781 var ty = start_type;784 var ty = start_type;
782 while (true) {785 while (true) {
...@@ -3013,7 +3016,7 @@ pub const Type = extern union {...@@ -3013,7 +3016,7 @@ pub const Type = extern union {
3013 .base = .{ .tag = t },3016 .base = .{ .tag = t },
3014 .data = data,3017 .data = data,
3015 };3018 };
3016 return Type{ .ptr_otherwise = &ptr.base };3019 return file_struct.Type{ .ptr_otherwise = &ptr.base };
3017 }3020 }
30183021
3019 pub fn Data(comptime t: Tag) type {3022 pub fn Data(comptime t: Tag) type {
...@@ -3163,7 +3166,6 @@ pub const CType = enum {...@@ -3163,7 +3166,6 @@ pub const CType = enum {
3163 longdouble,3166 longdouble,
31643167
3165 pub fn sizeInBits(self: CType, target: Target) u16 {3168 pub fn sizeInBits(self: CType, target: Target) u16 {
3166 const arch = target.cpu.arch;
3167 switch (target.os.tag) {3169 switch (target.os.tag) {
3168 .freestanding, .other => switch (target.cpu.arch) {3170 .freestanding, .other => switch (target.cpu.arch) {
3169 .msp430 => switch (self) {3171 .msp430 => switch (self) {
src/value.zig+8
...@@ -626,6 +626,7 @@ pub const Value = extern union {...@@ -626,6 +626,7 @@ pub const Value = extern union {
626 return std.mem.dupe(allocator, u8, payload.data);626 return std.mem.dupe(allocator, u8, payload.data);
627 }627 }
628 if (self.castTag(.repeated)) |payload| {628 if (self.castTag(.repeated)) |payload| {
629 _ = payload;
629 @panic("TODO implement toAllocatedBytes for this Value tag");630 @panic("TODO implement toAllocatedBytes for this Value tag");
630 }631 }
631 if (self.castTag(.decl_ref)) |payload| {632 if (self.castTag(.decl_ref)) |payload| {
...@@ -747,6 +748,7 @@ pub const Value = extern union {...@@ -747,6 +748,7 @@ pub const Value = extern union {
747748
748 /// Asserts the type is an enum type.749 /// Asserts the type is an enum type.
749 pub fn toEnum(val: Value, enum_ty: Type, comptime E: type) E {750 pub fn toEnum(val: Value, enum_ty: Type, comptime E: type) E {
751 _ = enum_ty;
750 // TODO this needs to resolve other kinds of Value tags rather than752 // TODO this needs to resolve other kinds of Value tags rather than
751 // assuming the tag will be .enum_field_index.753 // assuming the tag will be .enum_field_index.
752 const field_index = val.castTag(.enum_field_index).?.data;754 const field_index = val.castTag(.enum_field_index).?.data;
...@@ -935,6 +937,7 @@ pub const Value = extern union {...@@ -935,6 +937,7 @@ pub const Value = extern union {
935 /// Converts an integer or a float to a float.937 /// Converts an integer or a float to a float.
936 /// Returns `error.Overflow` if the value does not fit in the new type.938 /// Returns `error.Overflow` if the value does not fit in the new type.
937 pub fn floatCast(self: Value, allocator: *Allocator, ty: Type, target: Target) !Value {939 pub fn floatCast(self: Value, allocator: *Allocator, ty: Type, target: Target) !Value {
940 _ = target;
938 switch (ty.tag()) {941 switch (ty.tag()) {
939 .f16 => {942 .f16 => {
940 @panic("TODO add __trunctfhf2 to compiler-rt");943 @panic("TODO add __trunctfhf2 to compiler-rt");
...@@ -1292,17 +1295,21 @@ pub const Value = extern union {...@@ -1292,17 +1295,21 @@ pub const Value = extern union {
12921295
1293 pub const ArrayHashContext = struct {1296 pub const ArrayHashContext = struct {
1294 pub fn hash(self: @This(), v: Value) u32 {1297 pub fn hash(self: @This(), v: Value) u32 {
1298 _ = self;
1295 return v.hash_u32();1299 return v.hash_u32();
1296 }1300 }
1297 pub fn eql(self: @This(), a: Value, b: Value) bool {1301 pub fn eql(self: @This(), a: Value, b: Value) bool {
1302 _ = self;
1298 return a.eql(b);1303 return a.eql(b);
1299 }1304 }
1300 };1305 };
1301 pub const HashContext = struct {1306 pub const HashContext = struct {
1302 pub fn hash(self: @This(), v: Value) u64 {1307 pub fn hash(self: @This(), v: Value) u64 {
1308 _ = self;
1303 return v.hash();1309 return v.hash();
1304 }1310 }
1305 pub fn eql(self: @This(), a: Value, b: Value) bool {1311 pub fn eql(self: @This(), a: Value, b: Value) bool {
1312 _ = self;
1306 return a.eql(b);1313 return a.eql(b);
1307 }1314 }
1308 };1315 };
...@@ -1345,6 +1352,7 @@ pub const Value = extern union {...@@ -1345,6 +1352,7 @@ pub const Value = extern union {
1345 }1352 }
13461353
1347 pub fn fieldValue(val: Value, allocator: *Allocator, index: usize) error{OutOfMemory}!Value {1354 pub fn fieldValue(val: Value, allocator: *Allocator, index: usize) error{OutOfMemory}!Value {
1355 _ = allocator;
1348 switch (val.tag()) {1356 switch (val.tag()) {
1349 .@"struct" => {1357 .@"struct" => {
1350 const field_values = val.castTag(.@"struct").?.data;1358 const field_values = val.castTag(.@"struct").?.data;
test/behavior/align.zig+1
...@@ -167,6 +167,7 @@ test "generic function with align param" {...@@ -167,6 +167,7 @@ test "generic function with align param" {
167}167}
168168
169fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {169fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {
170 _ = align_bytes;
170 return 0x1;171 return 0x1;
171}172}
172173
test/behavior/async_fn.zig+26
...@@ -13,6 +13,7 @@ test "simple coroutine suspend and resume" {...@@ -13,6 +13,7 @@ test "simple coroutine suspend and resume" {
13 resume frame;13 resume frame;
14 try expect(global_x == 3);14 try expect(global_x == 3);
15 const af: anyframe->void = &frame;15 const af: anyframe->void = &frame;
16 _ = af;
16 resume frame;17 resume frame;
17 try expect(global_x == 4);18 try expect(global_x == 4);
18}19}
...@@ -45,6 +46,7 @@ test "suspend at end of function" {...@@ -45,6 +46,7 @@ test "suspend at end of function" {
45 fn doTheTest() !void {46 fn doTheTest() !void {
46 try expect(x == 1);47 try expect(x == 1);
47 const p = async suspendAtEnd();48 const p = async suspendAtEnd();
49 _ = p;
48 try expect(x == 2);50 try expect(x == 2);
49 }51 }
5052
...@@ -131,7 +133,9 @@ test "@frameSize" {...@@ -131,7 +133,9 @@ test "@frameSize" {
131 other(1);133 other(1);
132 }134 }
133 fn other(param: i32) void {135 fn other(param: i32) void {
136 _ = param;
134 var local: i32 = undefined;137 var local: i32 = undefined;
138 _ = local;
135 suspend {}139 suspend {}
136 }140 }
137 };141 };
...@@ -181,6 +185,7 @@ test "coroutine suspend, resume" {...@@ -181,6 +185,7 @@ test "coroutine suspend, resume" {
181185
182test "coroutine suspend with block" {186test "coroutine suspend with block" {
183 const p = async testSuspendBlock();187 const p = async testSuspendBlock();
188 _ = p;
184 try expect(!global_result);189 try expect(!global_result);
185 resume a_promise;190 resume a_promise;
186 try expect(global_result);191 try expect(global_result);
...@@ -207,6 +212,7 @@ var await_final_result: i32 = 0;...@@ -207,6 +212,7 @@ var await_final_result: i32 = 0;
207test "coroutine await" {212test "coroutine await" {
208 await_seq('a');213 await_seq('a');
209 var p = async await_amain();214 var p = async await_amain();
215 _ = p;
210 await_seq('f');216 await_seq('f');
211 resume await_a_promise;217 resume await_a_promise;
212 await_seq('i');218 await_seq('i');
...@@ -243,6 +249,7 @@ var early_final_result: i32 = 0;...@@ -243,6 +249,7 @@ var early_final_result: i32 = 0;
243test "coroutine await early return" {249test "coroutine await early return" {
244 early_seq('a');250 early_seq('a');
245 var p = async early_amain();251 var p = async early_amain();
252 _ = p;
246 early_seq('f');253 early_seq('f');
247 try expect(early_final_result == 1234);254 try expect(early_final_result == 1234);
248 try expect(std.mem.eql(u8, &early_points, "abcdef"));255 try expect(std.mem.eql(u8, &early_points, "abcdef"));
...@@ -276,6 +283,7 @@ test "async function with dot syntax" {...@@ -276,6 +283,7 @@ test "async function with dot syntax" {
276 }283 }
277 };284 };
278 const p = async S.foo();285 const p = async S.foo();
286 _ = p;
279 try expect(S.y == 2);287 try expect(S.y == 2);
280}288}
281289
...@@ -362,11 +370,13 @@ test "error return trace across suspend points - early return" {...@@ -362,11 +370,13 @@ test "error return trace across suspend points - early return" {
362 const p = nonFailing();370 const p = nonFailing();
363 resume p;371 resume p;
364 const p2 = async printTrace(p);372 const p2 = async printTrace(p);
373 _ = p2;
365}374}
366375
367test "error return trace across suspend points - async return" {376test "error return trace across suspend points - async return" {
368 const p = nonFailing();377 const p = nonFailing();
369 const p2 = async printTrace(p);378 const p2 = async printTrace(p);
379 _ = p2;
370 resume p;380 resume p;
371}381}
372382
...@@ -396,6 +406,7 @@ fn printTrace(p: anyframe->(anyerror!void)) callconv(.Async) void {...@@ -396,6 +406,7 @@ fn printTrace(p: anyframe->(anyerror!void)) callconv(.Async) void {
396test "break from suspend" {406test "break from suspend" {
397 var my_result: i32 = 1;407 var my_result: i32 = 1;
398 const p = async testBreakFromSuspend(&my_result);408 const p = async testBreakFromSuspend(&my_result);
409 _ = p;
399 try std.testing.expect(my_result == 2);410 try std.testing.expect(my_result == 2);
400}411}
401fn testBreakFromSuspend(my_result: *i32) callconv(.Async) void {412fn testBreakFromSuspend(my_result: *i32) callconv(.Async) void {
...@@ -619,11 +630,14 @@ test "returning a const error from async function" {...@@ -619,11 +630,14 @@ test "returning a const error from async function" {
619 fn amain() !void {630 fn amain() !void {
620 var download_frame = async fetchUrl(10, "a string");631 var download_frame = async fetchUrl(10, "a string");
621 const download_text = try await download_frame;632 const download_text = try await download_frame;
633 _ = download_text;
622634
623 @panic("should not get here");635 @panic("should not get here");
624 }636 }
625637
626 fn fetchUrl(unused: i32, url: []const u8) ![]u8 {638 fn fetchUrl(unused: i32, url: []const u8) ![]u8 {
639 _ = unused;
640 _ = url;
627 frame = @frame();641 frame = @frame();
628 suspend {}642 suspend {}
629 ok = true;643 ok = true;
...@@ -700,6 +714,7 @@ fn testAsyncAwaitTypicalUsage(...@@ -700,6 +714,7 @@ fn testAsyncAwaitTypicalUsage(
700714
701 var global_download_frame: anyframe = undefined;715 var global_download_frame: anyframe = undefined;
702 fn fetchUrl(allocator: *std.mem.Allocator, url: []const u8) anyerror![]u8 {716 fn fetchUrl(allocator: *std.mem.Allocator, url: []const u8) anyerror![]u8 {
717 _ = url;
703 const result = try std.mem.dupe(allocator, u8, "expected download text");718 const result = try std.mem.dupe(allocator, u8, "expected download text");
704 errdefer allocator.free(result);719 errdefer allocator.free(result);
705 if (suspend_download) {720 if (suspend_download) {
...@@ -713,6 +728,7 @@ fn testAsyncAwaitTypicalUsage(...@@ -713,6 +728,7 @@ fn testAsyncAwaitTypicalUsage(
713728
714 var global_file_frame: anyframe = undefined;729 var global_file_frame: anyframe = undefined;
715 fn readFile(allocator: *std.mem.Allocator, filename: []const u8) anyerror![]u8 {730 fn readFile(allocator: *std.mem.Allocator, filename: []const u8) anyerror![]u8 {
731 _ = filename;
716 const result = try std.mem.dupe(allocator, u8, "expected file text");732 const result = try std.mem.dupe(allocator, u8, "expected file text");
717 errdefer allocator.free(result);733 errdefer allocator.free(result);
718 if (suspend_file) {734 if (suspend_file) {
...@@ -730,6 +746,7 @@ test "alignment of local variables in async functions" {...@@ -730,6 +746,7 @@ test "alignment of local variables in async functions" {
730 const S = struct {746 const S = struct {
731 fn doTheTest() !void {747 fn doTheTest() !void {
732 var y: u8 = 123;748 var y: u8 = 123;
749 _ = y;
733 var x: u8 align(128) = 1;750 var x: u8 align(128) = 1;
734 try expect(@ptrToInt(&x) % 128 == 0);751 try expect(@ptrToInt(&x) % 128 == 0);
735 }752 }
...@@ -742,6 +759,7 @@ test "no reason to resolve frame still works" {...@@ -742,6 +759,7 @@ test "no reason to resolve frame still works" {
742}759}
743fn simpleNothing() void {760fn simpleNothing() void {
744 var x: i32 = 1234;761 var x: i32 = 1234;
762 _ = x;
745}763}
746764
747test "async call a generic function" {765test "async call a generic function" {
...@@ -802,6 +820,7 @@ test "struct parameter to async function is copied to the frame" {...@@ -802,6 +820,7 @@ test "struct parameter to async function is copied to the frame" {
802 if (x == 0) return;820 if (x == 0) return;
803 clobberStack(x - 1);821 clobberStack(x - 1);
804 var y: i32 = x;822 var y: i32 = x;
823 _ = y;
805 }824 }
806825
807 fn bar(f: *@Frame(foo)) void {826 fn bar(f: *@Frame(foo)) void {
...@@ -1212,6 +1231,7 @@ test "suspend in while loop" {...@@ -1212,6 +1231,7 @@ test "suspend in while loop" {
1212 suspend {}1231 suspend {}
1213 return val;1232 return val;
1214 } else |err| {1233 } else |err| {
1234 err catch {};
1215 return 0;1235 return 0;
1216 }1236 }
1217 }1237 }
...@@ -1341,6 +1361,7 @@ test "async function passed 0-bit arg after non-0-bit arg" {...@@ -1341,6 +1361,7 @@ test "async function passed 0-bit arg after non-0-bit arg" {
1341 }1361 }
13421362
1343 fn bar(x: i32, args: anytype) anyerror!void {1363 fn bar(x: i32, args: anytype) anyerror!void {
1364 _ = args;
1344 global_frame = @frame();1365 global_frame = @frame();
1345 suspend {}1366 suspend {}
1346 global_int = x;1367 global_int = x;
...@@ -1636,6 +1657,8 @@ test "@asyncCall with pass-by-value arguments" {...@@ -1636,6 +1657,8 @@ test "@asyncCall with pass-by-value arguments" {
1636 pub const AT = [5]u8;1657 pub const AT = [5]u8;
16371658
1638 pub fn f(_fill0: u64, s: ST, _fill1: u64, a: AT, _fill2: u64) callconv(.Async) void {1659 pub fn f(_fill0: u64, s: ST, _fill1: u64, a: AT, _fill2: u64) callconv(.Async) void {
1660 _ = s;
1661 _ = a;
1639 // Check that the array and struct arguments passed by value don't1662 // Check that the array and struct arguments passed by value don't
1640 // end up overflowing the adjacent fields in the frame structure.1663 // end up overflowing the adjacent fields in the frame structure.
1641 expectEqual(F0, _fill0) catch @panic("test failure");1664 expectEqual(F0, _fill0) catch @panic("test failure");
...@@ -1654,6 +1677,7 @@ test "@asyncCall with pass-by-value arguments" {...@@ -1654,6 +1677,7 @@ test "@asyncCall with pass-by-value arguments" {
1654 [_]u8{ 1, 2, 3, 4, 5 },1677 [_]u8{ 1, 2, 3, 4, 5 },
1655 F2,1678 F2,
1656 });1679 });
1680 _ = frame_ptr;
1657}1681}
16581682
1659test "@asyncCall with arguments having non-standard alignment" {1683test "@asyncCall with arguments having non-standard alignment" {
...@@ -1662,6 +1686,7 @@ test "@asyncCall with arguments having non-standard alignment" {...@@ -1662,6 +1686,7 @@ test "@asyncCall with arguments having non-standard alignment" {
16621686
1663 const S = struct {1687 const S = struct {
1664 pub fn f(_fill0: u32, s: struct { x: u64 align(16) }, _fill1: u64) callconv(.Async) void {1688 pub fn f(_fill0: u32, s: struct { x: u64 align(16) }, _fill1: u64) callconv(.Async) void {
1689 _ = s;
1665 // The compiler inserts extra alignment for s, check that the1690 // The compiler inserts extra alignment for s, check that the
1666 // generated code picks the right slot for fill1.1691 // generated code picks the right slot for fill1.
1667 expectEqual(F0, _fill0) catch @panic("test failure");1692 expectEqual(F0, _fill0) catch @panic("test failure");
...@@ -1673,4 +1698,5 @@ test "@asyncCall with arguments having non-standard alignment" {...@@ -1673,4 +1698,5 @@ test "@asyncCall with arguments having non-standard alignment" {
1673 // The function pointer must not be comptime-known.1698 // The function pointer must not be comptime-known.
1674 var t = S.f;1699 var t = S.f;
1675 var frame_ptr = @asyncCall(&buffer, {}, t, .{ F0, undefined, F1 });1700 var frame_ptr = @asyncCall(&buffer, {}, t, .{ F0, undefined, F1 });
1701 _ = frame_ptr;
1676}1702}
test/behavior/atomics.zig-2
...@@ -97,7 +97,6 @@ test "cmpxchg with ptr" {...@@ -97,7 +97,6 @@ test "cmpxchg with ptr" {
9797
98test "cmpxchg with ignored result" {98test "cmpxchg with ignored result" {
99 var x: i32 = 1234;99 var x: i32 = 1234;
100 var ptr = &x;
101100
102 _ = @cmpxchgStrong(i32, &x, 1234, 5678, .Monotonic, .Monotonic);101 _ = @cmpxchgStrong(i32, &x, 1234, 5678, .Monotonic, .Monotonic);
103102
...@@ -195,7 +194,6 @@ fn testAtomicRmwInt() !void {...@@ -195,7 +194,6 @@ fn testAtomicRmwInt() !void {
195test "atomics with different types" {194test "atomics with different types" {
196 try testAtomicsWithType(bool, true, false);195 try testAtomicsWithType(bool, true, false);
197 inline for (.{ u1, i4, u5, i15, u24 }) |T| {196 inline for (.{ u1, i4, u5, i15, u24 }) |T| {
198 var x: T = 0;
199 try testAtomicsWithType(T, 0, 1);197 try testAtomicsWithType(T, 0, 1);
200 }198 }
201 try testAtomicsWithType(u0, 0, 0);199 try testAtomicsWithType(u0, 0, 0);
test/behavior/await_struct.zig+1
...@@ -12,6 +12,7 @@ var await_final_result = Foo{ .x = 0 };...@@ -12,6 +12,7 @@ var await_final_result = Foo{ .x = 0 };
12test "coroutine await struct" {12test "coroutine await struct" {
13 await_seq('a');13 await_seq('a');
14 var p = async await_amain();14 var p = async await_amain();
15 _ = p;
15 await_seq('f');16 await_seq('f');
16 resume await_a_promise;17 resume await_a_promise;
17 await_seq('i');18 await_seq('i');
test/behavior/bit_shifting.zig+1-1
...@@ -100,5 +100,5 @@ test "comptime shr of BigInt" {...@@ -100,5 +100,5 @@ test "comptime shr of BigInt" {
100}100}
101101
102test "comptime shift safety check" {102test "comptime shift safety check" {
103 const x = @as(usize, 42) << @sizeOf(usize);103 _ = @as(usize, 42) << @sizeOf(usize);
104}104}
test/behavior/bugs/1310.zig+2
...@@ -16,6 +16,8 @@ pub const InvocationTable_ = struct_InvocationTable_;...@@ -16,6 +16,8 @@ pub const InvocationTable_ = struct_InvocationTable_;
16pub const VM_ = struct_VM_;16pub const VM_ = struct_VM_;
1717
18fn agent_callback(_vm: [*]VM, options: [*]u8) callconv(.C) i32 {18fn agent_callback(_vm: [*]VM, options: [*]u8) callconv(.C) i32 {
19 _ = _vm;
20 _ = options;
19 return 11;21 return 11;
20}22}
2123
test/behavior/bugs/1467.zig+1
...@@ -4,4 +4,5 @@ pub const S = extern struct {...@@ -4,4 +4,5 @@ pub const S = extern struct {
4};4};
5test "bug 1467" {5test "bug 1467" {
6 const s: S = undefined;6 const s: S = undefined;
7 _ = s;
7}8}
test/behavior/bugs/1500.zig+4
...@@ -7,4 +7,8 @@ const B = fn (A) void;...@@ -7,4 +7,8 @@ const B = fn (A) void;
7test "allow these dependencies" {7test "allow these dependencies" {
8 var a: A = undefined;8 var a: A = undefined;
9 var b: B = undefined;9 var b: B = undefined;
10 if (false) {
11 a;
12 b;
13 }
10}14}
test/behavior/bugs/2346.zig+2
...@@ -1,6 +1,8 @@...@@ -1,6 +1,8 @@
1test "fixed" {1test "fixed" {
2 const a: *void = undefined;2 const a: *void = undefined;
3 const b: *[1]void = a;3 const b: *[1]void = a;
4 _ = b;
4 const c: *[0]u8 = undefined;5 const c: *[0]u8 = undefined;
5 const d: []u8 = c;6 const d: []u8 = c;
7 _ = d;
6}8}
test/behavior/bugs/2578.zig+3-1
...@@ -5,7 +5,9 @@ const Foo = struct {...@@ -5,7 +5,9 @@ const Foo = struct {
5var foo: Foo = undefined;5var foo: Foo = undefined;
6const t = &foo;6const t = &foo;
77
8fn bar(pointer: ?*c_void) void {}8fn bar(pointer: ?*c_void) void {
9 _ = pointer;
10}
911
10test "fixed" {12test "fixed" {
11 bar(t);13 bar(t);
test/behavior/bugs/2692.zig+3-1
...@@ -1,4 +1,6 @@...@@ -1,4 +1,6 @@
1fn foo(a: []u8) void {}1fn foo(a: []u8) void {
2 _ = a;
3}
24
3test "address of 0 length array" {5test "address of 0 length array" {
4 var pt: [0]u8 = undefined;6 var pt: [0]u8 = undefined;
test/behavior/bugs/3367.zig+3-1
...@@ -3,7 +3,9 @@ const Foo = struct {...@@ -3,7 +3,9 @@ const Foo = struct {
3};3};
44
5const Mixin = struct {5const Mixin = struct {
6 pub fn two(self: Foo) void {}6 pub fn two(self: Foo) void {
7 _ = self;
8 }
7};9};
810
9test "container member access usingnamespace decls" {11test "container member access usingnamespace decls" {
test/behavior/bugs/3586.zig+1
...@@ -8,4 +8,5 @@ test "fixed" {...@@ -8,4 +8,5 @@ test "fixed" {
8 var ctr = Container{8 var ctr = Container{
9 .params = NoteParams{},9 .params = NoteParams{},
10 };10 };
11 _ = ctr;
11}12}
test/behavior/bugs/4328.zig+2
...@@ -53,10 +53,12 @@ test "Peer resolution of extern function calls in @TypeOf" {...@@ -53,10 +53,12 @@ test "Peer resolution of extern function calls in @TypeOf" {
53test "Extern function calls, dereferences and field access in @TypeOf" {53test "Extern function calls, dereferences and field access in @TypeOf" {
54 const Test = struct {54 const Test = struct {
55 fn test_fn_1(a: c_long) @TypeOf(fopen("test", "r").*) {55 fn test_fn_1(a: c_long) @TypeOf(fopen("test", "r").*) {
56 _ = a;
56 return .{ .dummy_field = 0 };57 return .{ .dummy_field = 0 };
57 }58 }
5859
59 fn test_fn_2(a: anytype) @TypeOf(fopen("test", "r").*.dummy_field) {60 fn test_fn_2(a: anytype) @TypeOf(fopen("test", "r").*.dummy_field) {
61 _ = a;
60 return 255;62 return 255;
61 }63 }
6264
test/behavior/bugs/4560.zig+4
...@@ -25,6 +25,10 @@ pub fn StringHashMap(comptime V: type) type {...@@ -25,6 +25,10 @@ pub fn StringHashMap(comptime V: type) type {
25}25}
2626
27pub fn HashMap(comptime K: type, comptime V: type) type {27pub fn HashMap(comptime K: type, comptime V: type) type {
28 if (false) {
29 K;
30 V;
31 }
28 return struct {32 return struct {
29 size: usize,33 size: usize,
30 max_distance_from_start_index: usize,34 max_distance_from_start_index: usize,
test/behavior/bugs/4954.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1fn f(buf: []u8) void {1fn f(buf: []u8) void {
2 var ptr = &buf[@sizeOf(u32)];2 _ = &buf[@sizeOf(u32)];
3}3}
44
5test "crash" {5test "crash" {
test/behavior/bugs/529_other_file_2.zig+3-1
...@@ -1,4 +1,6 @@...@@ -1,4 +1,6 @@
1pub const A = extern struct {1pub const A = extern struct {
2 field: c_int,2 field: c_int,
3};3};
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 @@...@@ -1,6 +1,7 @@
1const io = @import("std").io;1const io = @import("std").io;
22
3pub fn write(_: void, bytes: []const u8) !usize {3pub fn write(_: void, bytes: []const u8) !usize {
4 _ = bytes;
4 return 0;5 return 0;
5}6}
6pub fn writer() io.Writer(void, @typeInfo(@typeInfo(@TypeOf(write)).Fn.return_type.?).ErrorUnion.error_set, write) {7pub 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 {...@@ -12,6 +12,7 @@ const ListenerContext = struct {
12const ContextAllocator = MemoryPool(TestContext);12const ContextAllocator = MemoryPool(TestContext);
1313
14fn MemoryPool(comptime T: type) type {14fn MemoryPool(comptime T: type) type {
15 _ = T;
15 return struct {16 return struct {
16 n: usize,17 n: usize,
17 };18 };
test/behavior/bugs/679.zig+1
...@@ -2,6 +2,7 @@ const std = @import("std");...@@ -2,6 +2,7 @@ const std = @import("std");
2const expect = std.testing.expect;2const expect = std.testing.expect;
33
4pub fn List(comptime T: type) type {4pub fn List(comptime T: type) type {
5 _ = T;
5 return u32;6 return u32;
6}7}
78
test/behavior/bugs/7003.zig+1
...@@ -5,4 +5,5 @@ test "@Type should resolve its children types" {...@@ -5,4 +5,5 @@ test "@Type should resolve its children types" {
5 comptime var sparse_info = @typeInfo(anyerror!sparse);5 comptime var sparse_info = @typeInfo(anyerror!sparse);
6 sparse_info.ErrorUnion.payload = dense;6 sparse_info.ErrorUnion.payload = dense;
7 const B = @Type(sparse_info);7 const B = @Type(sparse_info);
8 _ = B;
8}9}
test/behavior/bugs/7027.zig+3-1
...@@ -9,7 +9,9 @@ const Foobar = struct {...@@ -9,7 +9,9 @@ const Foobar = struct {
9 }9 }
10};10};
1111
12fn foo(arg: anytype) void {}12fn foo(arg: anytype) void {
13 _ = arg;
14}
1315
14test "" {16test "" {
15 comptime var foobar = Foobar.foo();17 comptime var foobar = Foobar.foo();
test/behavior/bugs/704.zig+3-1
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1const xxx = struct {1const xxx = struct {
2 pub fn bar(self: *xxx) void {}2 pub fn bar(self: *xxx) void {
3 _ = self;
4 }
3};5};
4test "bug 704" {6test "bug 704" {
5 var x: xxx = undefined;7 var x: xxx = undefined;
test/behavior/bugs/7250.zig+3-1
...@@ -3,7 +3,9 @@ const nrfx_uart_t = extern struct {...@@ -3,7 +3,9 @@ const nrfx_uart_t = extern struct {
3 drv_inst_idx: u8,3 drv_inst_idx: u8,
4};4};
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
8threadlocal var g_uart0 = nrfx_uart_t{10threadlocal var g_uart0 = nrfx_uart_t{
9 .p_reg = 0,11 .p_reg = 0,
test/behavior/bugs/828.zig+6
...@@ -4,6 +4,7 @@ const CountBy = struct {...@@ -4,6 +4,7 @@ const CountBy = struct {
4 const One = CountBy{ .a = 1 };4 const One = CountBy{ .a = 1 };
55
6 pub fn counter(self: *const CountBy) Counter {6 pub fn counter(self: *const CountBy) Counter {
7 _ = self;
7 return Counter{ .i = 0 };8 return Counter{ .i = 0 };
8 }9 }
9};10};
...@@ -18,6 +19,7 @@ const Counter = struct {...@@ -18,6 +19,7 @@ const Counter = struct {
18};19};
1920
20fn constCount(comptime cb: *const CountBy, comptime unused: u32) void {21fn constCount(comptime cb: *const CountBy, comptime unused: u32) void {
22 _ = unused;
21 comptime {23 comptime {
22 var cnt = cb.counter();24 var cnt = cb.counter();
23 if (cnt.i != 0) @compileError("Counter instance reused!");25 if (cnt.i != 0) @compileError("Counter instance reused!");
...@@ -30,4 +32,8 @@ test "comptime struct return should not return the same instance" {...@@ -30,4 +32,8 @@ test "comptime struct return should not return the same instance" {
30 //a second parameter is required to trigger the bug32 //a second parameter is required to trigger the bug
31 const ValA = constCount(&CountBy.One, 12);33 const ValA = constCount(&CountBy.One, 12);
32 const ValB = constCount(&CountBy.One, 15);34 const ValB = constCount(&CountBy.One, 15);
35 if (false) {
36 ValA;
37 ValB;
38 }
33}39}
test/behavior/bugs/920.zig+2
...@@ -46,6 +46,8 @@ fn norm_f_inv(y: f64) f64 {...@@ -46,6 +46,8 @@ fn norm_f_inv(y: f64) f64 {
46 return math.sqrt(-2.0 * math.ln(y));46 return math.sqrt(-2.0 * math.ln(y));
47}47}
48fn norm_zero_case(random: *Random, u: f64) f64 {48fn norm_zero_case(random: *Random, u: f64) f64 {
49 _ = random;
50 _ = u;
49 return 0.0;51 return 0.0;
50}52}
5153
test/behavior/cast.zig+9-2
...@@ -102,6 +102,7 @@ fn castToOptionalTypeError(z: i32) !void {...@@ -102,6 +102,7 @@ fn castToOptionalTypeError(z: i32) !void {
102102
103 const f = z;103 const f = z;
104 const g: anyerror!?i32 = f;104 const g: anyerror!?i32 = f;
105 _ = g catch {};
105106
106 const a = A{ .a = z };107 const a = A{ .a = z };
107 const b: anyerror!?A = a;108 const b: anyerror!?A = a;
...@@ -114,7 +115,9 @@ test "implicitly cast from int to anyerror!?T" {...@@ -114,7 +115,9 @@ test "implicitly cast from int to anyerror!?T" {
114}115}
115fn implicitIntLitToOptional() void {116fn implicitIntLitToOptional() void {
116 const f: ?i32 = 1;117 const f: ?i32 = 1;
118 _ = f;
117 const g: anyerror!?i32 = 1;119 const g: anyerror!?i32 = 1;
120 _ = g catch {};
118}121}
119122
120test "return null from fn() anyerror!?&T" {123test "return null from fn() anyerror!?&T" {
...@@ -821,9 +824,13 @@ test "variable initialization uses result locations properly with regards to the...@@ -821,9 +824,13 @@ test "variable initialization uses result locations properly with regards to the
821test "cast between [*c]T and ?[*:0]T on fn parameter" {824test "cast between [*c]T and ?[*:0]T on fn parameter" {
822 const S = struct {825 const S = struct {
823 const Handler = ?fn ([*c]const u8) callconv(.C) void;826 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
828 fn doTheTest() void {835 fn doTheTest() void {
829 addCallback(myCallback);836 addCallback(myCallback);
test/behavior/enum.zig+2
...@@ -111,6 +111,8 @@ test "enum type" {...@@ -111,6 +111,8 @@ test "enum type" {
111 .y = 5678,111 .y = 5678,
112 },112 },
113 };113 };
114 try expect(foo1.One == 13);
115 try expect(foo2.Two.x == 1234 and foo2.Two.y == 5678);
114 const bar = Bar.B;116 const bar = Bar.B;
115117
116 try expect(bar == Bar.B);118 try expect(bar == Bar.B);
test/behavior/error.zig+13-3
...@@ -103,6 +103,7 @@ fn testErrorSetType() !void {...@@ -103,6 +103,7 @@ fn testErrorSetType() !void {
103103
104 const a: MyErrSet!i32 = 5678;104 const a: MyErrSet!i32 = 5678;
105 const b: MyErrSet!i32 = MyErrSet.OutOfMemory;105 const b: MyErrSet!i32 = MyErrSet.OutOfMemory;
106 try expect(b catch error.OutOfMemory == error.OutOfMemory);
106107
107 if (a) |value| try expect(value == 5678) else |err| switch (err) {108 if (a) |value| try expect(value == 5678) else |err| switch (err) {
108 error.OutOfMemory => unreachable,109 error.OutOfMemory => unreachable,
...@@ -138,7 +139,10 @@ test "comptime test error for empty error set" {...@@ -138,7 +139,10 @@ test "comptime test error for empty error set" {
138const EmptyErrorSet = error{};139const EmptyErrorSet = error{};
139140
140fn testComptimeTestErrorEmptySet(x: EmptyErrorSet!i32) !void {141fn 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 }
142}146}
143147
144test "syntax: optional operator in front of error union operator" {148test "syntax: optional operator in front of error union operator" {
...@@ -162,6 +166,7 @@ fn testErrToIntWithOnePossibleValue(...@@ -162,6 +166,7 @@ fn testErrToIntWithOnePossibleValue(
162166
163test "empty error union" {167test "empty error union" {
164 const x = error{} || error{};168 const x = error{} || error{};
169 _ = x;
165}170}
166171
167test "error union peer type resolution" {172test "error union peer type resolution" {
...@@ -204,6 +209,7 @@ fn entry() void {...@@ -204,6 +209,7 @@ fn entry() void {
204209
205fn foo2(f: fn () anyerror!void) void {210fn foo2(f: fn () anyerror!void) void {
206 const x = f();211 const x = f();
212 x catch {};
207}213}
208214
209fn bar2() (error{}!void) {}215fn bar2() (error{}!void) {}
...@@ -338,6 +344,7 @@ test "optional error set is the same size as error set" {...@@ -338,6 +344,7 @@ test "optional error set is the same size as error set" {
338test "debug info for optional error set" {344test "debug info for optional error set" {
339 const SomeError = error{Hello};345 const SomeError = error{Hello};
340 var a_local_variable: ?SomeError = null;346 var a_local_variable: ?SomeError = null;
347 _ = a_local_variable;
341}348}
342349
343test "nested catch" {350test "nested catch" {
...@@ -349,7 +356,7 @@ test "nested catch" {...@@ -349,7 +356,7 @@ test "nested catch" {
349 return error.Wrong;356 return error.Wrong;
350 }357 }
351 fn func() anyerror!Foo {358 fn func() anyerror!Foo {
352 const x = fail() catch359 _ = fail() catch
353 fail() catch360 fail() catch
354 return error.Bad;361 return error.Bad;
355 unreachable;362 unreachable;
...@@ -390,6 +397,7 @@ test "function pointer with return type that is error union with payload which i...@@ -390,6 +397,7 @@ test "function pointer with return type that is error union with payload which i
390 const Err = error{UnspecifiedErr};397 const Err = error{UnspecifiedErr};
391398
392 fn bar(a: i32) anyerror!*Foo {399 fn bar(a: i32) anyerror!*Foo {
400 _ = a;
393 return Err.UnspecifiedErr;401 return Err.UnspecifiedErr;
394 }402 }
395403
...@@ -444,7 +452,9 @@ test "error payload type is correctly resolved" {...@@ -444,7 +452,9 @@ test "error payload type is correctly resolved" {
444452
445test "error union comptime caching" {453test "error union comptime caching" {
446 const S = struct {454 const S = struct {
447 fn foo(comptime arg: anytype) void {}455 fn foo(comptime arg: anytype) void {
456 arg catch {};
457 }
448 };458 };
449459
450 S.foo(@as(anyerror!void, {}));460 S.foo(@as(anyerror!void, {}));
test/behavior/eval.zig+9-2
...@@ -184,6 +184,7 @@ fn testTryToTrickEvalWithRuntimeIf(b: bool) usize {...@@ -184,6 +184,7 @@ fn testTryToTrickEvalWithRuntimeIf(b: bool) usize {
184 comptime var i: usize = 0;184 comptime var i: usize = 0;
185 inline while (i < 10) : (i += 1) {185 inline while (i < 10) : (i += 1) {
186 const result = if (b) false else true;186 const result = if (b) false else true;
187 _ = result;
187 }188 }
188 comptime {189 comptime {
189 return i;190 return i;
...@@ -195,6 +196,7 @@ test "inlined loop has array literal with elided runtime scope on first iteratio...@@ -195,6 +196,7 @@ test "inlined loop has array literal with elided runtime scope on first iteratio
195 comptime var i: usize = 0;196 comptime var i: usize = 0;
196 inline while (i < 2) : (i += 1) {197 inline while (i < 2) : (i += 1) {
197 const result = if (i == 0) [1]i32{2} else runtime;198 const result = if (i == 0) [1]i32{2} else runtime;
199 _ = result;
198 }200 }
199 comptime {201 comptime {
200 try expect(i == 2);202 try expect(i == 2);
...@@ -420,6 +422,7 @@ test {...@@ -420,6 +422,7 @@ test {
420}422}
421423
422pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {424pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {
425 _ = field_name;
423 return struct {426 return struct {
424 pub const Node = struct {};427 pub const Node = struct {};
425 };428 };
...@@ -696,7 +699,9 @@ test "refer to the type of a generic function" {...@@ -696,7 +699,9 @@ test "refer to the type of a generic function" {
696 f(i32);699 f(i32);
697}700}
698701
699fn doNothingWithType(comptime T: type) void {}702fn doNothingWithType(comptime T: type) void {
703 _ = T;
704}
700705
701test "zero extend from u0 to u1" {706test "zero extend from u0 to u1" {
702 var zero_u0: u0 = 0;707 var zero_u0: u0 = 0;
...@@ -817,7 +822,9 @@ test "two comptime calls with array default initialized to undefined" {...@@ -817,7 +822,9 @@ test "two comptime calls with array default initialized to undefined" {
817 result.getCpuArch();822 result.getCpuArch();
818 }823 }
819824
820 pub fn getCpuArch(self: CrossTarget) void {}825 pub fn getCpuArch(self: CrossTarget) void {
826 _ = self;
827 }
821 };828 };
822829
823 const DynamicLinker = struct {830 const DynamicLinker = struct {
test/behavior/fn.zig+8-2
...@@ -23,6 +23,7 @@ test "void parameters" {...@@ -23,6 +23,7 @@ test "void parameters" {
23 try voidFun(1, void{}, 2, {});23 try voidFun(1, void{}, 2, {});
24}24}
25fn voidFun(a: i32, b: void, c: i32, d: void) !void {25fn voidFun(a: i32, b: void, c: i32, d: void) !void {
26 _ = d;
26 const v = b;27 const v = b;
27 const vv: void = if (a == 1) v else {};28 const vv: void = if (a == 1) v else {};
28 try expect(a + c == 3);29 try expect(a + c == 3);
...@@ -57,7 +58,9 @@ test "call function with empty string" {...@@ -57,7 +58,9 @@ test "call function with empty string" {
57 acceptsString("");58 acceptsString("");
58}59}
5960
60fn acceptsString(foo: []u8) void {}61fn acceptsString(foo: []u8) void {
62 _ = foo;
63}
6164
62fn @"weird function name"() i32 {65fn @"weird function name"() i32 {
63 return 1234;66 return 1234;
...@@ -70,7 +73,9 @@ test "implicit cast function unreachable return" {...@@ -70,7 +73,9 @@ test "implicit cast function unreachable return" {
70 wantsFnWithVoid(fnWithUnreachable);73 wantsFnWithVoid(fnWithUnreachable);
71}74}
7275
73fn wantsFnWithVoid(f: fn () void) void {}76fn wantsFnWithVoid(f: fn () void) void {
77 _ = f;
78}
7479
75fn fnWithUnreachable() noreturn {80fn fnWithUnreachable() noreturn {
76 unreachable;81 unreachable;
...@@ -162,6 +167,7 @@ const Point3 = struct {...@@ -162,6 +167,7 @@ const Point3 = struct {
162 y: i32,167 y: i32,
163168
164 fn addPointCoords(self: Point3, comptime T: type) i32 {169 fn addPointCoords(self: Point3, comptime T: type) i32 {
170 _ = T;
165 return self.x + self.y;171 return self.x + self.y;
166 }172 }
167};173};
test/behavior/for.zig+11-3
...@@ -29,10 +29,14 @@ test "for loop with pointer elem var" {...@@ -29,10 +29,14 @@ test "for loop with pointer elem var" {
29 mangleString(target[0..]);29 mangleString(target[0..]);
30 try expect(mem.eql(u8, &target, "bcdefgh"));30 try expect(mem.eql(u8, &target, "bcdefgh"));
3131
32 for (source) |*c, i|32 for (source) |*c, i| {
33 _ = i;
33 try expect(@TypeOf(c) == *const u8);34 try expect(@TypeOf(c) == *const u8);
34 for (target) |*c, i|35 }
36 for (target) |*c, i| {
37 _ = i;
35 try expect(@TypeOf(c) == *u8);38 try expect(@TypeOf(c) == *u8);
39 }
36}40}
3741
38fn mangleString(s: []u8) void {42fn mangleString(s: []u8) void {
...@@ -53,6 +57,7 @@ test "basic for loop" {...@@ -53,6 +57,7 @@ test "basic for loop" {
53 buf_index += 1;57 buf_index += 1;
54 }58 }
55 for (array) |item, index| {59 for (array) |item, index| {
60 _ = item;
56 buffer[buf_index] = @intCast(u8, index);61 buffer[buf_index] = @intCast(u8, index);
57 buf_index += 1;62 buf_index += 1;
58 }63 }
...@@ -62,6 +67,7 @@ test "basic for loop" {...@@ -62,6 +67,7 @@ test "basic for loop" {
62 buf_index += 1;67 buf_index += 1;
63 }68 }
64 for (array_ptr) |item, index| {69 for (array_ptr) |item, index| {
70 _ = item;
65 buffer[buf_index] = @intCast(u8, index);71 buffer[buf_index] = @intCast(u8, index);
66 buf_index += 1;72 buf_index += 1;
67 }73 }
...@@ -70,7 +76,7 @@ test "basic for loop" {...@@ -70,7 +76,7 @@ test "basic for loop" {
70 buffer[buf_index] = item;76 buffer[buf_index] = item;
71 buf_index += 1;77 buf_index += 1;
72 }78 }
73 for (unknown_size) |item, index| {79 for (unknown_size) |_, index| {
74 buffer[buf_index] = @intCast(u8, index);80 buffer[buf_index] = @intCast(u8, index);
75 buf_index += 1;81 buf_index += 1;
76 }82 }
...@@ -118,6 +124,7 @@ test "2 break statements and an else" {...@@ -118,6 +124,7 @@ test "2 break statements and an else" {
118 var buf: [10]u8 = undefined;124 var buf: [10]u8 = undefined;
119 var ok = false;125 var ok = false;
120 ok = for (buf) |item| {126 ok = for (buf) |item| {
127 _ = item;
121 if (f) break false;128 if (f) break false;
122 if (t) break true;129 if (t) break true;
123 } else false;130 } else false;
...@@ -136,6 +143,7 @@ test "for with null and T peer types and inferred result location type" {...@@ -136,6 +143,7 @@ test "for with null and T peer types and inferred result location type" {
136 break item;143 break item;
137 }144 }
138 } else null) |v| {145 } else null) |v| {
146 _ = v;
139 @panic("fail");147 @panic("fail");
140 }148 }
141 }149 }
test/behavior/if.zig+1-1
...@@ -45,7 +45,7 @@ var global_with_err: anyerror!u32 = error.SomeError;...@@ -45,7 +45,7 @@ var global_with_err: anyerror!u32 = error.SomeError;
45test "unwrap mutable global var" {45test "unwrap mutable global var" {
46 if (global_with_val) |v| {46 if (global_with_val) |v| {
47 try expect(v == 0);47 try expect(v == 0);
48 } else |e| {48 } else |_| {
49 unreachable;49 unreachable;
50 }50 }
51 if (global_with_err) |_| {51 if (global_with_err) |_| {
test/behavior/import.zig+1-1
...@@ -18,5 +18,5 @@ test "import in non-toplevel scope" {...@@ -18,5 +18,5 @@ test "import in non-toplevel scope" {
18}18}
1919
20test "import empty file" {20test "import empty file" {
21 const empty = @import("import/empty.zig");21 _ = @import("import/empty.zig");
22}22}
test/behavior/inttoptr.zig+1-1
...@@ -5,7 +5,7 @@ test "casting random address to function pointer" {...@@ -5,7 +5,7 @@ test "casting random address to function pointer" {
55
6fn randomAddressToFunction() void {6fn randomAddressToFunction() void {
7 var addr: usize = 0xdeadbeef;7 var addr: usize = 0xdeadbeef;
8 var ptr = @intToPtr(fn () void, addr);8 _ = @intToPtr(fn () void, addr);
9}9}
1010
11test "mutate through ptr initialized with constant intToPtr value" {11test "mutate through ptr initialized with constant intToPtr value" {
test/behavior/ir_block_deps.zig+1
...@@ -5,6 +5,7 @@ fn foo(id: u64) !i32 {...@@ -5,6 +5,7 @@ fn foo(id: u64) !i32 {
5 1 => getErrInt(),5 1 => getErrInt(),
6 2 => {6 2 => {
7 const size = try getErrInt();7 const size = try getErrInt();
8 _ = size;
8 return try getErrInt();9 return try getErrInt();
9 },10 },
10 else => error.ItBroke,11 else => error.ItBroke,
test/behavior/math.zig+11
...@@ -333,6 +333,12 @@ test "quad hex float literal parsing in range" {...@@ -333,6 +333,12 @@ test "quad hex float literal parsing in range" {
333 const b = 0x1.dedafcff354b6ae9758763545432p-9;333 const b = 0x1.dedafcff354b6ae9758763545432p-9;
334 const c = 0x1.2f34dd5f437e849b4baab754cdefp+4534;334 const c = 0x1.2f34dd5f437e849b4baab754cdefp+4534;
335 const d = 0x1.edcbff8ad76ab5bf46463233214fp-435;335 const d = 0x1.edcbff8ad76ab5bf46463233214fp-435;
336 if (false) {
337 a;
338 b;
339 c;
340 d;
341 }
336}342}
337343
338test "quad hex float literal parsing accurate" {344test "quad hex float literal parsing accurate" {
...@@ -457,6 +463,11 @@ test "hex float literal within range" {...@@ -457,6 +463,11 @@ test "hex float literal within range" {
457 const a = 0x1.0p16383;463 const a = 0x1.0p16383;
458 const b = 0x0.1p16387;464 const b = 0x0.1p16387;
459 const c = 0x1.0p-16382;465 const c = 0x1.0p-16382;
466 if (false) {
467 a;
468 b;
469 c;
470 }
460}471}
461472
462test "truncating shift left" {473test "truncating shift left" {
test/behavior/misc.zig+18-4
...@@ -234,6 +234,7 @@ test "compile time global reinterpret" {...@@ -234,6 +234,7 @@ test "compile time global reinterpret" {
234test "explicit cast maybe pointers" {234test "explicit cast maybe pointers" {
235 const a: ?*i32 = undefined;235 const a: ?*i32 = undefined;
236 const b: ?*f32 = @ptrCast(?*f32, a);236 const b: ?*f32 = @ptrCast(?*f32, a);
237 _ = b;
237}238}
238239
239test "generic malloc free" {240test "generic malloc free" {
...@@ -244,14 +245,18 @@ var some_mem: [100]u8 = undefined;...@@ -244,14 +245,18 @@ var some_mem: [100]u8 = undefined;
244fn memAlloc(comptime T: type, n: usize) anyerror![]T {245fn memAlloc(comptime T: type, n: usize) anyerror![]T {
245 return @ptrCast([*]T, &some_mem[0])[0..n];246 return @ptrCast([*]T, &some_mem[0])[0..n];
246}247}
247fn memFree(comptime T: type, memory: []T) void {}248fn memFree(comptime T: type, memory: []T) void {
249 _ = memory;
250}
248251
249test "cast undefined" {252test "cast undefined" {
250 const array: [100]u8 = undefined;253 const array: [100]u8 = undefined;
251 const slice = @as([]const u8, &array);254 const slice = @as([]const u8, &array);
252 testCastUndefined(slice);255 testCastUndefined(slice);
253}256}
254fn testCastUndefined(x: []const u8) void {}257fn testCastUndefined(x: []const u8) void {
258 _ = x;
259}
255260
256test "cast small unsigned to larger signed" {261test "cast small unsigned to larger signed" {
257 try expect(castSmallUnsignedToLargerSigned1(200) == @as(i16, 200));262 try expect(castSmallUnsignedToLargerSigned1(200) == @as(i16, 200));
...@@ -451,6 +456,7 @@ test "@typeName" {...@@ -451,6 +456,7 @@ test "@typeName" {
451}456}
452457
453fn TypeFromFn(comptime T: type) type {458fn TypeFromFn(comptime T: type) type {
459 _ = T;
454 return struct {};460 return struct {};
455}461}
456462
...@@ -554,7 +560,12 @@ test "packed struct, enum, union parameters in extern function" {...@@ -554,7 +560,12 @@ test "packed struct, enum, union parameters in extern function" {
554 }), &(PackedUnion{ .a = 1 }));560 }), &(PackedUnion{ .a = 1 }));
555}561}
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
559test "slicing zero length array" {570test "slicing zero length array" {
560 const s1 = ""[0..];571 const s1 = ""[0..];
...@@ -583,6 +594,7 @@ test "self reference through fn ptr field" {...@@ -583,6 +594,7 @@ test "self reference through fn ptr field" {
583 };594 };
584595
585 fn foo(a: A) u8 {596 fn foo(a: A) u8 {
597 _ = a;
586 return 12;598 return 12;
587 }599 }
588 };600 };
...@@ -752,7 +764,9 @@ test "extern variable with non-pointer opaque type" {...@@ -752,7 +764,9 @@ test "extern variable with non-pointer opaque type" {
752764
753test "lazy typeInfo value as generic parameter" {765test "lazy typeInfo value as generic parameter" {
754 const S = struct {766 const S = struct {
755 fn foo(args: anytype) void {}767 fn foo(args: anytype) void {
768 _ = args;
769 }
756 };770 };
757 S.foo(@typeInfo(@TypeOf(.{})));771 S.foo(@typeInfo(@TypeOf(.{})));
758}772}
test/behavior/null.zig+2
...@@ -39,6 +39,7 @@ test "test maybe object and get a pointer to the inner value" {...@@ -39,6 +39,7 @@ test "test maybe object and get a pointer to the inner value" {
39test "rhs maybe unwrap return" {39test "rhs maybe unwrap return" {
40 const x: ?bool = true;40 const x: ?bool = true;
41 const y = x orelse return;41 const y = x orelse return;
42 _ = y;
42}43}
4344
44test "maybe return" {45test "maybe return" {
...@@ -129,6 +130,7 @@ var struct_with_optional: StructWithOptional = undefined;...@@ -129,6 +130,7 @@ var struct_with_optional: StructWithOptional = undefined;
129test "unwrap optional which is field of global var" {130test "unwrap optional which is field of global var" {
130 struct_with_optional.field = null;131 struct_with_optional.field = null;
131 if (struct_with_optional.field) |payload| {132 if (struct_with_optional.field) |payload| {
133 _ = payload;
132 unreachable;134 unreachable;
133 }135 }
134 struct_with_optional.field = 1234;136 struct_with_optional.field = 1234;
test/behavior/optional.zig+2
...@@ -128,6 +128,7 @@ test "nested orelse" {...@@ -128,6 +128,7 @@ test "nested orelse" {
128 const x = maybe() orelse128 const x = maybe() orelse
129 maybe() orelse129 maybe() orelse
130 return null;130 return null;
131 _ = x;
131 unreachable;132 unreachable;
132 }133 }
133 const Foo = struct {134 const Foo = struct {
...@@ -160,6 +161,7 @@ test "self-referential struct through a slice of optional" {...@@ -160,6 +161,7 @@ test "self-referential struct through a slice of optional" {
160test "assigning to an unwrapped optional field in an inline loop" {161test "assigning to an unwrapped optional field in an inline loop" {
161 comptime var maybe_pos_arg: ?comptime_int = null;162 comptime var maybe_pos_arg: ?comptime_int = null;
162 inline for ("ab") |x| {163 inline for ("ab") |x| {
164 _ = x;
163 maybe_pos_arg = 0;165 maybe_pos_arg = 0;
164 if (maybe_pos_arg.? != 0) {166 if (maybe_pos_arg.? != 0) {
165 @compileError("bad");167 @compileError("bad");
test/behavior/pointers.zig+10-2
...@@ -65,6 +65,10 @@ test "assigning integer to C pointer" {...@@ -65,6 +65,10 @@ test "assigning integer to C pointer" {
65 var x: i32 = 0;65 var x: i32 = 0;
66 var ptr: [*c]u8 = 0;66 var ptr: [*c]u8 = 0;
67 var ptr2: [*c]u8 = x;67 var ptr2: [*c]u8 = x;
68 if (false) {
69 ptr;
70 ptr2;
71 }
68}72}
6973
70test "implicit cast single item pointer to C pointer and back" {74test "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" {...@@ -78,7 +82,6 @@ test "implicit cast single item pointer to C pointer and back" {
78test "C pointer comparison and arithmetic" {82test "C pointer comparison and arithmetic" {
79 const S = struct {83 const S = struct {
80 fn doTheTest() !void {84 fn doTheTest() !void {
81 var one: usize = 1;
82 var ptr1: [*c]u32 = 0;85 var ptr1: [*c]u32 = 0;
83 var ptr2 = ptr1 + 10;86 var ptr2 = ptr1 + 10;
84 try expect(ptr1 == 0);87 try expect(ptr1 == 0);
...@@ -176,6 +179,7 @@ test "assign null directly to C pointer and test null equality" {...@@ -176,6 +179,7 @@ test "assign null directly to C pointer and test null equality" {
176 try expect(!(x != null));179 try expect(!(x != null));
177 try expect(!(null != x));180 try expect(!(null != x));
178 if (x) |same_x| {181 if (x) |same_x| {
182 _ = same_x;
179 @panic("fail");183 @panic("fail");
180 }184 }
181 var otherx: i32 = undefined;185 var otherx: i32 = undefined;
...@@ -186,7 +190,10 @@ test "assign null directly to C pointer and test null equality" {...@@ -186,7 +190,10 @@ test "assign null directly to C pointer and test null equality" {
186 comptime try expect(null == y);190 comptime try expect(null == y);
187 comptime try expect(!(y != null));191 comptime try expect(!(y != null));
188 comptime try expect(!(null != y));192 comptime try expect(!(null != y));
189 if (y) |same_y| @panic("fail");193 if (y) |same_y| {
194 _ = same_y;
195 @panic("fail");
196 }
190 const othery: i32 = undefined;197 const othery: i32 = undefined;
191 comptime try expect((y orelse &othery) == &othery);198 comptime try expect((y orelse &othery) == &othery);
192199
...@@ -325,6 +332,7 @@ test "@ptrToInt on null optional at comptime" {...@@ -325,6 +332,7 @@ test "@ptrToInt on null optional at comptime" {
325 {332 {
326 const pointer = @intToPtr(?*u8, 0x000);333 const pointer = @intToPtr(?*u8, 0x000);
327 const x = @ptrToInt(pointer);334 const x = @ptrToInt(pointer);
335 _ = x;
328 comptime try expect(0 == @ptrToInt(pointer));336 comptime try expect(0 == @ptrToInt(pointer));
329 }337 }
330 {338 {
test/behavior/reflection.zig+5
...@@ -15,6 +15,11 @@ test "reflection: function return type, var args, and param types" {...@@ -15,6 +15,11 @@ test "reflection: function return type, var args, and param types" {
15}15}
1616
17fn dummy(a: bool, b: i32, c: f32) i32 {17fn dummy(a: bool, b: i32, c: f32) i32 {
18 if (false) {
19 a;
20 b;
21 c;
22 }
18 return 1234;23 return 1234;
19}24}
2025
test/behavior/sizeof_and_typeof.zig+2-2
...@@ -195,11 +195,11 @@ test "branching logic inside @TypeOf" {...@@ -195,11 +195,11 @@ test "branching logic inside @TypeOf" {
195195
196fn fn1(alpha: bool) void {196fn fn1(alpha: bool) void {
197 const n: usize = 7;197 const n: usize = 7;
198 const v = if (alpha) n else @sizeOf(usize);198 _ = if (alpha) n else @sizeOf(usize);
199}199}
200200
201test "lazy @sizeOf result is checked for definedness" {201test "lazy @sizeOf result is checked for definedness" {
202 const f = fn1;202 _ = fn1;
203}203}
204204
205test "@bitSizeOf" {205test "@bitSizeOf" {
test/behavior/slice.zig+1
...@@ -104,6 +104,7 @@ test "obtaining a null terminated slice" {...@@ -104,6 +104,7 @@ test "obtaining a null terminated slice" {
104104
105 // now we obtain a null terminated slice:105 // now we obtain a null terminated slice:
106 const ptr = buf[0..3 :0];106 const ptr = buf[0..3 :0];
107 _ = ptr;
107108
108 var runtime_len: usize = 3;109 var runtime_len: usize = 3;
109 const ptr2 = buf[0..runtime_len :0];110 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)" {...@@ -3,6 +3,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {
3 comptime {3 comptime {
4 var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;4 var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
5 const slice = target[0..3 :'d'];5 const slice = target[0..3 :'d'];
6 _ = slice;
6 }7 }
78
8 // ptr_array9 // ptr_array
...@@ -10,6 +11,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {...@@ -10,6 +11,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {
10 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;11 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
11 var target = &buf;12 var target = &buf;
12 const slice = target[0..3 :'d'];13 const slice = target[0..3 :'d'];
14 _ = slice;
13 }15 }
1416
15 // vector_ConstPtrSpecialBaseArray17 // vector_ConstPtrSpecialBaseArray
...@@ -17,6 +19,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {...@@ -17,6 +19,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {
17 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;19 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
18 var target: [*]u8 = &buf;20 var target: [*]u8 = &buf;
19 const slice = target[0..3 :'d'];21 const slice = target[0..3 :'d'];
22 _ = slice;
20 }23 }
2124
22 // vector_ConstPtrSpecialRef25 // vector_ConstPtrSpecialRef
...@@ -24,6 +27,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {...@@ -24,6 +27,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {
24 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;27 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
25 var target: [*]u8 = @ptrCast([*]u8, &buf);28 var target: [*]u8 = @ptrCast([*]u8, &buf);
26 const slice = target[0..3 :'d'];29 const slice = target[0..3 :'d'];
30 _ = slice;
27 }31 }
2832
29 // cvector_ConstPtrSpecialBaseArray33 // cvector_ConstPtrSpecialBaseArray
...@@ -31,6 +35,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {...@@ -31,6 +35,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {
31 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;35 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
32 var target: [*c]u8 = &buf;36 var target: [*c]u8 = &buf;
33 const slice = target[0..3 :'d'];37 const slice = target[0..3 :'d'];
38 _ = slice;
34 }39 }
3540
36 // cvector_ConstPtrSpecialRef41 // cvector_ConstPtrSpecialRef
...@@ -38,6 +43,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {...@@ -38,6 +43,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {
38 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;43 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
39 var target: [*c]u8 = @ptrCast([*c]u8, &buf);44 var target: [*c]u8 = @ptrCast([*c]u8, &buf);
40 const slice = target[0..3 :'d'];45 const slice = target[0..3 :'d'];
46 _ = slice;
41 }47 }
4248
43 // slice49 // slice
...@@ -45,6 +51,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {...@@ -45,6 +51,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {
45 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;51 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
46 var target: []u8 = &buf;52 var target: []u8 = &buf;
47 const slice = target[0..3 :'d'];53 const slice = target[0..3 :'d'];
54 _ = slice;
48 }55 }
49}56}
5057
...@@ -53,6 +60,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {...@@ -53,6 +60,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {
53 comptime {60 comptime {
54 var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;61 var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;
55 const slice = target[0..13 :0xff];62 const slice = target[0..13 :0xff];
63 _ = slice;
56 }64 }
5765
58 // ptr_array66 // ptr_array
...@@ -60,6 +68,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {...@@ -60,6 +68,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {
60 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;68 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;
61 var target = &buf;69 var target = &buf;
62 const slice = target[0..13 :0xff];70 const slice = target[0..13 :0xff];
71 _ = slice;
63 }72 }
6473
65 // vector_ConstPtrSpecialBaseArray74 // vector_ConstPtrSpecialBaseArray
...@@ -67,6 +76,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {...@@ -67,6 +76,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {
67 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;76 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;
68 var target: [*]u8 = &buf;77 var target: [*]u8 = &buf;
69 const slice = target[0..13 :0xff];78 const slice = target[0..13 :0xff];
79 _ = slice;
70 }80 }
7181
72 // vector_ConstPtrSpecialRef82 // vector_ConstPtrSpecialRef
...@@ -74,6 +84,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {...@@ -74,6 +84,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {
74 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;84 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;
75 var target: [*]u8 = @ptrCast([*]u8, &buf);85 var target: [*]u8 = @ptrCast([*]u8, &buf);
76 const slice = target[0..13 :0xff];86 const slice = target[0..13 :0xff];
87 _ = slice;
77 }88 }
7889
79 // cvector_ConstPtrSpecialBaseArray90 // cvector_ConstPtrSpecialBaseArray
...@@ -81,6 +92,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {...@@ -81,6 +92,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {
81 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;92 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;
82 var target: [*c]u8 = &buf;93 var target: [*c]u8 = &buf;
83 const slice = target[0..13 :0xff];94 const slice = target[0..13 :0xff];
95 _ = slice;
84 }96 }
8597
86 // cvector_ConstPtrSpecialRef98 // cvector_ConstPtrSpecialRef
...@@ -88,6 +100,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {...@@ -88,6 +100,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {
88 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;100 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;
89 var target: [*c]u8 = @ptrCast([*c]u8, &buf);101 var target: [*c]u8 = @ptrCast([*c]u8, &buf);
90 const slice = target[0..13 :0xff];102 const slice = target[0..13 :0xff];
103 _ = slice;
91 }104 }
92105
93 // slice106 // slice
...@@ -95,6 +108,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {...@@ -95,6 +108,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {
95 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;108 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;
96 var target: []u8 = &buf;109 var target: []u8 = &buf;
97 const slice = target[0..13 :0xff];110 const slice = target[0..13 :0xff];
111 _ = slice;
98 }112 }
99}113}
100114
...@@ -103,6 +117,7 @@ test "comptime slice-sentinel in bounds (terminated)" {...@@ -103,6 +117,7 @@ test "comptime slice-sentinel in bounds (terminated)" {
103 comptime {117 comptime {
104 var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;118 var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
105 const slice = target[0..3 :'d'];119 const slice = target[0..3 :'d'];
120 _ = slice;
106 }121 }
107122
108 // ptr_array123 // ptr_array
...@@ -110,6 +125,7 @@ test "comptime slice-sentinel in bounds (terminated)" {...@@ -110,6 +125,7 @@ test "comptime slice-sentinel in bounds (terminated)" {
110 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;125 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
111 var target = &buf;126 var target = &buf;
112 const slice = target[0..3 :'d'];127 const slice = target[0..3 :'d'];
128 _ = slice;
113 }129 }
114130
115 // vector_ConstPtrSpecialBaseArray131 // vector_ConstPtrSpecialBaseArray
...@@ -117,6 +133,7 @@ test "comptime slice-sentinel in bounds (terminated)" {...@@ -117,6 +133,7 @@ test "comptime slice-sentinel in bounds (terminated)" {
117 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;133 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
118 var target: [*]u8 = &buf;134 var target: [*]u8 = &buf;
119 const slice = target[0..3 :'d'];135 const slice = target[0..3 :'d'];
136 _ = slice;
120 }137 }
121138
122 // vector_ConstPtrSpecialRef139 // vector_ConstPtrSpecialRef
...@@ -124,6 +141,7 @@ test "comptime slice-sentinel in bounds (terminated)" {...@@ -124,6 +141,7 @@ test "comptime slice-sentinel in bounds (terminated)" {
124 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;141 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
125 var target: [*]u8 = @ptrCast([*]u8, &buf);142 var target: [*]u8 = @ptrCast([*]u8, &buf);
126 const slice = target[0..3 :'d'];143 const slice = target[0..3 :'d'];
144 _ = slice;
127 }145 }
128146
129 // cvector_ConstPtrSpecialBaseArray147 // cvector_ConstPtrSpecialBaseArray
...@@ -131,6 +149,7 @@ test "comptime slice-sentinel in bounds (terminated)" {...@@ -131,6 +149,7 @@ test "comptime slice-sentinel in bounds (terminated)" {
131 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;149 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
132 var target: [*c]u8 = &buf;150 var target: [*c]u8 = &buf;
133 const slice = target[0..3 :'d'];151 const slice = target[0..3 :'d'];
152 _ = slice;
134 }153 }
135154
136 // cvector_ConstPtrSpecialRef155 // cvector_ConstPtrSpecialRef
...@@ -138,6 +157,7 @@ test "comptime slice-sentinel in bounds (terminated)" {...@@ -138,6 +157,7 @@ test "comptime slice-sentinel in bounds (terminated)" {
138 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;157 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
139 var target: [*c]u8 = @ptrCast([*c]u8, &buf);158 var target: [*c]u8 = @ptrCast([*c]u8, &buf);
140 const slice = target[0..3 :'d'];159 const slice = target[0..3 :'d'];
160 _ = slice;
141 }161 }
142162
143 // slice163 // slice
...@@ -145,6 +165,7 @@ test "comptime slice-sentinel in bounds (terminated)" {...@@ -145,6 +165,7 @@ test "comptime slice-sentinel in bounds (terminated)" {
145 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;165 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
146 var target: []u8 = &buf;166 var target: []u8 = &buf;
147 const slice = target[0..3 :'d'];167 const slice = target[0..3 :'d'];
168 _ = slice;
148 }169 }
149}170}
150171
...@@ -153,6 +174,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {...@@ -153,6 +174,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {
153 comptime {174 comptime {
154 var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;175 var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
155 const slice = target[0..14 :0];176 const slice = target[0..14 :0];
177 _ = slice;
156 }178 }
157179
158 // ptr_array180 // ptr_array
...@@ -160,6 +182,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {...@@ -160,6 +182,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {
160 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;182 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
161 var target = &buf;183 var target = &buf;
162 const slice = target[0..14 :0];184 const slice = target[0..14 :0];
185 _ = slice;
163 }186 }
164187
165 // vector_ConstPtrSpecialBaseArray188 // vector_ConstPtrSpecialBaseArray
...@@ -167,6 +190,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {...@@ -167,6 +190,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {
167 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;190 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
168 var target: [*]u8 = &buf;191 var target: [*]u8 = &buf;
169 const slice = target[0..14 :0];192 const slice = target[0..14 :0];
193 _ = slice;
170 }194 }
171195
172 // vector_ConstPtrSpecialRef196 // vector_ConstPtrSpecialRef
...@@ -174,6 +198,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {...@@ -174,6 +198,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {
174 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;198 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
175 var target: [*]u8 = @ptrCast([*]u8, &buf);199 var target: [*]u8 = @ptrCast([*]u8, &buf);
176 const slice = target[0..14 :0];200 const slice = target[0..14 :0];
201 _ = slice;
177 }202 }
178203
179 // cvector_ConstPtrSpecialBaseArray204 // cvector_ConstPtrSpecialBaseArray
...@@ -181,6 +206,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {...@@ -181,6 +206,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {
181 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;206 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
182 var target: [*c]u8 = &buf;207 var target: [*c]u8 = &buf;
183 const slice = target[0..14 :0];208 const slice = target[0..14 :0];
209 _ = slice;
184 }210 }
185211
186 // cvector_ConstPtrSpecialRef212 // cvector_ConstPtrSpecialRef
...@@ -188,6 +214,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {...@@ -188,6 +214,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {
188 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;214 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
189 var target: [*c]u8 = @ptrCast([*c]u8, &buf);215 var target: [*c]u8 = @ptrCast([*c]u8, &buf);
190 const slice = target[0..14 :0];216 const slice = target[0..14 :0];
217 _ = slice;
191 }218 }
192219
193 // slice220 // slice
...@@ -195,5 +222,6 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {...@@ -195,5 +222,6 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {
195 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;222 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
196 var target: []u8 = &buf;223 var target: []u8 = &buf;
197 const slice = target[0..14 :0];224 const slice = target[0..14 :0];
225 _ = slice;
198 }226 }
199}227}
test/behavior/struct.zig+10-3
...@@ -182,6 +182,7 @@ test "empty struct method call" {...@@ -182,6 +182,7 @@ test "empty struct method call" {
182}182}
183const EmptyStruct = struct {183const EmptyStruct = struct {
184 fn method(es: *const EmptyStruct) i32 {184 fn method(es: *const EmptyStruct) i32 {
185 _ = es;
185 return 1234;186 return 1234;
186 }187 }
187};188};
...@@ -452,9 +453,11 @@ fn alloc(comptime T: type) []T {...@@ -452,9 +453,11 @@ fn alloc(comptime T: type) []T {
452test "call method with mutable reference to struct with no fields" {453test "call method with mutable reference to struct with no fields" {
453 const S = struct {454 const S = struct {
454 fn doC(s: *const @This()) bool {455 fn doC(s: *const @This()) bool {
456 _ = s;
455 return true;457 return true;
456 }458 }
457 fn do(s: *@This()) bool {459 fn do(s: *@This()) bool {
460 _ = s;
458 return true;461 return true;
459 }462 }
460 };463 };
...@@ -584,13 +587,14 @@ test "default struct initialization fields" {...@@ -584,13 +587,14 @@ test "default struct initialization fields" {
584 const x = S{587 const x = S{
585 .b = 5,588 .b = 5,
586 };589 };
587 if (x.a + x.b != 1239) {
588 @compileError("it should be comptime known");
589 }
590 var five: i32 = 5;590 var five: i32 = 5;
591 const y = S{591 const y = S{
592 .b = five,592 .b = five,
593 };593 };
594 if (x.a + x.b != 1239) {
595 @compileError("it should be comptime known");
596 }
597 try expectEqual(y, x);
594 try expectEqual(1239, x.a + x.b);598 try expectEqual(1239, x.a + x.b);
595}599}
596600
...@@ -624,11 +628,13 @@ test "for loop over pointers to struct, getting field from struct pointer" {...@@ -624,11 +628,13 @@ test "for loop over pointers to struct, getting field from struct pointer" {
624 var ok = true;628 var ok = true;
625629
626 fn eql(a: []const u8) bool {630 fn eql(a: []const u8) bool {
631 _ = a;
627 return true;632 return true;
628 }633 }
629634
630 const ArrayList = struct {635 const ArrayList = struct {
631 fn toSlice(self: *ArrayList) []*Foo {636 fn toSlice(self: *ArrayList) []*Foo {
637 _ = self;
632 return @as([*]*Foo, undefined)[0..0];638 return @as([*]*Foo, undefined)[0..0];
633 }639 }
634 };640 };
...@@ -654,6 +660,7 @@ test "zero-bit field in packed struct" {...@@ -654,6 +660,7 @@ test "zero-bit field in packed struct" {
654 y: void,660 y: void,
655 };661 };
656 var x: S = undefined;662 var x: S = undefined;
663 _ = x;
657}664}
658665
659test "struct field init with catch" {666test "struct field init with catch" {
test/behavior/switch.zig+15-3
...@@ -103,6 +103,7 @@ fn switchProngWithVarFn(a: SwitchProngWithVarEnum) !void {...@@ -103,6 +103,7 @@ fn switchProngWithVarFn(a: SwitchProngWithVarEnum) !void {
103 },103 },
104 SwitchProngWithVarEnum.Meh => |x| {104 SwitchProngWithVarEnum.Meh => |x| {
105 const v: void = x;105 const v: void = x;
106 _ = v;
106 },107 },
107 }108 }
108}109}
...@@ -385,6 +386,7 @@ test "switch with null and T peer types and inferred result location type" {...@@ -385,6 +386,7 @@ test "switch with null and T peer types and inferred result location type" {
385 0 => true,386 0 => true,
386 else => null,387 else => null,
387 }) |v| {388 }) |v| {
389 _ = v;
388 @panic("fail");390 @panic("fail");
389 }391 }
390 }392 }
...@@ -410,12 +412,18 @@ test "switch prongs with cases with identical payload types" {...@@ -410,12 +412,18 @@ test "switch prongs with cases with identical payload types" {
410 try expect(@TypeOf(e) == usize);412 try expect(@TypeOf(e) == usize);
411 try expect(e == 8);413 try expect(e == 8);
412 },414 },
413 .B => |e| @panic("fail"),415 .B => |e| {
416 _ = e;
417 @panic("fail");
418 },
414 }419 }
415 }420 }
416 fn doTheSwitch2(u: Union) !void {421 fn doTheSwitch2(u: Union) !void {
417 switch (u) {422 switch (u) {
418 .A, .C => |e| @panic("fail"),423 .A, .C => |e| {
424 _ = e;
425 @panic("fail");
426 },
419 .B => |e| {427 .B => |e| {
420 try expect(@TypeOf(e) == isize);428 try expect(@TypeOf(e) == isize);
421 try expect(e == -8);429 try expect(e == -8);
...@@ -454,6 +462,7 @@ test "switch variable for range and multiple prongs" {...@@ -454,6 +462,7 @@ test "switch variable for range and multiple prongs" {
454 }462 }
455 }463 }
456 };464 };
465 _ = S;
457}466}
458467
459var state: u32 = 0;468var state: u32 = 0;
...@@ -506,7 +515,10 @@ test "switch on error set with single else" {...@@ -506,7 +515,10 @@ test "switch on error set with single else" {
506 fn doTheTest() !void {515 fn doTheTest() !void {
507 var some: error{Foo} = error.Foo;516 var some: error{Foo} = error.Foo;
508 try expect(switch (some) {517 try expect(switch (some) {
509 else => |a| true,518 else => |a| blk: {
519 a catch {};
520 break :blk true;
521 },
510 });522 });
511 }523 }
512 };524 };
test/behavior/tuple.zig+1
...@@ -105,6 +105,7 @@ test "tuple initializer for var" {...@@ -105,6 +105,7 @@ test "tuple initializer for var" {
105 .id = @as(usize, 2),105 .id = @as(usize, 2),
106 .name = Bytes{ .id = 20 },106 .name = Bytes{ .id = 20 },
107 };107 };
108 _ = tmp;
108 }109 }
109 };110 };
110111
test/behavior/type.zig+6-1
...@@ -431,11 +431,14 @@ test "Type.Fn" {...@@ -431,11 +431,14 @@ test "Type.Fn" {
431431
432 const foo = struct {432 const foo = struct {
433 fn func(a: usize, b: bool) align(4) callconv(.C) usize {433 fn func(a: usize, b: bool) align(4) callconv(.C) usize {
434 _ = a;
435 _ = b;
434 return 0;436 return 0;
435 }437 }
436 }.func;438 }.func;
437 const Foo = @Type(@typeInfo(@TypeOf(foo)));439 const Foo = @Type(@typeInfo(@TypeOf(foo)));
438 const foo_2: Foo = foo;440 const foo_2: Foo = foo;
441 _ = foo_2;
439}442}
440443
441test "Type.BoundFn" {444test "Type.BoundFn" {
...@@ -443,7 +446,9 @@ test "Type.BoundFn" {...@@ -443,7 +446,9 @@ test "Type.BoundFn" {
443 if (builtin.target.cpu.arch == .wasm32 or builtin.target.cpu.arch == .wasm64) return error.SkipZigTest;446 if (builtin.target.cpu.arch == .wasm32 or builtin.target.cpu.arch == .wasm64) return error.SkipZigTest;
444447
445 const TestStruct = packed struct {448 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 }
447 };452 };
448 const test_instance: TestStruct = undefined;453 const test_instance: TestStruct = undefined;
449 try testing.expect(std.meta.eql(454 try testing.expect(std.meta.eql(
test/behavior/type_info.zig+8-2
...@@ -277,7 +277,9 @@ const TestStruct = packed struct {...@@ -277,7 +277,9 @@ const TestStruct = packed struct {
277 fieldC: *Self,277 fieldC: *Self,
278 fieldD: u32 = 4,278 fieldD: u32 = 4,
279279
280 pub fn foo(self: *const Self) void {}280 pub fn foo(self: *const Self) void {
281 _ = self;
282 }
281 const Self = @This();283 const Self = @This();
282};284};
283285
...@@ -326,9 +328,12 @@ extern fn fooAligned(a: usize, b: bool, ...) align(4) callconv(.C) usize;...@@ -326,9 +328,12 @@ extern fn fooAligned(a: usize, b: bool, ...) align(4) callconv(.C) usize;
326328
327test "typeInfo with comptime parameter in struct fn def" {329test "typeInfo with comptime parameter in struct fn def" {
328 const S = struct {330 const S = struct {
329 pub fn func(comptime x: f32) void {}331 pub fn func(comptime x: f32) void {
332 _ = x;
333 }
330 };334 };
331 comptime var info = @typeInfo(S);335 comptime var info = @typeInfo(S);
336 _ = info;
332}337}
333338
334test "type info: vectors" {339test "type info: vectors" {
...@@ -368,6 +373,7 @@ test "type info: pass to function" {...@@ -368,6 +373,7 @@ test "type info: pass to function" {
368}373}
369374
370fn passTypeInfo(comptime info: TypeInfo) type {375fn passTypeInfo(comptime info: TypeInfo) type {
376 _ = info;
371 return void;377 return void;
372}378}
373379
test/behavior/underscore.zig+2
...@@ -7,7 +7,9 @@ test "ignore lval with underscore" {...@@ -7,7 +7,9 @@ test "ignore lval with underscore" {
77
8test "ignore lval with underscore (for loop)" {8test "ignore lval with underscore (for loop)" {
9 for ([_]void{}) |_, i| {9 for ([_]void{}) |_, i| {
10 _ = i;
10 for ([_]void{}) |_, j| {11 for ([_]void{}) |_, j| {
12 _ = j;
11 break;13 break;
12 }14 }
13 break;15 break;
test/behavior/union.zig+9-2
...@@ -374,7 +374,9 @@ const Attribute = union(enum) {...@@ -374,7 +374,9 @@ const Attribute = union(enum) {
374 B: u8,374 B: u8,
375};375};
376376
377fn setAttribute(attr: Attribute) void {}377fn setAttribute(attr: Attribute) void {
378 _ = attr;
379}
378380
379fn Setter(attr: Attribute) type {381fn Setter(attr: Attribute) type {
380 return struct {382 return struct {
...@@ -465,7 +467,9 @@ test "union no tag with struct member" {...@@ -465,7 +467,9 @@ test "union no tag with struct member" {
465 const Struct = struct {};467 const Struct = struct {};
466 const Union = union {468 const Union = union {
467 s: Struct,469 s: Struct,
468 pub fn foo(self: *@This()) void {}470 pub fn foo(self: *@This()) void {
471 _ = self;
472 }
469 };473 };
470 var u = Union{ .s = Struct{} };474 var u = Union{ .s = Struct{} };
471 u.foo();475 u.foo();
...@@ -703,6 +707,7 @@ test "method call on an empty union" {...@@ -703,6 +707,7 @@ test "method call on an empty union" {
703 X2: [0]u8,707 X2: [0]u8,
704708
705 pub fn useIt(self: *@This()) bool {709 pub fn useIt(self: *@This()) bool {
710 _ = self;
706 return true;711 return true;
707 }712 }
708 };713 };
...@@ -771,6 +776,7 @@ test "@unionInit on union w/ tag but no fields" {...@@ -771,6 +776,7 @@ test "@unionInit on union w/ tag but no fields" {
771 no_op: void,776 no_op: void,
772777
773 pub fn decode(buf: []const u8) Data {778 pub fn decode(buf: []const u8) Data {
779 _ = buf;
774 return @unionInit(Data, "no_op", {});780 return @unionInit(Data, "no_op", {});
775 }781 }
776 };782 };
...@@ -781,6 +787,7 @@ test "@unionInit on union w/ tag but no fields" {...@@ -781,6 +787,7 @@ test "@unionInit on union w/ tag but no fields" {
781787
782 fn doTheTest() !void {788 fn doTheTest() !void {
783 var data: Data = .{ .no_op = .{} };789 var data: Data = .{ .no_op = .{} };
790 _ = data;
784 var o = Data.decode(&[_]u8{});791 var o = Data.decode(&[_]u8{});
785 try expectEqual(Type.no_op, o);792 try expectEqual(Type.no_op, o);
786 }793 }
test/behavior/var_args.zig+5-2
...@@ -18,7 +18,7 @@ test "add arbitrary args" {...@@ -18,7 +18,7 @@ test "add arbitrary args" {
18}18}
1919
20fn readFirstVarArg(args: anytype) void {20fn readFirstVarArg(args: anytype) void {
21 const value = args[0];21 _ = args[0];
22}22}
2323
24test "send void arg to var args" {24test "send void arg to var args" {
...@@ -48,6 +48,7 @@ test "runtime parameter before var args" {...@@ -48,6 +48,7 @@ test "runtime parameter before var args" {
48}48}
4949
50fn extraFn(extra: u32, args: anytype) !usize {50fn extraFn(extra: u32, args: anytype) !usize {
51 _ = extra;
51 if (args.len >= 1) {52 if (args.len >= 1) {
52 try expect(args[0] == false);53 try expect(args[0] == false);
53 }54 }
...@@ -63,9 +64,11 @@ const foos = [_]fn (anytype) bool{...@@ -63,9 +64,11 @@ const foos = [_]fn (anytype) bool{
63};64};
6465
65fn foo1(args: anytype) bool {66fn foo1(args: anytype) bool {
67 _ = args;
66 return true;68 return true;
67}69}
68fn foo2(args: anytype) bool {70fn foo2(args: anytype) bool {
71 _ = args;
69 return false;72 return false;
70}73}
7174
...@@ -79,5 +82,5 @@ test "pass zero length array to var args param" {...@@ -79,5 +82,5 @@ test "pass zero length array to var args param" {
79}82}
8083
81fn doNothingWithFirstArg(args: anytype) void {84fn doNothingWithFirstArg(args: anytype) void {
82 const a = args[0];85 _ = args[0];
83}86}
test/behavior/vector.zig+2
...@@ -113,6 +113,7 @@ test "array to vector" {...@@ -113,6 +113,7 @@ test "array to vector" {
113 var foo: f32 = 3.14;113 var foo: f32 = 3.14;
114 var arr = [4]f32{ foo, 1.5, 0.0, 0.0 };114 var arr = [4]f32{ foo, 1.5, 0.0, 0.0 };
115 var vec: Vector(4, f32) = arr;115 var vec: Vector(4, f32) = arr;
116 _ = vec;
116}117}
117118
118test "vector casts of sizes not divisable by 8" {119test "vector casts of sizes not divisable by 8" {
...@@ -264,6 +265,7 @@ test "initialize vector which is a struct field" {...@@ -264,6 +265,7 @@ test "initialize vector which is a struct field" {
264 var foo = Vec4Obj{265 var foo = Vec4Obj{
265 .data = [_]f32{ 1, 2, 3, 4 },266 .data = [_]f32{ 1, 2, 3, 4 },
266 };267 };
268 _ = foo;
267 }269 }
268 };270 };
269 try S.doTheTest();271 try S.doTheTest();
test/behavior/void.zig+1-1
...@@ -36,5 +36,5 @@ test "void optional" {...@@ -36,5 +36,5 @@ test "void optional" {
3636
37test "void array as a local variable initializer" {37test "void array as a local variable initializer" {
38 var x = [_]void{{}} ** 1004;38 var x = [_]void{{}} ** 1004;
39 var y = x[0];39 _ = x[0];
40}40}
test/behavior/while.zig+2-2
...@@ -151,14 +151,14 @@ test "while on optional with else result follow break prong" {...@@ -151,14 +151,14 @@ test "while on optional with else result follow break prong" {
151test "while on error union with else result follow else prong" {151test "while on error union with else result follow else prong" {
152 const result = while (returnError()) |value| {152 const result = while (returnError()) |value| {
153 break value;153 break value;
154 } else |err| @as(i32, 2);154 } else |_| @as(i32, 2);
155 try expect(result == 2);155 try expect(result == 2);
156}156}
157157
158test "while on error union with else result follow break prong" {158test "while on error union with else result follow break prong" {
159 const result = while (returnSuccess(10)) |value| {159 const result = while (returnSuccess(10)) |value| {
160 break value;160 break value;
161 } else |err| @as(i32, 2);161 } else |_| @as(i32, 2);
162 try expect(result == 10);162 try expect(result == 10);
163}163}
164164
test/stage2/cbe.zig+37-28
...@@ -93,16 +93,16 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -93,16 +93,16 @@ pub fn addCases(ctx: *TestContext) !void {
93 , "");93 , "");
94 case.addError(94 case.addError(
95 \\pub export fn main() c_int {95 \\pub export fn main() c_int {
96 \\ const c = @intToError(0);96 \\ _ = @intToError(0);
97 \\ return 0;97 \\ return 0;
98 \\}98 \\}
99 , &.{":2:27: error: integer value 0 represents no error"});99 , &.{":2:21: error: integer value 0 represents no error"});
100 case.addError(100 case.addError(
101 \\pub export fn main() c_int {101 \\pub export fn main() c_int {
102 \\ const c = @intToError(3);102 \\ _ = @intToError(3);
103 \\ return 0;103 \\ return 0;
104 \\}104 \\}
105 , &.{":2:27: error: integer value 3 represents no error"});105 , &.{":2:21: error: integer value 3 represents no error"});
106 }106 }
107107
108 {108 {
...@@ -383,6 +383,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -383,6 +383,7 @@ pub fn addCases(ctx: *TestContext) !void {
383 \\ true => 2,383 \\ true => 2,
384 \\ false => 3,384 \\ false => 3,
385 \\ };385 \\ };
386 \\ _ = b;
386 \\}387 \\}
387 , &.{388 , &.{
388 ":6:9: error: duplicate switch value",389 ":6:9: error: duplicate switch value",
...@@ -398,6 +399,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -398,6 +399,7 @@ pub fn addCases(ctx: *TestContext) !void {
398 \\ f64, i32 => 3,399 \\ f64, i32 => 3,
399 \\ else => 4,400 \\ else => 4,
400 \\ };401 \\ };
402 \\ _ = b;
401 \\}403 \\}
402 , &.{404 , &.{
403 ":6:14: error: duplicate switch value",405 ":6:14: error: duplicate switch value",
...@@ -414,6 +416,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -414,6 +416,7 @@ pub fn addCases(ctx: *TestContext) !void {
414 \\ f16...f64 => 3,416 \\ f16...f64 => 3,
415 \\ else => 4,417 \\ else => 4,
416 \\ };418 \\ };
419 \\ _ = b;
417 \\}420 \\}
418 , &.{421 , &.{
419 ":3:30: error: ranges not allowed when switching on type 'type'",422 ":3:30: error: ranges not allowed when switching on type 'type'",
...@@ -431,6 +434,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -431,6 +434,7 @@ pub fn addCases(ctx: *TestContext) !void {
431 \\ 3 => 40,434 \\ 3 => 40,
432 \\ else => 50,435 \\ else => 50,
433 \\ };436 \\ };
437 \\ _ = b;
434 \\}438 \\}
435 , &.{439 , &.{
436 ":8:14: error: unreachable else prong; all cases already handled",440 ":8:14: error: unreachable else prong; all cases already handled",
...@@ -556,10 +560,10 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -556,10 +560,10 @@ pub fn addCases(ctx: *TestContext) !void {
556 \\const E1 = packed enum { a, b, c };560 \\const E1 = packed enum { a, b, c };
557 \\const E2 = extern enum { a, b, c };561 \\const E2 = extern enum { a, b, c };
558 \\export fn foo() void {562 \\export fn foo() void {
559 \\ const x = E1.a;563 \\ _ = E1.a;
560 \\}564 \\}
561 \\export fn bar() void {565 \\export fn bar() void {
562 \\ const x = E2.a;566 \\ _ = E2.a;
563 \\}567 \\}
564 , &.{568 , &.{
565 ":1:12: error: enums do not support 'packed' or 'extern'; instead provide an explicit integer tag type",569 ":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 {...@@ -579,10 +583,10 @@ pub fn addCases(ctx: *TestContext) !void {
579 \\ c,583 \\ c,
580 \\};584 \\};
581 \\export fn foo() void {585 \\export fn foo() void {
582 \\ const x = E1.a;586 \\ _ = E1.a;
583 \\}587 \\}
584 \\export fn bar() void {588 \\export fn bar() void {
585 \\ const x = E2.a;589 \\ _ = E2.a;
586 \\}590 \\}
587 , &.{591 , &.{
588 ":3:5: error: enum fields cannot be marked comptime",592 ":3:5: error: enum fields cannot be marked comptime",
...@@ -621,7 +625,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -621,7 +625,7 @@ pub fn addCases(ctx: *TestContext) !void {
621 \\ c,625 \\ c,
622 \\};626 \\};
623 \\export fn foo() void {627 \\export fn foo() void {
624 \\ const x = E1.a;628 \\ _ = E1.a;
625 \\}629 \\}
626 , &.{630 , &.{
627 ":3:7: error: expected ',', found 'align'",631 ":3:7: error: expected ',', found 'align'",
...@@ -638,7 +642,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -638,7 +642,7 @@ pub fn addCases(ctx: *TestContext) !void {
638 \\ _,642 \\ _,
639 \\};643 \\};
640 \\export fn foo() void {644 \\export fn foo() void {
641 \\ const x = E1.a;645 \\ _ = E1.a;
642 \\}646 \\}
643 , &.{647 , &.{
644 ":6:5: error: redundant non-exhaustive enum mark",648 ":6:5: error: redundant non-exhaustive enum mark",
...@@ -653,7 +657,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -653,7 +657,7 @@ pub fn addCases(ctx: *TestContext) !void {
653 \\ _ = 10,657 \\ _ = 10,
654 \\};658 \\};
655 \\export fn foo() void {659 \\export fn foo() void {
656 \\ const x = E1.a;660 \\ _ = E1.a;
657 \\}661 \\}
658 , &.{662 , &.{
659 ":5:9: error: '_' is used to mark an enum as non-exhaustive and cannot be assigned a value",663 ":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 {...@@ -662,7 +666,7 @@ pub fn addCases(ctx: *TestContext) !void {
662 case.addError(666 case.addError(
663 \\const E1 = enum {};667 \\const E1 = enum {};
664 \\export fn foo() void {668 \\export fn foo() void {
665 \\ const x = E1.a;669 \\ _ = E1.a;
666 \\}670 \\}
667 , &.{671 , &.{
668 ":1:12: error: enum declarations must have at least one tag",672 ":1:12: error: enum declarations must have at least one tag",
...@@ -671,7 +675,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -671,7 +675,7 @@ pub fn addCases(ctx: *TestContext) !void {
671 case.addError(675 case.addError(
672 \\const E1 = enum { a, b, _ };676 \\const E1 = enum { a, b, _ };
673 \\export fn foo() void {677 \\export fn foo() void {
674 \\ const x = E1.a;678 \\ _ = E1.a;
675 \\}679 \\}
676 , &.{680 , &.{
677 ":1:12: error: non-exhaustive enum missing integer tag type",681 ":1:12: error: non-exhaustive enum missing integer tag type",
...@@ -681,7 +685,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -681,7 +685,7 @@ pub fn addCases(ctx: *TestContext) !void {
681 case.addError(685 case.addError(
682 \\const E1 = enum { a, b, c, b, d };686 \\const E1 = enum { a, b, c, b, d };
683 \\pub export fn main() c_int {687 \\pub export fn main() c_int {
684 \\ const x = E1.a;688 \\ _ = E1.a;
685 \\}689 \\}
686 , &.{690 , &.{
687 ":1:28: error: duplicate enum tag",691 ":1:28: error: duplicate enum tag",
...@@ -691,28 +695,28 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -691,28 +695,28 @@ pub fn addCases(ctx: *TestContext) !void {
691 case.addError(695 case.addError(
692 \\pub export fn main() c_int {696 \\pub export fn main() c_int {
693 \\ const a = true;697 \\ const a = true;
694 \\ const b = @enumToInt(a);698 \\ _ = @enumToInt(a);
695 \\}699 \\}
696 , &.{700 , &.{
697 ":3:26: error: expected enum or tagged union, found bool",701 ":3:20: error: expected enum or tagged union, found bool",
698 });702 });
699703
700 case.addError(704 case.addError(
701 \\pub export fn main() c_int {705 \\pub export fn main() c_int {
702 \\ const a = 1;706 \\ const a = 1;
703 \\ const b = @intToEnum(bool, a);707 \\ _ = @intToEnum(bool, a);
704 \\}708 \\}
705 , &.{709 , &.{
706 ":3:26: error: expected enum, found bool",710 ":3:20: error: expected enum, found bool",
707 });711 });
708712
709 case.addError(713 case.addError(
710 \\const E = enum { a, b, c };714 \\const E = enum { a, b, c };
711 \\pub export fn main() c_int {715 \\pub export fn main() c_int {
712 \\ const b = @intToEnum(E, 3);716 \\ _ = @intToEnum(E, 3);
713 \\}717 \\}
714 , &.{718 , &.{
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",
716 ":1:11: note: enum declared here",720 ":1:11: note: enum declared here",
717 });721 });
718722
...@@ -780,10 +784,10 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -780,10 +784,10 @@ pub fn addCases(ctx: *TestContext) !void {
780 case.addError(784 case.addError(
781 \\const E = enum { a, b, c };785 \\const E = enum { a, b, c };
782 \\pub export fn main() c_int {786 \\pub export fn main() c_int {
783 \\ var x = E.d;787 \\ _ = E.d;
784 \\}788 \\}
785 , &.{789 , &.{
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'",
787 ":1:11: note: enum declared here",791 ":1:11: note: enum declared here",
788 });792 });
789793
...@@ -791,6 +795,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -791,6 +795,7 @@ pub fn addCases(ctx: *TestContext) !void {
791 \\const E = enum { a, b, c };795 \\const E = enum { a, b, c };
792 \\pub export fn main() c_int {796 \\pub export fn main() c_int {
793 \\ var x: E = .d;797 \\ var x: E = .d;
798 \\ _ = x;
794 \\}799 \\}
795 , &.{800 , &.{
796 ":3:17: error: enum 'test_case.E' has no field named 'd'",801 ":3:17: error: enum 'test_case.E' has no field named 'd'",
...@@ -818,31 +823,35 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -818,31 +823,35 @@ pub fn addCases(ctx: *TestContext) !void {
818 \\823 \\
819 );824 );
820 ctx.h("header with single param function", linux_x64,825 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 \\}
822 ,829 ,
823 \\ZIG_EXTERN_C void start(uint8_t a0);830 \\ZIG_EXTERN_C void start(uint8_t a0);
824 \\831 \\
825 );832 );
826 ctx.h("header with multiple param function", linux_x64,833 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 \\}
828 ,837 ,
829 \\ZIG_EXTERN_C void start(uint8_t a0, uint8_t a1, uint8_t a2);838 \\ZIG_EXTERN_C void start(uint8_t a0, uint8_t a1, uint8_t a2);
830 \\839 \\
831 );840 );
832 ctx.h("header with u32 param function", linux_x64,841 ctx.h("header with u32 param function", linux_x64,
833 \\export fn start(a: u32) void{}842 \\export fn start(a: u32) void{ _ = a; }
834 ,843 ,
835 \\ZIG_EXTERN_C void start(uint32_t a0);844 \\ZIG_EXTERN_C void start(uint32_t a0);
836 \\845 \\
837 );846 );
838 ctx.h("header with usize param function", linux_x64,847 ctx.h("header with usize param function", linux_x64,
839 \\export fn start(a: usize) void{}848 \\export fn start(a: usize) void{ _ = a; }
840 ,849 ,
841 \\ZIG_EXTERN_C void start(uintptr_t a0);850 \\ZIG_EXTERN_C void start(uintptr_t a0);
842 \\851 \\
843 );852 );
844 ctx.h("header with bool param function", linux_x64,853 ctx.h("header with bool param function", linux_x64,
845 \\export fn start(a: bool) void{}854 \\export fn start(a: bool) void{_ = a;}
846 ,855 ,
847 \\ZIG_EXTERN_C void start(bool a0);856 \\ZIG_EXTERN_C void start(bool a0);
848 \\857 \\
...@@ -866,7 +875,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -866,7 +875,7 @@ pub fn addCases(ctx: *TestContext) !void {
866 \\875 \\
867 );876 );
868 ctx.h("header with multiple includes", linux_x64,877 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; }
870 ,879 ,
871 \\ZIG_EXTERN_C void start(uint32_t a0, uintptr_t a1);880 \\ZIG_EXTERN_C void start(uint32_t a0, uintptr_t a1);
872 \\881 \\
test/stage2/test.zig+27-10
...@@ -246,11 +246,20 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -246,11 +246,20 @@ pub fn addCases(ctx: *TestContext) !void {
246 "",246 "",
247 );247 );
248 }248 }
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 }
249 {257 {
250 var case = ctx.exe("@TypeOf", linux_x64);258 var case = ctx.exe("@TypeOf", linux_x64);
251 case.addCompareOutput(259 case.addCompareOutput(
252 \\pub fn main() void {260 \\pub fn main() void {
253 \\ var x: usize = 0;261 \\ var x: usize = 0;
262 \\ _ = x;
254 \\ const z = @TypeOf(x, @as(u128, 5));263 \\ const z = @TypeOf(x, @as(u128, 5));
255 \\ assert(z == u128);264 \\ assert(z == u128);
256 \\}265 \\}
...@@ -275,9 +284,9 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -275,9 +284,9 @@ pub fn addCases(ctx: *TestContext) !void {
275 );284 );
276 case.addError(285 case.addError(
277 \\pub fn main() void {286 \\pub fn main() void {
278 \\ const z = @TypeOf(true, 1);287 \\ _ = @TypeOf(true, 1);
279 \\}288 \\}
280 , &[_][]const u8{":2:15: error: incompatible types: 'bool' and 'comptime_int'"});289 , &[_][]const u8{":2:9: error: incompatible types: 'bool' and 'comptime_int'"});
281 }290 }
282291
283 {292 {
...@@ -738,6 +747,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -738,6 +747,7 @@ pub fn addCases(ctx: *TestContext) !void {
738 \\ \\ cool thx747 \\ \\ cool thx
739 \\ \\748 \\ \\
740 \\ ;749 \\ ;
750 \\ _ = ignore;
741 \\ add('ぁ', '\x03');751 \\ add('ぁ', '\x03');
742 \\}752 \\}
743 \\753 \\
...@@ -889,6 +899,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -889,6 +899,7 @@ pub fn addCases(ctx: *TestContext) !void {
889 \\ try expect(false);899 \\ try expect(false);
890 \\ }900 \\ }
891 \\ };901 \\ };
902 \\ _ = S;
892 \\}903 \\}
893 ,904 ,
894 &.{":4:13: error: invalid 'try' outside function scope"},905 &.{":4:13: error: invalid 'try' outside function scope"},
...@@ -979,6 +990,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -979,6 +990,7 @@ pub fn addCases(ctx: *TestContext) !void {
979 \\ return bar;990 \\ return bar;
980 \\ }991 \\ }
981 \\ };992 \\ };
993 \\ _ = S;
982 \\}994 \\}
983 , &.{995 , &.{
984 ":5:20: error: 'bar' not accessible from inner function",996 ":5:20: error: 'bar' not accessible from inner function",
...@@ -1064,6 +1076,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -1064,6 +1076,7 @@ pub fn addCases(ctx: *TestContext) !void {
1064 \\ @compileLog(b, 20, f, x);1076 \\ @compileLog(b, 20, f, x);
1065 \\ @compileLog(1000);1077 \\ @compileLog(1000);
1066 \\ var bruh: usize = true;1078 \\ var bruh: usize = true;
1079 \\ _ = bruh;
1067 \\ unreachable;1080 \\ unreachable;
1068 \\}1081 \\}
1069 \\export fn other() void {1082 \\export fn other() void {
...@@ -1209,6 +1222,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -1209,6 +1222,7 @@ pub fn addCases(ctx: *TestContext) !void {
1209 case.addError(1222 case.addError(
1210 \\pub fn main() void {1223 \\pub fn main() void {
1211 \\ var x = null;1224 \\ var x = null;
1225 \\ _ = x;
1212 \\}1226 \\}
1213 , &[_][]const u8{1227 , &[_][]const u8{
1214 ":2:9: error: variable of type '@Type(.Null)' must be const or comptime",1228 ":2:9: error: variable of type '@Type(.Null)' must be const or comptime",
...@@ -1378,7 +1392,9 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -1378,7 +1392,9 @@ pub fn addCases(ctx: *TestContext) !void {
1378 \\pub fn main() void {1392 \\pub fn main() void {
1379 \\ doNothing(0);1393 \\ doNothing(0);
1380 \\}1394 \\}
1381 \\fn doNothing(arg: u0) void {}1395 \\fn doNothing(arg: u0) void {
1396 \\ _ = arg;
1397 \\}
1382 ,1398 ,
1383 "",1399 "",
1384 );1400 );
...@@ -1448,14 +1464,14 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -1448,14 +1464,14 @@ pub fn addCases(ctx: *TestContext) !void {
1448 case.addCompareOutput(1464 case.addCompareOutput(
1449 \\pub fn main() void {1465 \\pub fn main() void {
1450 \\ const E = error{ A, B, D } || error { A, B, C };1466 \\ const E = error{ A, B, D } || error { A, B, C };
1451 \\ const a = E.A;1467 \\ E.A catch {};
1452 \\ const b = E.B;1468 \\ E.B catch {};
1453 \\ const c = E.C;1469 \\ E.C catch {};
1454 \\ const d = E.D;1470 \\ E.D catch {};
1455 \\ const E2 = error { X, Y } || @TypeOf(error.Z);1471 \\ const E2 = error { X, Y } || @TypeOf(error.Z);
1456 \\ const x = E2.X;1472 \\ E2.X catch {};
1457 \\ const y = E2.Y;1473 \\ E2.Y catch {};
1458 \\ const z = E2.Z;1474 \\ E2.Z catch {};
1459 \\ assert(anyerror || error { Z } == anyerror);1475 \\ assert(anyerror || error { Z } == anyerror);
1460 \\}1476 \\}
1461 \\fn assert(b: bool) void {1477 \\fn assert(b: bool) void {
...@@ -1477,6 +1493,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -1477,6 +1493,7 @@ pub fn addCases(ctx: *TestContext) !void {
1477 \\ [arg1] "{rdi}" (code)1493 \\ [arg1] "{rdi}" (code)
1478 \\ : "rcx", "r11", "memory"1494 \\ : "rcx", "r11", "memory"
1479 \\ );1495 \\ );
1496 \\ _ = x;
1480 \\}1497 \\}
1481 , &[_][]const u8{":4:27: error: expected type, found comptime_int"});1498 , &[_][]const u8{":4:27: error: expected type, found comptime_int"});
1482 }1499 }
test/stage2/wasm.zig+11-1
...@@ -64,7 +64,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -64,7 +64,7 @@ pub fn addCases(ctx: *TestContext) !void {
64 \\ foo(10, 20);64 \\ foo(10, 20);
65 \\ return 5;65 \\ return 5;
66 \\}66 \\}
67 \\fn foo(x: u32, y: u32) void {}67 \\fn foo(x: u32, y: u32) void { _ = x; _ = y; }
68 , "5\n");68 , "5\n");
69 }69 }
7070
...@@ -76,6 +76,10 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -76,6 +76,10 @@ pub fn addCases(ctx: *TestContext) !void {
76 \\ var i: u32 = 5;76 \\ var i: u32 = 5;
77 \\ var y: f32 = 42.0;77 \\ var y: f32 = 42.0;
78 \\ var x: u32 = 10;78 \\ var x: u32 = 10;
79 \\ if (false) {
80 \\ y;
81 \\ x;
82 \\ }
79 \\ return i;83 \\ return i;
80 \\}84 \\}
81 , "5\n");85 , "5\n");
...@@ -84,12 +88,14 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -84,12 +88,14 @@ pub fn addCases(ctx: *TestContext) !void {
84 \\pub export fn _start() u32 {88 \\pub export fn _start() u32 {
85 \\ var i: u32 = 5;89 \\ var i: u32 = 5;
86 \\ var y: f32 = 42.0;90 \\ var y: f32 = 42.0;
91 \\ _ = y;
87 \\ var x: u32 = 10;92 \\ var x: u32 = 10;
88 \\ foo(i, x);93 \\ foo(i, x);
89 \\ i = x;94 \\ i = x;
90 \\ return i;95 \\ return i;
91 \\}96 \\}
92 \\fn foo(x: u32, y: u32) void {97 \\fn foo(x: u32, y: u32) void {
98 \\ _ = y;
93 \\ var i: u32 = 10;99 \\ var i: u32 = 10;
94 \\ i = x;100 \\ i = x;
95 \\}101 \\}
...@@ -388,6 +394,10 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -388,6 +394,10 @@ pub fn addCases(ctx: *TestContext) !void {
388 \\pub export fn _start() i32 {394 \\pub export fn _start() i32 {
389 \\ var number1 = Number.One;395 \\ var number1 = Number.One;
390 \\ var number2: Number = .Two;396 \\ var number2: Number = .Two;
397 \\ if (false) {
398 \\ number1;
399 \\ number2;
400 \\ }
391 \\ const number3 = @intToEnum(Number, 2);401 \\ const number3 = @intToEnum(Number, 2);
392 \\402 \\
393 \\ return @enumToInt(number3);403 \\ return @enumToInt(number3);
test/standalone/hello_world/hello_libc.zig+2
...@@ -8,6 +8,8 @@ const c = @cImport({...@@ -8,6 +8,8 @@ const c = @cImport({
8const msg = "Hello, world!\n";8const msg = "Hello, world!\n";
99
10pub export fn main(argc: c_int, argv: **u8) c_int {10pub export fn main(argc: c_int, argv: **u8) c_int {
11 _ = argv;
12 _ = argc;
11 if (c.printf(msg) != @intCast(c_int, c.strlen(msg))) return -1;13 if (c.printf(msg) != @intCast(c_int, c.strlen(msg))) return -1;
12 return 0;14 return 0;
13}15}
test/standalone/issue_339/test.zig+2
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1const StackTrace = @import("std").builtin.StackTrace;1const StackTrace = @import("std").builtin.StackTrace;
2pub fn panic(msg: []const u8, stack_trace: ?*StackTrace) noreturn {2pub fn panic(msg: []const u8, stack_trace: ?*StackTrace) noreturn {
3 _ = msg;
4 _ = stack_trace;
3 @breakpoint();5 @breakpoint();
4 while (true) {}6 while (true) {}
5}7}
test/standalone/issue_8550/main.zig+5
...@@ -1,6 +1,11 @@...@@ -1,6 +1,11 @@
1export fn main(r0: u32, r1: u32, atags: u32) callconv(.C) noreturn {1export fn main(r0: u32, r1: u32, atags: u32) callconv(.C) noreturn {
2 _ = r0;
3 _ = r1;
4 _ = atags;
2 unreachable; // never gets run so it doesn't matter5 unreachable; // never gets run so it doesn't matter
3}6}
4pub fn panic(msg: []const u8, error_return_trace: ?*@import("std").builtin.StackTrace) noreturn {7pub fn panic(msg: []const u8, error_return_trace: ?*@import("std").builtin.StackTrace) noreturn {
8 _ = msg;
9 _ = error_return_trace;
5 while (true) {}10 while (true) {}
6}11}
test/tests.zig+2-1
...@@ -417,6 +417,8 @@ pub fn addStandaloneTests(b: *build.Builder, test_filter: ?[]const u8, modes: []...@@ -417,6 +417,8 @@ pub fn addStandaloneTests(b: *build.Builder, test_filter: ?[]const u8, modes: []
417}417}
418418
419pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step {419pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step {
420 _ = test_filter;
421 _ = modes;
420 const step = b.step("test-cli", "Test the command line interface");422 const step = b.step("test-cli", "Test the command line interface");
421423
422 const exe = b.addExecutable("test-cli", "test/cli.zig");424 const exe = b.addExecutable("test-cli", "test/cli.zig");
...@@ -525,7 +527,6 @@ pub fn addPkgTests(...@@ -525,7 +527,6 @@ pub fn addPkgTests(
525 if (skip_single_threaded and test_target.single_threaded)527 if (skip_single_threaded and test_target.single_threaded)
526 continue;528 continue;
527529
528 const ArchTag = std.meta.Tag(std.Target.Cpu.Arch);
529 if (test_target.disable_native and530 if (test_target.disable_native and
530 test_target.target.getOsTag() == std.Target.current.os.tag and531 test_target.target.getOsTag() == std.Target.current.os.tag and
531 test_target.target.getCpuArch() == std.Target.current.cpu.arch)532 test_target.target.getCpuArch() == std.Target.current.cpu.arch)
tools/process_headers.zig+3
...@@ -236,12 +236,14 @@ const DestTarget = struct {...@@ -236,12 +236,14 @@ const DestTarget = struct {
236236
237 const HashContext = struct {237 const HashContext = struct {
238 pub fn hash(self: @This(), a: DestTarget) u32 {238 pub fn hash(self: @This(), a: DestTarget) u32 {
239 _ = self;
239 return @enumToInt(a.arch) +%240 return @enumToInt(a.arch) +%
240 (@enumToInt(a.os) *% @as(u32, 4202347608)) +%241 (@enumToInt(a.os) *% @as(u32, 4202347608)) +%
241 (@enumToInt(a.abi) *% @as(u32, 4082223418));242 (@enumToInt(a.abi) *% @as(u32, 4082223418));
242 }243 }
243244
244 pub fn eql(self: @This(), a: DestTarget, b: DestTarget) bool {245 pub fn eql(self: @This(), a: DestTarget, b: DestTarget) bool {
246 _ = self;
245 return a.arch.eql(b.arch) and247 return a.arch.eql(b.arch) and
246 a.os == b.os and248 a.os == b.os and
247 a.abi == b.abi;249 a.abi == b.abi;
...@@ -256,6 +258,7 @@ const Contents = struct {...@@ -256,6 +258,7 @@ const Contents = struct {
256 is_generic: bool,258 is_generic: bool,
257259
258 fn hitCountLessThan(context: void, lhs: *const Contents, rhs: *const Contents) bool {260 fn hitCountLessThan(context: void, lhs: *const Contents, rhs: *const Contents) bool {
261 _ = context;
259 return lhs.hit_count < rhs.hit_count;262 return lhs.hit_count < rhs.hit_count;
260 }263 }
261};264};
tools/update_clang_options.zig+3
...@@ -585,6 +585,8 @@ const Syntax = union(enum) {...@@ -585,6 +585,8 @@ const Syntax = union(enum) {
585 options: std.fmt.FormatOptions,585 options: std.fmt.FormatOptions,
586 out_stream: anytype,586 out_stream: anytype,
587 ) !void {587 ) !void {
588 _ = fmt;
589 _ = options;
588 switch (self) {590 switch (self) {
589 .multi_arg => |n| return out_stream.print(".{{.{s}={}}}", .{ @tagName(self), n }),591 .multi_arg => |n| return out_stream.print(".{{.{s}={}}}", .{ @tagName(self), n }),
590 else => return out_stream.print(".{s}", .{@tagName(self)}),592 else => return out_stream.print(".{s}", .{@tagName(self)}),
...@@ -663,6 +665,7 @@ fn syntaxMatchesWithEql(syntax: Syntax) bool {...@@ -663,6 +665,7 @@ fn syntaxMatchesWithEql(syntax: Syntax) bool {
663}665}
664666
665fn objectLessThan(context: void, a: *json.ObjectMap, b: *json.ObjectMap) bool {667fn objectLessThan(context: void, a: *json.ObjectMap, b: *json.ObjectMap) bool {
668 _ = context;
666 // Priority is determined by exact matches first, followed by prefix matches in descending669 // Priority is determined by exact matches first, followed by prefix matches in descending
667 // length, with key as a final tiebreaker.670 // length, with key as a final tiebreaker.
668 const a_syntax = objSyntax(a);671 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 {...@@ -1227,14 +1227,17 @@ fn usageAndExit(file: fs.File, arg0: []const u8, code: u8) noreturn {
1227}1227}
12281228
1229fn featureLessThan(context: void, a: Feature, b: Feature) bool {1229fn featureLessThan(context: void, a: Feature, b: Feature) bool {
1230 _ = context;
1230 return std.ascii.lessThanIgnoreCase(a.zig_name, b.zig_name);1231 return std.ascii.lessThanIgnoreCase(a.zig_name, b.zig_name);
1231}1232}
12321233
1233fn cpuLessThan(context: void, a: Cpu, b: Cpu) bool {1234fn cpuLessThan(context: void, a: Cpu, b: Cpu) bool {
1235 _ = context;
1234 return std.ascii.lessThanIgnoreCase(a.zig_name, b.zig_name);1236 return std.ascii.lessThanIgnoreCase(a.zig_name, b.zig_name);
1235}1237}
12361238
1237fn asciiLessThan(context: void, a: []const u8, b: []const u8) bool {1239fn asciiLessThan(context: void, a: []const u8, b: []const u8) bool {
1240 _ = context;
1238 return std.ascii.lessThanIgnoreCase(a, b);1241 return std.ascii.lessThanIgnoreCase(a, b);
1239}1242}
12401243
tools/update_glibc.zig+5-3
...@@ -155,7 +155,7 @@ pub fn main() !void {...@@ -155,7 +155,7 @@ pub fn main() !void {
155 }155 }
156 const fn_set = &target_funcs_gop.value_ptr.list;156 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| {
159 const lib_prefix = if (std.mem.eql(u8, lib_name, "ld")) "" else "lib";159 const lib_prefix = if (std.mem.eql(u8, lib_name, "ld")) "" else "lib";
160 const basename = try fmt.allocPrint(allocator, "{s}{s}.abilist", .{ lib_prefix, lib_name });160 const basename = try fmt.allocPrint(allocator, "{s}{s}.abilist", .{ lib_prefix, lib_name });
161 const abi_list_filename = blk: {161 const abi_list_filename = blk: {
...@@ -263,7 +263,7 @@ pub fn main() !void {...@@ -263,7 +263,7 @@ pub fn main() !void {
263263
264 // Now the mapping of version and function to integer index is complete.264 // Now the mapping of version and function to integer index is complete.
265 // Here we create a mapping of function name to list of versions.265 // 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| {
267 const value = target_functions.getPtr(@ptrToInt(abi_list)).?;267 const value = target_functions.getPtr(@ptrToInt(abi_list)).?;
268 const fn_vers_list = &value.fn_vers_list;268 const fn_vers_list = &value.fn_vers_list;
269 for (value.list.items) |*ver_fn| {269 for (value.list.items) |*ver_fn| {
...@@ -286,7 +286,7 @@ pub fn main() !void {...@@ -286,7 +286,7 @@ pub fn main() !void {
286 const abilist_txt = buffered.writer();286 const abilist_txt = buffered.writer();
287287
288 // first iterate over the abi lists288 // first iterate over the abi lists
289 for (abi_lists) |*abi_list, abi_index| {289 for (abi_lists) |*abi_list| {
290 const fn_vers_list = &target_functions.getPtr(@ptrToInt(abi_list)).?.fn_vers_list;290 const fn_vers_list = &target_functions.getPtr(@ptrToInt(abi_list)).?.fn_vers_list;
291 for (abi_list.targets) |target, it_i| {291 for (abi_list.targets) |target, it_i| {
292 if (it_i != 0) try abilist_txt.writeByte(' ');292 if (it_i != 0) try abilist_txt.writeByte(' ');
...@@ -312,10 +312,12 @@ pub fn main() !void {...@@ -312,10 +312,12 @@ pub fn main() !void {
312}312}
313313
314pub fn strCmpLessThan(context: void, a: []const u8, b: []const u8) bool {314pub fn strCmpLessThan(context: void, a: []const u8, b: []const u8) bool {
315 _ = context;
315 return std.mem.order(u8, a, b) == .lt;316 return std.mem.order(u8, a, b) == .lt;
316}317}
317318
318pub fn versionLessThan(context: void, a: []const u8, b: []const u8) bool {319pub fn versionLessThan(context: void, a: []const u8, b: []const u8) bool {
320 _ = context;
319 const sep_chars = "GLIBC_.";321 const sep_chars = "GLIBC_.";
320 var a_tokens = std.mem.tokenize(a, sep_chars);322 var a_tokens = std.mem.tokenize(a, sep_chars);
321 var b_tokens = std.mem.tokenize(b, sep_chars);323 var b_tokens = std.mem.tokenize(b, sep_chars);
tools/update_spirv_features.zig+1
...@@ -37,6 +37,7 @@ const Version = struct {...@@ -37,6 +37,7 @@ const Version = struct {
37 }37 }
3838
39 fn lessThan(ctx: void, a: Version, b: Version) bool {39 fn lessThan(ctx: void, a: Version, b: Version) bool {
40 _ = ctx;
40 return if (a.major == b.major)41 return if (a.major == b.major)
41 a.minor < b.minor42 a.minor < b.minor
42 else43 else