Skip to content

Commit

Permalink
run zig fmt on std lib and self hosted
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexu committed Jul 11, 2020
1 parent 8110639 commit b7f0219
Show file tree
Hide file tree
Showing 129 changed files with 464 additions and 468 deletions.
2 changes: 1 addition & 1 deletion lib/std/array_list.zig
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
/// Deprecated: use `items` field directly.
/// Return contents as a slice. Only valid while the list
/// doesn't change size.
pub fn span(self: var) @TypeOf(self.items) {
pub fn span(self: anytype) @TypeOf(self.items) {
return self.items;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/std/array_list_sentineled.zig
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn ArrayListSentineled(comptime T: type, comptime sentinel: T) type {
}

/// Only works when `T` is `u8`.
pub fn allocPrint(allocator: *Allocator, comptime format: []const u8, args: var) !Self {
pub fn allocPrint(allocator: *Allocator, comptime format: []const u8, args: anytype) !Self {
const size = std.math.cast(usize, std.fmt.count(format, args)) catch |err| switch (err) {
error.Overflow => return error.OutOfMemory,
};
Expand All @@ -82,7 +82,7 @@ pub fn ArrayListSentineled(comptime T: type, comptime sentinel: T) type {
self.list.deinit();
}

pub fn span(self: var) @TypeOf(self.list.items[0..:sentinel]) {
pub fn span(self: anytype) @TypeOf(self.list.items[0..:sentinel]) {
return self.list.items[0..self.len() :sentinel];
}

Expand Down
4 changes: 2 additions & 2 deletions lib/std/atomic/queue.zig
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ pub fn Queue(comptime T: type) type {
/// Dumps the contents of the queue to `stream`.
/// Up to 4 elements from the head are dumped and the tail of the queue is
/// dumped as well.
pub fn dumpToStream(self: *Self, stream: var) !void {
pub fn dumpToStream(self: *Self, stream: anytype) !void {
const S = struct {
fn dumpRecursive(
s: var,
s: anytype,
optional_node: ?*Node,
indent: usize,
comptime depth: comptime_int,
Expand Down
4 changes: 2 additions & 2 deletions lib/std/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ pub const Builder = struct {
return write_file_step;
}

pub fn addLog(self: *Builder, comptime format: []const u8, args: var) *LogStep {
pub fn addLog(self: *Builder, comptime format: []const u8, args: anytype) *LogStep {
const data = self.fmt(format, args);
const log_step = self.allocator.create(LogStep) catch unreachable;
log_step.* = LogStep.init(self, data);
Expand Down Expand Up @@ -883,7 +883,7 @@ pub const Builder = struct {
return fs.path.resolve(self.allocator, &[_][]const u8{ self.build_root, rel_path }) catch unreachable;
}

pub fn fmt(self: *Builder, comptime format: []const u8, args: var) []u8 {
pub fn fmt(self: *Builder, comptime format: []const u8, args: anytype) []u8 {
return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/std/build/emit_raw.zig
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const BinaryElfOutput = struct {
return segment.p_offset <= section.elfOffset and (segment.p_offset + segment.p_filesz) >= (section.elfOffset + section.fileSize);
}

fn sectionValidForOutput(shdr: var) bool {
fn sectionValidForOutput(shdr: anytype) bool {
return shdr.sh_size > 0 and shdr.sh_type != elf.SHT_NOBITS and
((shdr.sh_flags & elf.SHF_ALLOC) == elf.SHF_ALLOC);
}
Expand Down
10 changes: 5 additions & 5 deletions lib/std/builtin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ pub const TypeInfo = union(enum) {
/// The type of the sentinel is the element type of the pointer, which is
/// the value of the `child` field in this struct. However there is no way
/// to refer to that type here, so we use `var`.
sentinel: var,
sentinel: anytype,

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
Expand All @@ -220,7 +220,7 @@ pub const TypeInfo = union(enum) {
/// The type of the sentinel is the element type of the array, which is
/// the value of the `child` field in this struct. However there is no way
/// to refer to that type here, so we use `var`.
sentinel: var,
sentinel: anytype,
};

/// This data structure is used by the Zig language code generation and
Expand All @@ -237,7 +237,7 @@ pub const TypeInfo = union(enum) {
name: []const u8,
offset: ?comptime_int,
field_type: type,
default_value: var,
default_value: anytype,
};

/// This data structure is used by the Zig language code generation and
Expand Down Expand Up @@ -328,7 +328,7 @@ pub const TypeInfo = union(enum) {
/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const Frame = struct {
function: var,
function: anytype,
};

/// This data structure is used by the Zig language code generation and
Expand Down Expand Up @@ -452,7 +452,7 @@ pub const Version = struct {
self: Version,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
out_stream: var,
out_stream: anytype,
) !void {
if (fmt.len == 0) {
if (self.patch == 0) {
Expand Down
2 changes: 1 addition & 1 deletion lib/std/c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub usingnamespace switch (std.Target.current.os.tag) {
else => struct {},
};

pub fn getErrno(rc: var) u16 {
pub fn getErrno(rc: anytype) u16 {
if (rc == -1) {
return @intCast(u16, _errno().*);
} else {
Expand Down
14 changes: 7 additions & 7 deletions lib/std/c/ast.zig
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub const Error = union(enum) {
NothingDeclared: SimpleError("declaration doesn't declare anything"),
QualifierIgnored: SingleTokenError("qualifier '{}' ignored"),

pub fn render(self: *const Error, tree: *Tree, stream: var) !void {
pub fn render(self: *const Error, tree: *Tree, stream: anytype) !void {
switch (self.*) {
.InvalidToken => |*x| return x.render(tree, stream),
.ExpectedToken => |*x| return x.render(tree, stream),
Expand Down Expand Up @@ -114,7 +114,7 @@ pub const Error = union(enum) {
token: TokenIndex,
expected_id: @TagType(Token.Id),

pub fn render(self: *const ExpectedToken, tree: *Tree, stream: var) !void {
pub fn render(self: *const ExpectedToken, tree: *Tree, stream: anytype) !void {
const found_token = tree.tokens.at(self.token);
if (found_token.id == .Invalid) {
return stream.print("expected '{}', found invalid bytes", .{self.expected_id.symbol()});
Expand All @@ -129,7 +129,7 @@ pub const Error = union(enum) {
token: TokenIndex,
type_spec: *Node.TypeSpec,

pub fn render(self: *const ExpectedToken, tree: *Tree, stream: var) !void {
pub fn render(self: *const ExpectedToken, tree: *Tree, stream: anytype) !void {
try stream.write("invalid type specifier '");
try type_spec.spec.print(tree, stream);
const token_name = tree.tokens.at(self.token).id.symbol();
Expand All @@ -141,7 +141,7 @@ pub const Error = union(enum) {
kw: TokenIndex,
name: TokenIndex,

pub fn render(self: *const ExpectedToken, tree: *Tree, stream: var) !void {
pub fn render(self: *const ExpectedToken, tree: *Tree, stream: anytype) !void {
return stream.print("must use '{}' tag to refer to type '{}'", .{ tree.slice(kw), tree.slice(name) });
}
};
Expand All @@ -150,7 +150,7 @@ pub const Error = union(enum) {
return struct {
token: TokenIndex,

pub fn render(self: *const @This(), tree: *Tree, stream: var) !void {
pub fn render(self: *const @This(), tree: *Tree, stream: anytype) !void {
const actual_token = tree.tokens.at(self.token);
return stream.print(msg, .{actual_token.id.symbol()});
}
Expand All @@ -163,7 +163,7 @@ pub const Error = union(enum) {

token: TokenIndex,

pub fn render(self: *const ThisError, tokens: *Tree.TokenList, stream: var) !void {
pub fn render(self: *const ThisError, tokens: *Tree.TokenList, stream: anytype) !void {
return stream.write(msg);
}
};
Expand Down Expand Up @@ -317,7 +317,7 @@ pub const Node = struct {
sym_type: *Type,
},

pub fn print(self: *@This(), self: *const @This(), tree: *Tree, stream: var) !void {
pub fn print(self: *@This(), self: *const @This(), tree: *Tree, stream: anytype) !void {
switch (self.spec) {
.None => unreachable,
.Void => |index| try stream.write(tree.slice(index)),
Expand Down
2 changes: 1 addition & 1 deletion lib/std/cache_hash.zig
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub const CacheHash = struct {

/// Convert the input value into bytes and record it as a dependency of the
/// process being cached
pub fn add(self: *CacheHash, val: var) void {
pub fn add(self: *CacheHash, val: anytype) void {
assert(self.manifest_file == null);

const valPtr = switch (@typeInfo(@TypeOf(val))) {
Expand Down
6 changes: 3 additions & 3 deletions lib/std/comptime_string_map.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const mem = std.mem;
/// `kvs` expects a list literal containing list literals or an array/slice of structs
/// where `.@"0"` is the `[]const u8` key and `.@"1"` is the associated value of type `V`.
/// TODO: https://github.com/ziglang/zig/issues/4335
pub fn ComptimeStringMap(comptime V: type, comptime kvs: var) type {
pub fn ComptimeStringMap(comptime V: type, comptime kvs: anytype) type {
const precomputed = comptime blk: {
@setEvalBranchQuota(2000);
const KV = struct {
Expand Down Expand Up @@ -126,7 +126,7 @@ test "ComptimeStringMap slice of structs" {
testMap(map);
}

fn testMap(comptime map: var) void {
fn testMap(comptime map: anytype) void {
std.testing.expectEqual(TestEnum.A, map.get("have").?);
std.testing.expectEqual(TestEnum.B, map.get("nothing").?);
std.testing.expect(null == map.get("missing"));
Expand Down Expand Up @@ -165,7 +165,7 @@ test "ComptimeStringMap void value type, list literal of list literals" {
testSet(map);
}

fn testSet(comptime map: var) void {
fn testSet(comptime map: anytype) void {
std.testing.expectEqual({}, map.get("have").?);
std.testing.expectEqual({}, map.get("nothing").?);
std.testing.expect(null == map.get("missing"));
Expand Down
12 changes: 6 additions & 6 deletions lib/std/crypto/benchmark.zig
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const hashes = [_]Crypto{
Crypto{ .ty = crypto.Blake3, .name = "blake3" },
};

pub fn benchmarkHash(comptime Hash: var, comptime bytes: comptime_int) !u64 {
pub fn benchmarkHash(comptime Hash: anytype, comptime bytes: comptime_int) !u64 {
var h = Hash.init();

var block: [Hash.digest_length]u8 = undefined;
Expand All @@ -56,7 +56,7 @@ const macs = [_]Crypto{
Crypto{ .ty = crypto.HmacSha256, .name = "hmac-sha256" },
};

pub fn benchmarkMac(comptime Mac: var, comptime bytes: comptime_int) !u64 {
pub fn benchmarkMac(comptime Mac: anytype, comptime bytes: comptime_int) !u64 {
std.debug.assert(32 >= Mac.mac_length and 32 >= Mac.minimum_key_length);

var in: [1 * MiB]u8 = undefined;
Expand All @@ -81,7 +81,7 @@ pub fn benchmarkMac(comptime Mac: var, comptime bytes: comptime_int) !u64 {

const exchanges = [_]Crypto{Crypto{ .ty = crypto.X25519, .name = "x25519" }};

pub fn benchmarkKeyExchange(comptime DhKeyExchange: var, comptime exchange_count: comptime_int) !u64 {
pub fn benchmarkKeyExchange(comptime DhKeyExchange: anytype, comptime exchange_count: comptime_int) !u64 {
std.debug.assert(DhKeyExchange.minimum_key_length >= DhKeyExchange.secret_length);

var in: [DhKeyExchange.minimum_key_length]u8 = undefined;
Expand Down Expand Up @@ -166,21 +166,21 @@ pub fn main() !void {
inline for (hashes) |H| {
if (filter == null or std.mem.indexOf(u8, H.name, filter.?) != null) {
const throughput = try benchmarkHash(H.ty, mode(32 * MiB));
try stdout.print("{:>11}: {:5} MiB/s\n", .{H.name, throughput / (1 * MiB)});
try stdout.print("{:>11}: {:5} MiB/s\n", .{ H.name, throughput / (1 * MiB) });
}
}

inline for (macs) |M| {
if (filter == null or std.mem.indexOf(u8, M.name, filter.?) != null) {
const throughput = try benchmarkMac(M.ty, mode(128 * MiB));
try stdout.print("{:>11}: {:5} MiB/s\n", .{M.name, throughput / (1 * MiB)});
try stdout.print("{:>11}: {:5} MiB/s\n", .{ M.name, throughput / (1 * MiB) });
}
}

inline for (exchanges) |E| {
if (filter == null or std.mem.indexOf(u8, E.name, filter.?) != null) {
const throughput = try benchmarkKeyExchange(E.ty, mode(1000));
try stdout.print("{:>11}: {:5} exchanges/s\n", .{E.name, throughput});
try stdout.print("{:>11}: {:5} exchanges/s\n", .{ E.name, throughput });
}
}
}
2 changes: 1 addition & 1 deletion lib/std/crypto/test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const mem = std.mem;
const fmt = std.fmt;

// Hash using the specified hasher `H` asserting `expected == H(input)`.
pub fn assertEqualHash(comptime Hasher: var, comptime expected: []const u8, input: []const u8) void {
pub fn assertEqualHash(comptime Hasher: anytype, comptime expected: []const u8, input: []const u8) void {
var h: [expected.len / 2]u8 = undefined;
Hasher.hash(input, h[0..]);

Expand Down
24 changes: 12 additions & 12 deletions lib/std/debug.zig
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub const warn = print;

/// Print to stderr, unbuffered, and silently returning on failure. Intended
/// for use in "printf debugging." Use `std.log` functions for proper logging.
pub fn print(comptime fmt: []const u8, args: var) void {
pub fn print(comptime fmt: []const u8, args: anytype) void {
const held = stderr_mutex.acquire();
defer held.release();
const stderr = io.getStdErr().writer();
Expand Down Expand Up @@ -223,7 +223,7 @@ pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}

pub fn panic(comptime format: []const u8, args: var) noreturn {
pub fn panic(comptime format: []const u8, args: anytype) noreturn {
@setCold(true);
// TODO: remove conditional once wasi / LLVM defines __builtin_return_address
const first_trace_addr = if (builtin.os.tag == .wasi) null else @returnAddress();
Expand All @@ -241,7 +241,7 @@ var panic_mutex = std.Mutex.init();
/// This is used to catch and handle panics triggered by the panic handler.
threadlocal var panic_stage: usize = 0;

pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, comptime format: []const u8, args: var) noreturn {
pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, comptime format: []const u8, args: anytype) noreturn {
@setCold(true);

if (enable_segfault_handler) {
Expand Down Expand Up @@ -306,7 +306,7 @@ const RESET = "\x1b[0m";

pub fn writeStackTrace(
stack_trace: builtin.StackTrace,
out_stream: var,
out_stream: anytype,
allocator: *mem.Allocator,
debug_info: *DebugInfo,
tty_config: TTY.Config,
Expand Down Expand Up @@ -384,7 +384,7 @@ pub const StackIterator = struct {
};

pub fn writeCurrentStackTrace(
out_stream: var,
out_stream: anytype,
debug_info: *DebugInfo,
tty_config: TTY.Config,
start_addr: ?usize,
Expand All @@ -399,7 +399,7 @@ pub fn writeCurrentStackTrace(
}

pub fn writeCurrentStackTraceWindows(
out_stream: var,
out_stream: anytype,
debug_info: *DebugInfo,
tty_config: TTY.Config,
start_addr: ?usize,
Expand Down Expand Up @@ -435,7 +435,7 @@ pub const TTY = struct {
// TODO give this a payload of file handle
windows_api,

fn setColor(conf: Config, out_stream: var, color: Color) void {
fn setColor(conf: Config, out_stream: anytype, color: Color) void {
nosuspend switch (conf) {
.no_color => return,
.escape_codes => switch (color) {
Expand Down Expand Up @@ -555,7 +555,7 @@ fn machoSearchSymbols(symbols: []const MachoSymbol, address: usize) ?*const Mach
}

/// TODO resources https://github.com/ziglang/zig/issues/4353
pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: var, address: usize, tty_config: TTY.Config) !void {
pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: anytype, address: usize, tty_config: TTY.Config) !void {
const module = debug_info.getModuleForAddress(address) catch |err| switch (err) {
error.MissingDebugInfo, error.InvalidDebugInfo => {
return printLineInfo(
Expand Down Expand Up @@ -586,13 +586,13 @@ pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: var, address: us
}

fn printLineInfo(
out_stream: var,
out_stream: anytype,
line_info: ?LineInfo,
address: usize,
symbol_name: []const u8,
compile_unit_name: []const u8,
tty_config: TTY.Config,
comptime printLineFromFile: var,
comptime printLineFromFile: anytype,
) !void {
nosuspend {
tty_config.setColor(out_stream, .White);
Expand Down Expand Up @@ -820,7 +820,7 @@ fn readCoffDebugInfo(allocator: *mem.Allocator, coff_file: File) !ModuleDebugInf
}
}

fn readSparseBitVector(stream: var, allocator: *mem.Allocator) ![]usize {
fn readSparseBitVector(stream: anytype, allocator: *mem.Allocator) ![]usize {
const num_words = try stream.readIntLittle(u32);
var word_i: usize = 0;
var list = ArrayList(usize).init(allocator);
Expand Down Expand Up @@ -1004,7 +1004,7 @@ fn readMachODebugInfo(allocator: *mem.Allocator, macho_file: File) !ModuleDebugI
};
}

fn printLineFromFileAnyOs(out_stream: var, line_info: LineInfo) !void {
fn printLineFromFileAnyOs(out_stream: anytype, line_info: LineInfo) !void {
// Need this to always block even in async I/O mode, because this could potentially
// be called from e.g. the event loop code crashing.
var f = try fs.cwd().openFile(line_info.file_name, .{ .intended_io_mode = .blocking });
Expand Down
Loading

0 comments on commit b7f0219

Please sign in to comment.