authorgravatar for emekankurumeh@outlook.comemekoi <emekankurumeh@outlook.com> 2019-05-19 15:26:43-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-19 16:33:31-04:00
log1c73c08298fc3a19886038d935e45cf74ba152fb
tree0583f8c9b0118e3e9f3c0268d6e6ea14063cd363
parent6672ee9eb39a1cd9a3d6874ac1fb6de347ee2d33

ran zig fmt on stdlib


8 files changed, 71 insertions(+), 149 deletions(-)

std/debug.zig+10-8
......@@ -1490,14 +1490,16 @@ fn parseFormValueTargetAddrSize(in_stream: var) !u64 {
14901490}
14911491
14921492fn parseFormValueRef(allocator: *mem.Allocator, in_stream: var, size: i32) !FormValue {
1493 return FormValue{ .Ref = switch (size) {
1494 1 => try in_stream.readIntLittle(u8),
1495 2 => try in_stream.readIntLittle(u16),
1496 4 => try in_stream.readIntLittle(u32),
1497 8 => try in_stream.readIntLittle(u64),
1498 -1 => try leb.readULEB128(u64, in_stream),
1499 else => unreachable,
1500 } };
1493 return FormValue{
1494 .Ref = switch (size) {
1495 1 => try in_stream.readIntLittle(u8),
1496 2 => try in_stream.readIntLittle(u16),
1497 4 => try in_stream.readIntLittle(u32),
1498 8 => try in_stream.readIntLittle(u64),
1499 -1 => try leb.readULEB128(u64, in_stream),
1500 else => unreachable,
1501 },
1502 };
15011503}
15021504
15031505fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64: bool) anyerror!FormValue {
std/io.zig+12-8
......@@ -1116,10 +1116,12 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
11161116 pub const Stream = InStream(Error);
11171117
11181118 pub fn init(in_stream: *Stream) Self {
1119 return Self{ .in_stream = switch (packing) {
1120 .Bit => BitInStream(endian, Stream.Error).init(in_stream),
1121 .Byte => in_stream,
1122 } };
1119 return Self{
1120 .in_stream = switch (packing) {
1121 .Bit => BitInStream(endian, Stream.Error).init(in_stream),
1122 .Byte => in_stream,
1123 },
1124 };
11231125 }
11241126
11251127 pub fn alignToByte(self: *Self) void {
......@@ -1325,10 +1327,12 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
13251327 pub const Stream = OutStream(Error);
13261328
13271329 pub fn init(out_stream: *Stream) Self {
1328 return Self{ .out_stream = switch (packing) {
1329 .Bit => BitOutStream(endian, Stream.Error).init(out_stream),
1330 .Byte => out_stream,
1331 } };
1330 return Self{
1331 .out_stream = switch (packing) {
1332 .Bit => BitOutStream(endian, Stream.Error).init(out_stream),
1333 .Byte => out_stream,
1334 },
1335 };
13321336 }
13331337
13341338 /// Flushes any unwritten bits to the stream
std/os/linux/tls.zig+1-1
......@@ -114,7 +114,7 @@ pub fn setThreadPointer(addr: usize) void {
114114 .aarch64 => {
115115 asm volatile (
116116 \\ msr tpidr_el0, %[addr]
117 :
117 :
118118 : [addr] "r" (addr)
119119 );
120120 },
std/special/bootstrap.zig+4-1
......@@ -8,7 +8,10 @@ const assert = std.debug.assert;
88
99var argc_ptr: [*]usize = undefined;
1010
11const is_wasm = switch (builtin.arch) { .wasm32, .wasm64 => true, else => false};
11const is_wasm = switch (builtin.arch) {
12 .wasm32, .wasm64 => true,
13 else => false,
14};
1215
1316comptime {
1417 if (builtin.link_libc) {
std/special/c.zig+8-2
......@@ -8,8 +8,14 @@ const std = @import("std");
88const builtin = @import("builtin");
99const maxInt = std.math.maxInt;
1010
11const is_wasm = switch (builtin.arch) { .wasm32, .wasm64 => true, else => false};
12const is_freestanding = switch (builtin.os) { .freestanding => true, else => false };
11const is_wasm = switch (builtin.arch) {
12 .wasm32, .wasm64 => true,
13 else => false,
14};
15const is_freestanding = switch (builtin.os) {
16 .freestanding => true,
17 else => false,
18};
1319comptime {
1420 if (is_freestanding and is_wasm and builtin.link_libc) {
1521 @export("_start", wasm_start, .Strong);
std/special/compiler_rt/extendXfYf2.zig+1-1
......@@ -76,7 +76,7 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @t
7676 // renormalize the significand and clear the leading bit, then insert
7777 // the correct adjusted exponent in the destination type.
7878 const scale: u32 = @clz(src_rep_t, aAbs) -
79 @clz(src_rep_t, src_rep_t(srcMinNormal));
79 @clz(src_rep_t, src_rep_t(srcMinNormal));
8080 absResult = dst_rep_t(aAbs) << @intCast(DstShift, dstSigBits - srcSigBits + scale);
8181 absResult ^= dstMinNormal;
8282 const resultExponent: u32 = dstExpBias - srcExpBias - scale + 1;
std/valgrind/callgrind.zig+9-32
......@@ -10,70 +10,48 @@ pub const CallgrindClientRequest = extern enum {
1010 StopInstrumentation,
1111};
1212
13fn doCallgrindClientRequestExpr(default: usize, request: CallgrindClientRequest,
14 a1: usize, a2: usize, a3: usize, a4: usize, a5: usize
15 ) usize
16{
17 return valgrind.doClientRequest(
18 default,
19 @intCast(usize, @enumToInt(request)),
20 a1, a2, a3, a4, a5);
13fn doCallgrindClientRequestExpr(default: usize, request: CallgrindClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) usize {
14 return valgrind.doClientRequest(default, @intCast(usize, @enumToInt(request)), a1, a2, a3, a4, a5);
2115}
2216
23fn doCallgrindClientRequestStmt(request: CallgrindClientRequest,
24 a1: usize, a2: usize, a3: usize, a4: usize, a5: usize
25 ) void
26{
17fn doCallgrindClientRequestStmt(request: CallgrindClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) void {
2718 _ = doCallgrindClientRequestExpr(0, request, a1, a2, a3, a4, a5);
2819}
2920
30
31
3221/// Dump current state of cost centers, and zero them afterwards
3322pub fn dumpStats() void {
34 doCallgrindClientRequestStmt(CallgrindClientRequest.DumpStats,
35 0, 0, 0, 0, 0);
23 doCallgrindClientRequestStmt(CallgrindClientRequest.DumpStats, 0, 0, 0, 0, 0);
3624}
3725
38
3926/// Dump current state of cost centers, and zero them afterwards.
4027/// The argument is appended to a string stating the reason which triggered
4128/// the dump. This string is written as a description field into the
4229/// profile data dump.
4330pub fn dumpStatsAt(pos_str: [*]u8) void {
44 doCallgrindClientRequestStmt(CallgrindClientRequest.DumpStatsAt,
45 @ptrToInt(pos_str),
46 0, 0, 0, 0);
31 doCallgrindClientRequestStmt(CallgrindClientRequest.DumpStatsAt, @ptrToInt(pos_str), 0, 0, 0, 0);
4732}
4833
49
5034/// Zero cost centers
5135pub fn zeroStats() void {
52 doCallgrindClientRequestStmt(CallgrindClientRequest.ZeroStats,
53 0, 0, 0, 0, 0);
36 doCallgrindClientRequestStmt(CallgrindClientRequest.ZeroStats, 0, 0, 0, 0, 0);
5437}
5538
56
5739/// Toggles collection state.
5840/// The collection state specifies whether the happening of events
5941/// should be noted or if they are to be ignored. Events are noted
6042/// by increment of counters in a cost center
6143pub fn toggleCollect() void {
62 doCallgrindClientRequestStmt(CallgrindClientRequest.ToggleCollect,
63 0, 0, 0, 0, 0);
44 doCallgrindClientRequestStmt(CallgrindClientRequest.ToggleCollect, 0, 0, 0, 0, 0);
6445}
6546
66
6747/// Start full callgrind instrumentation if not already switched on.
6848/// When cache simulation is done, it will flush the simulated cache;
6949/// this will lead to an artificial cache warmup phase afterwards with
7050/// cache misses which would not have happened in reality.
7151pub fn startInstrumentation() void {
72 doCallgrindClientRequestStmt(CallgrindClientRequest.StartInstrumentation,
73 0, 0, 0, 0, 0);
52 doCallgrindClientRequestStmt(CallgrindClientRequest.StartInstrumentation, 0, 0, 0, 0, 0);
7453}
7554
76
7755/// Stop full callgrind instrumentation if not already switched off.
7856/// This flushes Valgrinds translation cache, and does no additional
7957/// instrumentation afterwards, which effectivly will run at the same
......@@ -82,6 +60,5 @@ pub fn startInstrumentation() void {
8260/// To start Callgrind in this mode to ignore the setup phase, use
8361/// the option "--instr-atstart=no".
8462pub fn stopInstrumentation() void {
85 doCallgrindClientRequestStmt(CallgrindClientRequest.StopInstrumentation,
86 0, 0, 0, 0, 0);
63 doCallgrindClientRequestStmt(CallgrindClientRequest.StopInstrumentation, 0, 0, 0, 0, 0);
8764}
std/valgrind/memcheck.zig+26-96
......@@ -19,149 +19,102 @@ pub const MemCheckClientRequest = extern enum {
1919 DisableAddrErrorReportingInRange,
2020};
2121
22fn doMemCheckClientRequestExpr(default: usize, request: MemCheckClientRequest,
23 a1: usize, a2: usize, a3: usize, a4: usize, a5: usize
24 ) usize
25{
26 return valgrind.doClientRequest(
27 default,
28 @intCast(usize, @enumToInt(request)),
29 a1, a2, a3, a4, a5);
30}
31
32fn doMemCheckClientRequestStmt(request: MemCheckClientRequest,
33 a1: usize, a2: usize, a3: usize, a4: usize, a5: usize
34 ) void
35{
36 _ = doMemCheckClientRequestExpr(0, request, a1, a2, a3, a4, a5);
22fn doMemCheckClientRequestExpr(default: usize, request: MemCheckClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) usize {
23 return valgrind.doClientRequest(default, @intCast(usize, @enumToInt(request)), a1, a2, a3, a4, a5);
3724}
3825
39
26fn doMemCheckClientRequestStmt(request: MemCheckClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) void {
27 _ = doMemCheckClientRequestExpr(0, request, a1, a2, a3, a4, a5);
28}
4029
4130/// Mark memory at qzz.ptr as unaddressable for qzz.len bytes.
4231/// This returns -1 when run on Valgrind and 0 otherwise.
4332pub fn makeMemNoAccess(qzz: []u8) i1 {
4433 return @intCast(i1, doMemCheckClientRequestExpr(0, // default return
45 MemCheckClientRequest.MakeMemNoAccess,
46 @ptrToInt(qzz.ptr), qzz.len,
47 0, 0, 0));
34 MemCheckClientRequest.MakeMemNoAccess, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0));
4835}
4936
50
5137/// Similarly, mark memory at qzz.ptr as addressable but undefined
5238/// for qzz.len bytes.
5339/// This returns -1 when run on Valgrind and 0 otherwise.
5440pub fn makeMemUndefined(qzz: []u8) i1 {
5541 return @intCast(i1, doMemCheckClientRequestExpr(0, // default return
56 MemCheckClientRequest.MakeMemUndefined,
57 @ptrToInt(qzz.ptr), qzz.len,
58 0, 0, 0));
42 MemCheckClientRequest.MakeMemUndefined, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0));
5943}
6044
61
6245/// Similarly, mark memory at qzz.ptr as addressable and defined
6346/// for qzz.len bytes.
6447pub fn makeMemDefined(qzz: []u8) i1 {
65// This returns -1 when run on Valgrind and 0 otherwise.
48 // This returns -1 when run on Valgrind and 0 otherwise.
6649 return @intCast(i1, doMemCheckClientRequestExpr(0, // default return
67 MemCheckClientRequest.MakeMemDefined,
68 @ptrToInt(qzz.ptr), qzz.len,
69 0, 0, 0));
50 MemCheckClientRequest.MakeMemDefined, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0));
7051}
7152
72
7353/// Similar to makeMemDefined except that addressability is
7454/// not altered: bytes which are addressable are marked as defined,
7555/// but those which are not addressable are left unchanged.
7656/// This returns -1 when run on Valgrind and 0 otherwise.
7757pub fn makeMemDefinedIfAddressable(qzz: []u8) i1 {
7858 return @intCast(i1, doMemCheckClientRequestExpr(0, // default return
79 MemCheckClientRequest.MakeMemDefinedIfAddressable,
80 @ptrToInt(qzz.ptr), qzz.len,
81 0, 0, 0));
59 MemCheckClientRequest.MakeMemDefinedIfAddressable, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0));
8260}
8361
84
8562/// Create a block-description handle. The description is an ascii
8663/// string which is included in any messages pertaining to addresses
8764/// within the specified memory range. Has no other effect on the
8865/// properties of the memory range.
8966pub fn createBlock(qzz: []u8, desc: [*]u8) usize {
9067 return doMemCheckClientRequestExpr(0, // default return
91 MemCheckClientRequest.CreateBlock,
92 @ptrToInt(qzz.ptr), qzz.len, @ptrToInt(desc),
93 0, 0);
68 MemCheckClientRequest.CreateBlock, @ptrToInt(qzz.ptr), qzz.len, @ptrToInt(desc), 0, 0);
9469}
9570
96
9771/// Discard a block-description-handle. Returns 1 for an
9872/// invalid handle, 0 for a valid handle.
9973pub fn discard(blkindex) bool {
10074 return doMemCheckClientRequestExpr(0, // default return
101 MemCheckClientRequest.Discard,
102 0, blkindex,
103 0, 0, 0) != 0;
75 MemCheckClientRequest.Discard, 0, blkindex, 0, 0, 0) != 0;
10476}
10577
106
10778/// Check that memory at qzz.ptr is addressable for qzz.len bytes.
10879/// If suitable addressibility is not established, Valgrind prints an
10980/// error message and returns the address of the first offending byte.
11081/// Otherwise it returns zero.
11182pub fn checkMemIsAddressable(qzz: []u8) usize {
112 return doMemCheckClientRequestExpr(0,
113 MemCheckClientRequest.CheckMemIsAddressable,
114 @ptrToInt(qzz.ptr), qzz.len,
115 0, 0, 0);
83 return doMemCheckClientRequestExpr(0, MemCheckClientRequest.CheckMemIsAddressable, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0);
11684}
11785
118
11986/// Check that memory at qzz.ptr is addressable and defined for
12087/// qzz.len bytes. If suitable addressibility and definedness are not
12188/// established, Valgrind prints an error message and returns the
12289/// address of the first offending byte. Otherwise it returns zero.
12390pub fn checkMemIsDefined(qzz: []u8) usize {
124 return doMemCheckClientRequestExpr(0,
125 MemCheckClientRequest.CheckMemIsDefined,
126 @ptrToInt(qzz.ptr), qzz.len,
127 0, 0, 0);
91 return doMemCheckClientRequestExpr(0, MemCheckClientRequest.CheckMemIsDefined, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0);
12892}
12993
13094/// Do a full memory leak check (like --leak-check=full) mid-execution.
13195pub fn doLeakCheck() void {
132 doMemCheckClientRequestStmt(MemCheckClientRequest.DO_LEAK_CHECK,
133 0, 0,
134 0, 0, 0);
96 doMemCheckClientRequestStmt(MemCheckClientRequest.DO_LEAK_CHECK, 0, 0, 0, 0, 0);
13597}
13698
13799/// Same as doLeakCheck() but only showing the entries for
138100/// which there was an increase in leaked bytes or leaked nr of blocks
139101/// since the previous leak search.
140102pub fn doAddedLeakCheck() void {
141 doMemCheckClientRequestStmt(MemCheckClientRequest.DO_LEAK_CHECK,
142 0, 1,
143 0, 0, 0);
103 doMemCheckClientRequestStmt(MemCheckClientRequest.DO_LEAK_CHECK, 0, 1, 0, 0, 0);
144104}
145105
146
147106/// Same as doAddedLeakCheck() but showing entries with
148107/// increased or decreased leaked bytes/blocks since previous leak
149108/// search.
150109pub fn doChangedLeakCheck() void {
151 doMemCheckClientRequestStmt(MemCheckClientRequest.DO_LEAK_CHECK,
152 0, 2,
153 0, 0, 0);
110 doMemCheckClientRequestStmt(MemCheckClientRequest.DO_LEAK_CHECK, 0, 2, 0, 0, 0);
154111}
155112
156
157113/// Do a summary memory leak check (like --leak-check=summary) mid-execution.
158114pub fn doQuickLeakCheck() void {
159 doMemCheckClientRequestStmt(MemCheckClientRequest.DO_LEAK_CHECK,
160 1, 0,
161 0, 0, 0);
115 doMemCheckClientRequestStmt(MemCheckClientRequest.DO_LEAK_CHECK, 1, 0, 0, 0, 0);
162116}
163117
164
165118/// Return number of leaked, dubious, reachable and suppressed bytes found by
166119/// all previous leak checks.
167120const CountResult = struct {
......@@ -172,34 +125,27 @@ const CountResult = struct {
172125};
173126
174127pub fn countLeaks() CountResult {
175 var res = CountResult {
128 var res = CountResult{
176129 .leaked = 0,
177130 .dubious = 0,
178131 .reachable = 0,
179132 .suppressed = 0,
180133 };
181 doMemCheckClientRequestStmt(MemCheckClientRequest.CountLeaks,
182 &res.leaked, &res.dubious,
183 &res.reachable, &res.suppressed,
184 0);
134 doMemCheckClientRequestStmt(MemCheckClientRequest.CountLeaks, &res.leaked, &res.dubious, &res.reachable, &res.suppressed, 0);
185135 return res;
186136}
187137
188138pub fn countLeakBlocks() CountResult {
189 var res = CountResult {
139 var res = CountResult{
190140 .leaked = 0,
191141 .dubious = 0,
192142 .reachable = 0,
193143 .suppressed = 0,
194144 };
195 doMemCheckClientRequestStmt(MemCheckClientRequest.CountLeakBlocks,
196 &res.leaked, &res.dubious,
197 &res.reachable, &res.suppressed,
198 0);
145 doMemCheckClientRequestStmt(MemCheckClientRequest.CountLeakBlocks, &res.leaked, &res.dubious, &res.reachable, &res.suppressed, 0);
199146 return res;
200147}
201148
202
203149/// Get the validity data for addresses zza and copy it
204150/// into the provided zzvbits array. Return values:
205151/// 0 if not running on valgrind
......@@ -210,15 +156,9 @@ pub fn countLeakBlocks() CountResult {
210156/// impossible to segfault your system by using this call.
211157pub fn getVbits(zza: []u8, zzvbits: []u8) u2 {
212158 std.debug.assert(zzvbits.len >= zza.len / 8);
213 return @intCast(u2, doMemCheckClientRequestExpr(0,
214 MemCheckClientRequest.GetVbits,
215 @ptrToInt(zza.ptr),
216 @ptrToInt(zzvbits),
217 zza.len,
218 0, 0));
159 return @intCast(u2, doMemCheckClientRequestExpr(0, MemCheckClientRequest.GetVbits, @ptrToInt(zza.ptr), @ptrToInt(zzvbits), zza.len, 0, 0));
219160}
220161
221
222162/// Set the validity data for addresses zza, copying it
223163/// from the provided zzvbits array. Return values:
224164/// 0 if not running on valgrind
......@@ -229,27 +169,17 @@ pub fn getVbits(zza: []u8, zzvbits: []u8) u2 {
229169/// impossible to segfault your system by using this call.
230170pub fn setVbits(zzvbits: []u8, zza: []u8) u2 {
231171 std.debug.assert(zzvbits.len >= zza.len / 8);
232 return @intCast(u2, doMemCheckClientRequestExpr(0,
233 MemCheckClientRequest.SetVbits,
234 @ptrToInt(zza.ptr),
235 @ptrToInt(zzvbits),
236 zza.len,
237 0, 0));
172 return @intCast(u2, doMemCheckClientRequestExpr(0, MemCheckClientRequest.SetVbits, @ptrToInt(zza.ptr), @ptrToInt(zzvbits), zza.len, 0, 0));
238173}
239174
240
241175/// Disable and re-enable reporting of addressing errors in the
242176/// specified address range.
243177pub fn disableAddrErrorReportingInRange(qzz: []u8) usize {
244178 return doMemCheckClientRequestExpr(0, // default return
245 MemCheckClientRequest.DisableAddrErrorReportingInRange,
246 @ptrToInt(qzz.ptr), qzz.len,
247 0, 0, 0);
179 MemCheckClientRequest.DisableAddrErrorReportingInRange, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0);
248180}
249181
250182pub fn enableAddrErrorReportingInRange(qzz: []u8) usize {
251183 return doMemCheckClientRequestExpr(0, // default return
252 MemCheckClientRequest.EnableAddrErrorReportingInRange,
253 @ptrToInt(qzz.ptr), qzz.len,
254 0, 0, 0);
184 MemCheckClientRequest.EnableAddrErrorReportingInRange, @ptrToInt(qzz.ptr), qzz.len, 0, 0, 0);
255185}