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 2824728
Show file tree
Hide file tree
Showing 150 changed files with 530 additions and 522 deletions.
8 changes: 4 additions & 4 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub fn build(b: *Builder) !void {
test_step.dependOn(docs_step);
}

fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
fn dependOnLib(b: *Builder, lib_exe_obj: anytype, dep: LibraryDep) void {
for (dep.libdirs.items) |lib_dir| {
lib_exe_obj.addLibPath(lib_dir);
}
Expand Down Expand Up @@ -193,7 +193,7 @@ fn fileExists(filename: []const u8) !bool {
return true;
}

fn addCppLib(b: *Builder, lib_exe_obj: var, cmake_binary_dir: []const u8, lib_name: []const u8) void {
fn addCppLib(b: *Builder, lib_exe_obj: anytype, cmake_binary_dir: []const u8, lib_name: []const u8) void {
lib_exe_obj.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
cmake_binary_dir,
"zig_cpp",
Expand Down Expand Up @@ -275,7 +275,7 @@ fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
return result;
}

fn configureStage2(b: *Builder, exe: var, ctx: Context) !void {
fn configureStage2(b: *Builder, exe: anytype, ctx: Context) !void {
exe.addIncludeDir("src");
exe.addIncludeDir(ctx.cmake_binary_dir);
addCppLib(b, exe, ctx.cmake_binary_dir, "zig_cpp");
Expand Down Expand Up @@ -340,7 +340,7 @@ fn configureStage2(b: *Builder, exe: var, ctx: Context) !void {
fn addCxxKnownPath(
b: *Builder,
ctx: Context,
exe: var,
exe: anytype,
objname: []const u8,
errtxt: ?[]const u8,
) !void {
Expand Down
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
Loading

0 comments on commit 2824728

Please sign in to comment.