Skip to content

Commit

Permalink
Merge pull request #9106 from Vexu/fmt
Browse files Browse the repository at this point in the history
Add formatting check to CI pipeline
  • Loading branch information
andrewrk committed Jun 14, 2021
2 parents df4f11f + e63ff4f commit 86ebd4b
Show file tree
Hide file tree
Showing 33 changed files with 859 additions and 576 deletions.
3 changes: 3 additions & 0 deletions ci/azure/linux_script
Expand Up @@ -59,6 +59,9 @@ unset CXX

make $JOBS install

# look for formatting errors
release/bin/zig fmt --check --ast-check .. || (echo "Please run 'zig fmt' to fix the non-conforming files listed above." && false)

# Here we rebuild zig but this time using the Zig binary we just now produced to
# build zig1.o rather than relying on the one built with stage0. See
# https://github.com/ziglang/zig/issues/6830 for more details.
Expand Down
16 changes: 8 additions & 8 deletions lib/std/Thread/Futex.zig
Expand Up @@ -84,7 +84,7 @@ else

const WindowsFutex = struct {
const windows = std.os.windows;

fn wait(ptr: *const Atomic(u32), expect: u32, timeout: ?u64) error{TimedOut}!void {
var timeout_value: windows.LARGE_INTEGER = undefined;
var timeout_ptr: ?*const windows.LARGE_INTEGER = null;
Expand Down Expand Up @@ -299,7 +299,7 @@ const PosixFutex = struct {
state: State = .empty,
cond: std.c.pthread_cond_t = .{},
mutex: std.c.pthread_mutex_t = .{},

const Self = @This();
const State = enum {
empty,
Expand Down Expand Up @@ -381,7 +381,7 @@ test "Futex - wait/wake" {

const wait_noop_result = Futex.wait(&value, 0, 0);
try testing.expectError(error.TimedOut, wait_noop_result);

const wait_longer_result = Futex.wait(&value, 0, std.time.ns_per_ms);
try testing.expectError(error.TimedOut, wait_longer_result);

Expand Down Expand Up @@ -416,7 +416,7 @@ test "Futex - Signal" {
const Thread = struct {
tx: *Self,
rx: *Self,

const start_value = 1;

fn run(self: Thread) void {
Expand Down Expand Up @@ -472,7 +472,7 @@ test "Futex - Broadcast" {
self.broadcast.store(BROADCAST_RECEIVED, .Release);
Futex.wake(&self.broadcast, 1);
}
}
}

fn run() !void {
var self = Self{};
Expand Down Expand Up @@ -542,7 +542,7 @@ test "Futex - Chain" {
if (chain.index + 1 < chain.self.threads.len) {
next_signal = &chain.self.threads[chain.index + 1].signal;
}

this_signal.wait();
next_signal.notify();
}
Expand All @@ -554,7 +554,7 @@ test "Futex - Chain" {
for (self.threads) |*entry, index| {
entry.signal = .{};
entry.thread = try std.Thread.spawn(Chain.run, .{
.self = &self,
.self = &self,
.index = index,
});
}
Expand All @@ -567,4 +567,4 @@ test "Futex - Chain" {
}
}
}).run();
}
}
4 changes: 2 additions & 2 deletions lib/std/c/darwin.zig
Expand Up @@ -246,7 +246,7 @@ pub const ULF_WAIT_ADAPTIVE_SPIN = 0x40000;

pub extern "c" fn __ulock_wait2(op: u32, addr: ?*const c_void, val: u64, timeout_us: u32, val2: u64) c_int;
pub extern "c" fn __ulock_wait(op: u32, addr: ?*const c_void, val: u64, timeout_us: u32) c_int;
pub extern "c" fn __ulock_wake(op: u32, addr: ?*const c_void, val: u64) c_int;
pub extern "c" fn __ulock_wake(op: u32, addr: ?*const c_void, val: u64) c_int;

pub const OS_UNFAIR_LOCK_INIT = os_unfair_lock{};
pub const os_unfair_lock_t = *os_unfair_lock;
Expand All @@ -258,4 +258,4 @@ pub extern "c" fn os_unfair_lock_lock(o: os_unfair_lock_t) void;
pub extern "c" fn os_unfair_lock_unlock(o: os_unfair_lock_t) void;
pub extern "c" fn os_unfair_lock_trylock(o: os_unfair_lock_t) bool;
pub extern "c" fn os_unfair_lock_assert_owner(o: os_unfair_lock_t) void;
pub extern "c" fn os_unfair_lock_assert_not_owner(o: os_unfair_lock_t) void;
pub extern "c" fn os_unfair_lock_assert_not_owner(o: os_unfair_lock_t) void;
15 changes: 14 additions & 1 deletion lib/std/fmt/parse_float.zig
Expand Up @@ -34,7 +34,7 @@
// - Only supports round-to-zero
// - Does not handle denormals

const std = @import("../std.zig");
const std = @import("std");
const ascii = std.ascii;

// The mantissa field in FloatRepr is 64bit wide and holds only 19 digits
Expand Down Expand Up @@ -231,6 +231,8 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
} else if (c == '.') {
i += 1;
state = .LeadingFractionalZeros;
} else if (c == '_') {
i += 1;
} else {
state = .MantissaIntegral;
}
Expand Down Expand Up @@ -259,6 +261,8 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
} else if (c == '.') {
i += 1;
state = .MantissaFractional;
} else if (c == '_') {
i += 1;
} else {
state = .MantissaFractional;
}
Expand All @@ -276,13 +280,17 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
} else if (c == 'e' or c == 'E') {
i += 1;
state = .ExponentSign;
} else if (c == '_') {
i += 1;
} else {
state = .ExponentSign;
}
},
.ExponentSign => {
if (c == '+') {
i += 1;
} else if (c == '_') {
return error.InvalidCharacter;
} else if (c == '-') {
negative_exp = true;
i += 1;
Expand All @@ -293,6 +301,8 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
.LeadingExponentZeros => {
if (c == '0') {
i += 1;
} else if (c == '_') {
i += 1;
} else {
state = .Exponent;
}
Expand All @@ -304,6 +314,8 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
exponent += @intCast(i32, c - '0');
}

i += 1;
} else if (c == '_') {
i += 1;
} else {
return error.InvalidCharacter;
Expand Down Expand Up @@ -405,6 +417,7 @@ test "fmt.parseFloat" {
try expectEqual(try parseFloat(T, "-INF"), -std.math.inf(T));

try expectEqual(try parseFloat(T, "0.4e0066999999999999999999999999999999999999999999999999999"), std.math.inf(T));
try expect(approxEqAbs(T, try parseFloat(T, "0_1_2_3_4_5_6.7_8_9_0_0_0e0_0_1_0"), @as(T, 123456.789000e10), epsilon));

if (T != f16) {
try expect(approxEqAbs(T, try parseFloat(T, "1e-2"), 0.01, epsilon));
Expand Down

0 comments on commit 86ebd4b

Please sign in to comment.