| author | |
| committer | |
| log | 6a0f2227e8b40e3456d3c85c72f68f483b239af3 |
| tree | 11649e598ed1bc743ed946318fea1f47708d72d2 |
| parent | 7b0d826849f5def7b5c847a35e9e54ef81d70dc7 |
20 files changed, 302 insertions(+), 356 deletions(-)
lib/std/Build/Fuzz/WebServer.zig+14-24| ... | ... | @@ -100,8 +100,7 @@ fn accept(ws: *WebServer, connection: std.net.Server.Connection) void { |
| 100 | 100 | |
| 101 | 101 | var sr = connection.stream.reader(); |
| 102 | 102 | var rb: [0x4000]u8 = undefined; |
| 103 | var br: std.io.BufferedReader = undefined; | |
| 104 | br.init(sr.interface(), &rb); | |
| 103 | var br = sr.interface().buffered(&rb); | |
| 105 | 104 | |
| 106 | 105 | var sw = connection.stream.writer(); |
| 107 | 106 | var wb: [0x4000]u8 = undefined; |
| ... | ... | @@ -109,7 +108,6 @@ fn accept(ws: *WebServer, connection: std.net.Server.Connection) void { |
| 109 | 108 | |
| 110 | 109 | var server: std.http.Server = .init(&br, &bw); |
| 111 | 110 | var web_socket: std.http.WebSocket = undefined; |
| 112 | var send_buffer: [0x4000]u8 = undefined; | |
| 113 | 111 | var ws_recv_buffer: [0x4000]u8 align(4) = undefined; |
| 114 | 112 | while (server.state == .ready) { |
| 115 | 113 | var request = server.receiveHead() catch |err| switch (err) { |
| ... | ... | @@ -119,7 +117,7 @@ fn accept(ws: *WebServer, connection: std.net.Server.Connection) void { |
| 119 | 117 | return; |
| 120 | 118 | }, |
| 121 | 119 | }; |
| 122 | if (web_socket.init(&request, &send_buffer, &ws_recv_buffer) catch |err| { | |
| 120 | if (web_socket.init(&request, &ws_recv_buffer) catch |err| { | |
| 123 | 121 | log.err("initializing web socket: {s}", .{@errorName(err)}); |
| 124 | 122 | return; |
| 125 | 123 | }) { |
| ... | ... | @@ -281,19 +279,16 @@ fn buildWasmBinary( |
| 281 | 279 | try sendMessage(child.stdin.?, .update); |
| 282 | 280 | try sendMessage(child.stdin.?, .exit); |
| 283 | 281 | |
| 284 | const Header = std.zig.Server.Message.Header; | |
| 285 | 282 | var result: ?Path = null; |
| 286 | 283 | var result_error_bundle = std.zig.ErrorBundle.empty; |
| 287 | 284 | |
| 288 | const stdout = poller.fifo(.stdout); | |
| 289 | ||
| 285 | const stdout_br = poller.reader(.stdout); | |
| 290 | 286 | poll: while (true) { |
| 291 | while (stdout.readableLength() < @sizeOf(Header)) if (!try poller.poll()) break :poll; | |
| 292 | var header: Header = undefined; | |
| 293 | assert(stdout.read(std.mem.asBytes(&header)) == @sizeOf(Header)); | |
| 294 | while (stdout.readableLength() < header.bytes_len) if (!try poller.poll()) break :poll; | |
| 295 | const body = stdout.readableSliceOfLen(header.bytes_len); | |
| 296 | ||
| 287 | const Header = std.zig.Server.Message.Header; | |
| 288 | while (stdout_br.bufferContents().len < @sizeOf(Header)) if (!try poller.poll()) break :poll; | |
| 289 | const header = (stdout_br.takeStruct(Header) catch unreachable).*; | |
| 290 | while (stdout_br.bufferContents().len < header.bytes_len) if (!try poller.poll()) break :poll; | |
| 291 | const body = stdout_br.take(header.bytes_len) catch unreachable; | |
| 297 | 292 | switch (header.tag) { |
| 298 | 293 | .zig_version => { |
| 299 | 294 | if (!std.mem.eql(u8, builtin.zig_version_string, body)) { |
| ... | ... | @@ -330,15 +325,12 @@ fn buildWasmBinary( |
| 330 | 325 | }, |
| 331 | 326 | else => {}, // ignore other messages |
| 332 | 327 | } |
| 333 | ||
| 334 | stdout.discard(body.len); | |
| 335 | 328 | } |
| 336 | 329 | |
| 337 | const stderr = poller.fifo(.stderr); | |
| 338 | if (stderr.readableLength() > 0) { | |
| 339 | const owned_stderr = try stderr.toOwnedSlice(); | |
| 340 | defer gpa.free(owned_stderr); | |
| 341 | std.debug.print("{s}", .{owned_stderr}); | |
| 330 | const stderr_br = poller.reader(.stderr); | |
| 331 | const stderr_contents = stderr_br.bufferContents(); | |
| 332 | if (stderr_contents.len > 0) { | |
| 333 | std.debug.print("{s}", .{stderr_contents}); | |
| 342 | 334 | } |
| 343 | 335 | |
| 344 | 336 | // Send EOF to stdin. |
| ... | ... | @@ -484,9 +476,7 @@ fn serveSourcesTar(ws: *WebServer, request: *std.http.Server.Request) !void { |
| 484 | 476 | defer arena_instance.deinit(); |
| 485 | 477 | const arena = arena_instance.allocator(); |
| 486 | 478 | |
| 487 | var send_buffer: [0x4000]u8 = undefined; | |
| 488 | var response = request.respondStreaming(.{ | |
| 489 | .send_buffer = &send_buffer, | |
| 479 | var response = try request.respondStreaming(.{ | |
| 490 | 480 | .respond_options = .{ |
| 491 | 481 | .extra_headers = &.{ |
| 492 | 482 | .{ .name = "content-type", .value = "application/x-tar" }, |
| ... | ... | @@ -538,7 +528,7 @@ fn serveSourcesTar(ws: *WebServer, request: *std.http.Server.Request) !void { |
| 538 | 528 | defer file.close(); |
| 539 | 529 | |
| 540 | 530 | archiver.prefix = joined_path.root_dir.path orelse try memoizedCwd(arena, &cwd_cache); |
| 541 | try archiver.writeFile(joined_path.sub_path, file); | |
| 531 | try archiver.writeFile(joined_path.sub_path, file, try file.stat()); | |
| 542 | 532 | } |
| 543 | 533 | |
| 544 | 534 | // intentionally omitting the pointless trailer |
lib/std/Build/Step.zig+12-19| ... | ... | @@ -511,18 +511,15 @@ fn zigProcessUpdate(s: *Step, zp: *ZigProcess, watch: bool) !?Path { |
| 511 | 511 | try sendMessage(zp.child.stdin.?, .update); |
| 512 | 512 | if (!watch) try sendMessage(zp.child.stdin.?, .exit); |
| 513 | 513 | |
| 514 | const Header = std.zig.Server.Message.Header; | |
| 515 | 514 | var result: ?Path = null; |
| 516 | 515 | |
| 517 | const stdout = zp.poller.fifo(.stdout); | |
| 518 | ||
| 516 | const stdout_br = zp.poller.reader(.stdout); | |
| 519 | 517 | poll: while (true) { |
| 520 | while (stdout.readableLength() < @sizeOf(Header)) if (!try zp.poller.poll()) break :poll; | |
| 521 | var header: Header = undefined; | |
| 522 | assert(stdout.read(std.mem.asBytes(&header)) == @sizeOf(Header)); | |
| 523 | while (stdout.readableLength() < header.bytes_len) if (!try zp.poller.poll()) break :poll; | |
| 524 | const body = stdout.readableSliceOfLen(header.bytes_len); | |
| 525 | ||
| 518 | const Header = std.zig.Server.Message.Header; | |
| 519 | while (stdout_br.bufferContents().len < @sizeOf(Header)) if (!try zp.poller.poll()) break :poll; | |
| 520 | const header = (stdout_br.takeStruct(Header) catch unreachable).*; | |
| 521 | while (stdout_br.bufferContents().len < header.bytes_len) if (!try zp.poller.poll()) break :poll; | |
| 522 | const body = stdout_br.take(header.bytes_len) catch unreachable; | |
| 526 | 523 | switch (header.tag) { |
| 527 | 524 | .zig_version => { |
| 528 | 525 | if (!std.mem.eql(u8, builtin.zig_version_string, body)) { |
| ... | ... | @@ -547,11 +544,8 @@ fn zigProcessUpdate(s: *Step, zp: *ZigProcess, watch: bool) !?Path { |
| 547 | 544 | .string_bytes = try arena.dupe(u8, string_bytes), |
| 548 | 545 | .extra = extra_array, |
| 549 | 546 | }; |
| 550 | if (watch) { | |
| 551 | // This message indicates the end of the update. | |
| 552 | stdout.discard(body.len); | |
| 553 | break; | |
| 554 | } | |
| 547 | // This message indicates the end of the update. | |
| 548 | if (watch) break :poll; | |
| 555 | 549 | }, |
| 556 | 550 | .emit_digest => { |
| 557 | 551 | const EmitDigest = std.zig.Server.Message.EmitDigest; |
| ... | ... | @@ -611,15 +605,14 @@ fn zigProcessUpdate(s: *Step, zp: *ZigProcess, watch: bool) !?Path { |
| 611 | 605 | }, |
| 612 | 606 | else => {}, // ignore other messages |
| 613 | 607 | } |
| 614 | ||
| 615 | stdout.discard(body.len); | |
| 616 | 608 | } |
| 617 | 609 | |
| 618 | 610 | s.result_duration_ns = timer.read(); |
| 619 | 611 | |
| 620 | const stderr = zp.poller.fifo(.stderr); | |
| 621 | if (stderr.readableLength() > 0) { | |
| 622 | try s.result_error_msgs.append(arena, try stderr.toOwnedSlice()); | |
| 612 | const stderr_br = zp.poller.reader(.stderr); | |
| 613 | const stderr_contents = stderr_br.bufferContents(); | |
| 614 | if (stderr_contents.len > 0) { | |
| 615 | try s.result_error_msgs.append(arena, try arena.dupe(u8, stderr_contents)); | |
| 623 | 616 | } |
| 624 | 617 | |
| 625 | 618 | return result; |
lib/std/Build/Step/CheckObject.zig+12-12| ... | ... | @@ -1239,7 +1239,7 @@ const MachODumper = struct { |
| 1239 | 1239 | |
| 1240 | 1240 | fn parseRebaseInfo(ctx: ObjectContext, data: []const u8, rebases: *std.ArrayList(u64)) !void { |
| 1241 | 1241 | var br: std.io.BufferedReader = undefined; |
| 1242 | br.initFixed(data); | |
| 1242 | br.initFixed(@constCast(data)); | |
| 1243 | 1243 | |
| 1244 | 1244 | var seg_id: ?u8 = null; |
| 1245 | 1245 | var offset: u64 = 0; |
| ... | ... | @@ -1350,7 +1350,7 @@ const MachODumper = struct { |
| 1350 | 1350 | |
| 1351 | 1351 | fn parseBindInfo(ctx: ObjectContext, data: []const u8, bindings: *std.ArrayList(Binding)) !void { |
| 1352 | 1352 | var br: std.io.BufferedReader = undefined; |
| 1353 | br.initFixed(data); | |
| 1353 | br.initFixed(@constCast(data)); | |
| 1354 | 1354 | |
| 1355 | 1355 | var seg_id: ?u8 = null; |
| 1356 | 1356 | var tag: Binding.Tag = .self; |
| ... | ... | @@ -1448,7 +1448,7 @@ const MachODumper = struct { |
| 1448 | 1448 | |
| 1449 | 1449 | var exports: std.ArrayList(Export) = .init(arena.allocator()); |
| 1450 | 1450 | var br: std.io.BufferedReader = undefined; |
| 1451 | br.initFixed(data); | |
| 1451 | br.initFixed(@constCast(data)); | |
| 1452 | 1452 | try parseTrieNode(arena.allocator(), &br, "", &exports); |
| 1453 | 1453 | |
| 1454 | 1454 | mem.sort(Export, exports.items, {}, Export.lessThan); |
| ... | ... | @@ -1706,7 +1706,7 @@ const ElfDumper = struct { |
| 1706 | 1706 | fn parseAndDumpArchive(step: *Step, check: Check, bytes: []const u8) ![]const u8 { |
| 1707 | 1707 | const gpa = step.owner.allocator; |
| 1708 | 1708 | var br: std.io.BufferedReader = undefined; |
| 1709 | br.initFixed(bytes); | |
| 1709 | br.initFixed(@constCast(bytes)); | |
| 1710 | 1710 | |
| 1711 | 1711 | if (!mem.eql(u8, try br.takeArray(elf.ARMAG.len), elf.ARMAG)) return error.InvalidArchiveMagicNumber; |
| 1712 | 1712 | |
| ... | ... | @@ -1781,7 +1781,7 @@ const ElfDumper = struct { |
| 1781 | 1781 | |
| 1782 | 1782 | fn parseSymtab(ctx: *ArchiveContext, data: []const u8, ptr_width: enum { p32, p64 }) !void { |
| 1783 | 1783 | var br: std.io.BufferedReader = undefined; |
| 1784 | br.initFixed(data); | |
| 1784 | br.initFixed(@constCast(data)); | |
| 1785 | 1785 | const num = switch (ptr_width) { |
| 1786 | 1786 | .p32 => try br.takeInt(u32, .big), |
| 1787 | 1787 | .p64 => try br.takeInt(u64, .big), |
| ... | ... | @@ -1791,7 +1791,7 @@ const ElfDumper = struct { |
| 1791 | 1791 | .p64 => @sizeOf(u64), |
| 1792 | 1792 | }; |
| 1793 | 1793 | try br.discard(num * ptr_size); |
| 1794 | const strtab = try br.peekGreedy(0); | |
| 1794 | const strtab = br.bufferContents(); | |
| 1795 | 1795 | |
| 1796 | 1796 | assert(ctx.symtab.len == 0); |
| 1797 | 1797 | ctx.symtab = try ctx.gpa.alloc(ArSymtabEntry, num); |
| ... | ... | @@ -1852,7 +1852,7 @@ const ElfDumper = struct { |
| 1852 | 1852 | fn parseAndDumpObject(step: *Step, check: Check, bytes: []const u8) ![]const u8 { |
| 1853 | 1853 | const gpa = step.owner.allocator; |
| 1854 | 1854 | var br: std.io.BufferedReader = undefined; |
| 1855 | br.initFixed(bytes); | |
| 1855 | br.initFixed(@constCast(bytes)); | |
| 1856 | 1856 | |
| 1857 | 1857 | const hdr = try br.takeStruct(elf.Elf64_Ehdr); |
| 1858 | 1858 | if (!mem.eql(u8, hdr.e_ident[0..4], "\x7fELF")) return error.InvalidMagicNumber; |
| ... | ... | @@ -2355,7 +2355,7 @@ const WasmDumper = struct { |
| 2355 | 2355 | fn parseAndDump(step: *Step, check: Check, bytes: []const u8) ![]const u8 { |
| 2356 | 2356 | const gpa = step.owner.allocator; |
| 2357 | 2357 | var br: std.io.BufferedReader = undefined; |
| 2358 | br.initFixed(bytes); | |
| 2358 | br.initFixed(@constCast(bytes)); | |
| 2359 | 2359 | |
| 2360 | 2360 | const buf = try br.takeArray(8); |
| 2361 | 2361 | if (!mem.eql(u8, buf[0..4], &std.wasm.magic)) return error.InvalidMagicByte; |
| ... | ... | @@ -2402,7 +2402,7 @@ const WasmDumper = struct { |
| 2402 | 2402 | try bw.print( |
| 2403 | 2403 | \\Section {s} |
| 2404 | 2404 | \\size {d} |
| 2405 | , .{ @tagName(section), br.storageBuffer().len }); | |
| 2405 | , .{ @tagName(section), br.buffer.len }); | |
| 2406 | 2406 | |
| 2407 | 2407 | switch (section) { |
| 2408 | 2408 | .type, |
| ... | ... | @@ -2615,7 +2615,7 @@ const WasmDumper = struct { |
| 2615 | 2615 | /// https://webassembly.github.io/spec/core/appendix/custom.html |
| 2616 | 2616 | fn parseDumpNames(step: *Step, br: *std.io.BufferedReader, bw: *std.io.BufferedWriter) !void { |
| 2617 | 2617 | var subsection_br: std.io.BufferedReader = undefined; |
| 2618 | while (br.seek < br.storageBuffer().len) { | |
| 2618 | while (br.seek < br.buffer.len) { | |
| 2619 | 2619 | switch (try parseDumpType(step, std.wasm.NameSubsection, br, bw)) { |
| 2620 | 2620 | // The module name subsection ... consists of a single name |
| 2621 | 2621 | // that is assigned to the module itself. |
| ... | ... | @@ -2626,7 +2626,7 @@ const WasmDumper = struct { |
| 2626 | 2626 | \\name {s} |
| 2627 | 2627 | \\ |
| 2628 | 2628 | , .{name}); |
| 2629 | if (subsection_br.seek != subsection_br.storageBuffer().len) return error.BadSubsectionSize; | |
| 2629 | if (subsection_br.seek != subsection_br.buffer.len) return error.BadSubsectionSize; | |
| 2630 | 2630 | }, |
| 2631 | 2631 | |
| 2632 | 2632 | // The function name subsection ... consists of a name map |
| ... | ... | @@ -2647,7 +2647,7 @@ const WasmDumper = struct { |
| 2647 | 2647 | \\ |
| 2648 | 2648 | , .{ index, name }); |
| 2649 | 2649 | } |
| 2650 | if (subsection_br.seek != subsection_br.storageBuffer().len) return error.BadSubsectionSize; | |
| 2650 | if (subsection_br.seek != subsection_br.buffer.len) return error.BadSubsectionSize; | |
| 2651 | 2651 | }, |
| 2652 | 2652 | |
| 2653 | 2653 | // The local name subsection ... consists of an indirect name |
lib/std/Build/Step/Run.zig+18-24| ... | ... | @@ -1517,11 +1517,6 @@ fn evalZigTest( |
| 1517 | 1517 | break :failed false; |
| 1518 | 1518 | }; |
| 1519 | 1519 | |
| 1520 | const Header = std.zig.Server.Message.Header; | |
| 1521 | ||
| 1522 | const stdout = poller.fifo(.stdout); | |
| 1523 | const stderr = poller.fifo(.stderr); | |
| 1524 | ||
| 1525 | 1520 | var fail_count: u32 = 0; |
| 1526 | 1521 | var skip_count: u32 = 0; |
| 1527 | 1522 | var leak_count: u32 = 0; |
| ... | ... | @@ -1534,13 +1529,14 @@ fn evalZigTest( |
| 1534 | 1529 | var sub_prog_node: ?std.Progress.Node = null; |
| 1535 | 1530 | defer if (sub_prog_node) |n| n.end(); |
| 1536 | 1531 | |
| 1532 | const stdout_br = poller.reader(.stdout); | |
| 1533 | const stderr_br = poller.reader(.stderr); | |
| 1537 | 1534 | const any_write_failed = first_write_failed or poll: while (true) { |
| 1538 | while (stdout.readableLength() < @sizeOf(Header)) if (!try poller.poll()) break :poll false; | |
| 1539 | var header: Header = undefined; | |
| 1540 | assert(stdout.read(std.mem.asBytes(&header)) == @sizeOf(Header)); | |
| 1541 | while (stdout.readableLength() < header.bytes_len) if (!try poller.poll()) break :poll false; | |
| 1542 | const body = stdout.readableSliceOfLen(header.bytes_len); | |
| 1543 | ||
| 1535 | const Header = std.zig.Server.Message.Header; | |
| 1536 | while (stdout_br.bufferContents().len < @sizeOf(Header)) if (!try poller.poll()) break :poll false; | |
| 1537 | const header = (stdout_br.takeStruct(Header) catch unreachable).*; | |
| 1538 | while (stdout_br.bufferContents().len < header.bytes_len) if (!try poller.poll()) break :poll false; | |
| 1539 | const body = stdout_br.take(header.bytes_len) catch unreachable; | |
| 1544 | 1540 | switch (header.tag) { |
| 1545 | 1541 | .zig_version => { |
| 1546 | 1542 | if (!std.mem.eql(u8, builtin.zig_version_string, body)) { |
| ... | ... | @@ -1597,9 +1593,9 @@ fn evalZigTest( |
| 1597 | 1593 | |
| 1598 | 1594 | if (tr_hdr.flags.fail or tr_hdr.flags.leak or tr_hdr.flags.log_err_count > 0) { |
| 1599 | 1595 | const name = std.mem.sliceTo(md.string_bytes[md.names[tr_hdr.index]..], 0); |
| 1600 | const orig_msg = stderr.readableSlice(0); | |
| 1601 | defer stderr.discard(orig_msg.len); | |
| 1602 | const msg = std.mem.trim(u8, orig_msg, "\n"); | |
| 1596 | const stderr_contents = stderr_br.bufferContents(); | |
| 1597 | stderr_br.toss(stderr_contents.len); | |
| 1598 | const msg = std.mem.trim(u8, stderr_contents, "\n"); | |
| 1603 | 1599 | const label = if (tr_hdr.flags.fail) |
| 1604 | 1600 | "failed" |
| 1605 | 1601 | else if (tr_hdr.flags.leak) |
| ... | ... | @@ -1650,8 +1646,6 @@ fn evalZigTest( |
| 1650 | 1646 | }, |
| 1651 | 1647 | else => {}, // ignore other messages |
| 1652 | 1648 | } |
| 1653 | ||
| 1654 | stdout.discard(body.len); | |
| 1655 | 1649 | }; |
| 1656 | 1650 | |
| 1657 | 1651 | if (any_write_failed) { |
| ... | ... | @@ -1660,9 +1654,9 @@ fn evalZigTest( |
| 1660 | 1654 | while (try poller.poll()) {} |
| 1661 | 1655 | } |
| 1662 | 1656 | |
| 1663 | if (stderr.readableLength() > 0) { | |
| 1664 | const msg = std.mem.trim(u8, try stderr.toOwnedSlice(), "\n"); | |
| 1665 | if (msg.len > 0) run.step.result_stderr = msg; | |
| 1657 | const stderr_contents = std.mem.trim(u8, stderr_br.bufferContents(), "\n"); | |
| 1658 | if (stderr_contents.len > 0) { | |
| 1659 | run.step.result_stderr = try arena.dupe(u8, stderr_contents); | |
| 1666 | 1660 | } |
| 1667 | 1661 | |
| 1668 | 1662 | // Send EOF to stdin. |
| ... | ... | @@ -1776,7 +1770,7 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !StdIoResult { |
| 1776 | 1770 | var stdout_bytes: ?[]const u8 = null; |
| 1777 | 1771 | var stderr_bytes: ?[]const u8 = null; |
| 1778 | 1772 | |
| 1779 | run.stdio_limit = .limited(run.stdio_limit.min(run.max_stdio_size)); | |
| 1773 | run.stdio_limit = run.stdio_limit.min(.limited(run.max_stdio_size)); | |
| 1780 | 1774 | if (child.stdout) |stdout| { |
| 1781 | 1775 | if (child.stderr) |stderr| { |
| 1782 | 1776 | var poller = std.io.poll(arena, enum { stdout, stderr }, .{ |
| ... | ... | @@ -1787,15 +1781,15 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !StdIoResult { |
| 1787 | 1781 | |
| 1788 | 1782 | while (try poller.poll()) { |
| 1789 | 1783 | if (run.stdio_limit.toInt()) |limit| { |
| 1790 | if (poller.fifo(.stderr).count > limit) | |
| 1784 | if (poller.reader(.stderr).bufferContents().len > limit) | |
| 1791 | 1785 | return error.StdoutStreamTooLong; |
| 1792 | if (poller.fifo(.stderr).count > limit) | |
| 1786 | if (poller.reader(.stderr).bufferContents().len > limit) | |
| 1793 | 1787 | return error.StderrStreamTooLong; |
| 1794 | 1788 | } |
| 1795 | 1789 | } |
| 1796 | 1790 | |
| 1797 | stdout_bytes = try poller.fifo(.stdout).toOwnedSlice(); | |
| 1798 | stderr_bytes = try poller.fifo(.stderr).toOwnedSlice(); | |
| 1791 | stdout_bytes = poller.reader(.stdout).bufferContents(); | |
| 1792 | stderr_bytes = poller.reader(.stderr).bufferContents(); | |
| 1799 | 1793 | } else { |
| 1800 | 1794 | stdout_bytes = try stdout.readToEndAlloc(arena, run.stdio_limit); |
| 1801 | 1795 | } |
lib/std/fs/path.zig+5-6| ... | ... | @@ -150,27 +150,26 @@ pub fn fmtJoin(paths: []const []const u8) std.fmt.Formatter(formatJoin) { |
| 150 | 150 | return .{ .data = paths }; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | fn formatJoin(paths: []const []const u8, comptime fmt: []const u8, options: std.fmt.FormatOptions, w: anytype) !void { | |
| 153 | fn formatJoin(paths: []const []const u8, bw: *std.io.BufferedWriter, comptime fmt: []const u8) !void { | |
| 154 | 154 | _ = fmt; |
| 155 | _ = options; | |
| 156 | 155 | |
| 157 | 156 | const first_path_idx = for (paths, 0..) |p, idx| { |
| 158 | 157 | if (p.len != 0) break idx; |
| 159 | 158 | } else return; |
| 160 | 159 | |
| 161 | try w.writeAll(paths[first_path_idx]); // first component | |
| 160 | try bw.writeAll(paths[first_path_idx]); // first component | |
| 162 | 161 | var prev_path = paths[first_path_idx]; |
| 163 | 162 | for (paths[first_path_idx + 1 ..]) |this_path| { |
| 164 | 163 | if (this_path.len == 0) continue; // skip empty components |
| 165 | 164 | const prev_sep = isSep(prev_path[prev_path.len - 1]); |
| 166 | 165 | const this_sep = isSep(this_path[0]); |
| 167 | 166 | if (!prev_sep and !this_sep) { |
| 168 | try w.writeByte(sep); | |
| 167 | try bw.writeByte(sep); | |
| 169 | 168 | } |
| 170 | 169 | if (prev_sep and this_sep) { |
| 171 | try w.writeAll(this_path[1..]); // skip redundant separator | |
| 170 | try bw.writeAll(this_path[1..]); // skip redundant separator | |
| 172 | 171 | } else { |
| 173 | try w.writeAll(this_path); | |
| 172 | try bw.writeAll(this_path); | |
| 174 | 173 | } |
| 175 | 174 | prev_path = this_path; |
| 176 | 175 | } |
lib/std/http/WebSocket.zig+7-11| ... | ... | @@ -9,7 +9,7 @@ const native_endian = builtin.cpu.arch.endian(); |
| 9 | 9 | key: []const u8, |
| 10 | 10 | request: *std.http.Server.Request, |
| 11 | 11 | recv_fifo: std.fifo.LinearFifo(u8, .Slice), |
| 12 | reader: *std.io.BufferedReader, | |
| 12 | reader: std.io.BufferedReader, | |
| 13 | 13 | response: std.http.Server.Response, |
| 14 | 14 | /// Number of bytes that have been peeked but not discarded yet. |
| 15 | 15 | outstanding_len: usize, |
| ... | ... | @@ -20,7 +20,6 @@ pub const InitError = error{WebSocketUpgradeMissingKey} || |
| 20 | 20 | pub fn init( |
| 21 | 21 | ws: *WebSocket, |
| 22 | 22 | request: *std.http.Server.Request, |
| 23 | send_buffer: []u8, | |
| 24 | 23 | recv_buffer: []align(4) u8, |
| 25 | 24 | ) InitError!bool { |
| 26 | 25 | switch (request.head.version) { |
| ... | ... | @@ -58,9 +57,8 @@ pub fn init( |
| 58 | 57 | ws.* = .{ |
| 59 | 58 | .key = key, |
| 60 | 59 | .recv_fifo = .init(recv_buffer), |
| 61 | .reader = undefined, | |
| 62 | .response = request.respondStreaming(.{ | |
| 63 | .send_buffer = send_buffer, | |
| 60 | .reader = (try request.reader()).unbuffered(), | |
| 61 | .response = try request.respondStreaming(.{ | |
| 64 | 62 | .respond_options = .{ |
| 65 | 63 | .status = .switching_protocols, |
| 66 | 64 | .extra_headers = &.{ |
| ... | ... | @@ -74,7 +72,6 @@ pub fn init( |
| 74 | 72 | .request = request, |
| 75 | 73 | .outstanding_len = 0, |
| 76 | 74 | }; |
| 77 | ws.reader.init(try request.reader(), &.{}); | |
| 78 | 75 | return true; |
| 79 | 76 | } |
| 80 | 77 | |
| ... | ... | @@ -239,9 +236,8 @@ pub fn writeMessagev(ws: *WebSocket, message: []const std.posix.iovec_const, opc |
| 239 | 236 | }, |
| 240 | 237 | }; |
| 241 | 238 | |
| 242 | const response = &ws.response; | |
| 243 | try response.writeAll(header); | |
| 244 | for (message) |iovec| | |
| 245 | try response.writeAll(iovec.base[0..iovec.len]); | |
| 246 | try response.flush(); | |
| 239 | var bw = ws.response.writer().unbuffered(); | |
| 240 | try bw.writeAll(header); | |
| 241 | for (message) |iovec| try bw.writeAll(iovec.base[0..iovec.len]); | |
| 242 | try bw.flush(); | |
| 247 | 243 | } |
lib/std/io.zig+6-7| ... | ... | @@ -53,7 +53,12 @@ pub fn poll( |
| 53 | 53 | const enum_fields = @typeInfo(StreamEnum).@"enum".fields; |
| 54 | 54 | var result: Poller(StreamEnum) = .{ |
| 55 | 55 | .gpa = gpa, |
| 56 | .readers = undefined, | |
| 56 | .readers = @splat(.{ | |
| 57 | .unbuffered_reader = .failing, | |
| 58 | .buffer = &.{}, | |
| 59 | .end = 0, | |
| 60 | .seek = 0, | |
| 61 | }), | |
| 57 | 62 | .poll_fds = undefined, |
| 58 | 63 | .windows = if (is_windows) .{ |
| 59 | 64 | .first_read_done = false, |
| ... | ... | @@ -70,12 +75,6 @@ pub fn poll( |
| 70 | 75 | }; |
| 71 | 76 | |
| 72 | 77 | inline for (enum_fields, 0..) |field, i| { |
| 73 | result.readers[i] = .{ | |
| 74 | .unbuffered_reader = .failing, | |
| 75 | .buffer = &.{}, | |
| 76 | .end = 0, | |
| 77 | .seek = 0, | |
| 78 | }; | |
| 79 | 78 | if (is_windows) { |
| 80 | 79 | result.windows.active.handles_buf[i] = @field(files, field.name).handle; |
| 81 | 80 | } else { |
lib/std/io/BufferedReader.zig+57-18| ... | ... | @@ -51,6 +51,23 @@ pub fn readVec(br: *BufferedReader, data: []const []u8) Reader.Error!usize { |
| 51 | 51 | return passthruReadVec(br, data); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | pub fn readVecAll(br: *BufferedReader, data: [][]u8) Reader.Error!void { | |
| 55 | var index: usize = 0; | |
| 56 | var truncate: usize = 0; | |
| 57 | while (index < data.len) { | |
| 58 | { | |
| 59 | const untruncated = data[index]; | |
| 60 | data[index] = untruncated[truncate..]; | |
| 61 | defer data[index] = untruncated; | |
| 62 | truncate += try br.readVec(data[index..]); | |
| 63 | } | |
| 64 | while (index < data.len and truncate <= data[index].len) { | |
| 65 | truncate -= data[index].len; | |
| 66 | index += 1; | |
| 67 | } | |
| 68 | } | |
| 69 | } | |
| 70 | ||
| 54 | 71 | pub fn read(br: *BufferedReader, bw: *BufferedWriter, limit: Reader.Limit) Reader.RwError!usize { |
| 55 | 72 | return passthruRead(br, bw, limit); |
| 56 | 73 | } |
| ... | ... | @@ -58,8 +75,8 @@ pub fn read(br: *BufferedReader, bw: *BufferedWriter, limit: Reader.Limit) Reade |
| 58 | 75 | /// "Pump" data from the reader to the writer. |
| 59 | 76 | pub fn readAll(br: *BufferedReader, bw: *BufferedWriter, limit: Reader.Limit) Reader.RwError!void { |
| 60 | 77 | var remaining = limit; |
| 61 | while (true) { | |
| 62 | const n = try passthruRead(br, bw, remaining); | |
| 78 | while (remaining.nonzero()) { | |
| 79 | const n = try br.read(bw, remaining); | |
| 63 | 80 | remaining = remaining.subtract(n).?; |
| 64 | 81 | } |
| 65 | 82 | } |
| ... | ... | @@ -68,7 +85,7 @@ fn passthruRead(ctx: ?*anyopaque, bw: *BufferedWriter, limit: Reader.Limit) Read |
| 68 | 85 | const br: *BufferedReader = @alignCast(@ptrCast(ctx)); |
| 69 | 86 | const buffer = br.buffer[0..br.end]; |
| 70 | 87 | const buffered = buffer[br.seek..]; |
| 71 | const limited = buffered[0..limit.min(buffered.len)]; | |
| 88 | const limited = buffered[0..limit.minInt(buffered.len)]; | |
| 72 | 89 | if (limited.len > 0) { |
| 73 | 90 | const n = try bw.write(limited); |
| 74 | 91 | br.seek += n; |
| ... | ... | @@ -93,7 +110,7 @@ fn passthruReadVec(ctx: ?*anyopaque, data: []const []u8) Reader.Error!usize { |
| 93 | 110 | vecs[0] = buf[copy_len..]; |
| 94 | 111 | const vecs_len: usize = @min(vecs.len, data.len - i); |
| 95 | 112 | var vec_data_len: usize = vecs[0].len; |
| 96 | for (&vecs[1..vecs_len], data[i + 1 ..][0 .. vecs_len - 1]) |*v, d| { | |
| 113 | for (vecs[1..vecs_len], data[i + 1 ..][0 .. vecs_len - 1]) |*v, d| { | |
| 97 | 114 | vec_data_len += d.len; |
| 98 | 115 | v.* = d; |
| 99 | 116 | } |
| ... | ... | @@ -149,7 +166,6 @@ pub fn seekForwardBy(br: *BufferedReader, seek_by: u64) !void { |
| 149 | 166 | /// * `peek` |
| 150 | 167 | /// * `toss` |
| 151 | 168 | pub fn peek(br: *BufferedReader, n: usize) Reader.Error![]u8 { |
| 152 | assert(n <= br.buffer.len); | |
| 153 | 169 | try br.fill(n); |
| 154 | 170 | return br.buffer[br.seek..][0..n]; |
| 155 | 171 | } |
| ... | ... | @@ -169,7 +185,6 @@ pub fn peek(br: *BufferedReader, n: usize) Reader.Error![]u8 { |
| 169 | 185 | /// * `peek` |
| 170 | 186 | /// * `toss` |
| 171 | 187 | pub fn peekGreedy(br: *BufferedReader, n: usize) Reader.Error![]u8 { |
| 172 | assert(n <= br.buffer.len); | |
| 173 | 188 | try br.fill(n); |
| 174 | 189 | return br.buffer[br.seek..br.end]; |
| 175 | 190 | } |
| ... | ... | @@ -448,10 +463,12 @@ fn peekDelimiterInclusiveUnlessEnd(br: *BufferedReader, delimiter: u8) Delimiter |
| 448 | 463 | @branchHint(.likely); |
| 449 | 464 | return buffer[seek .. end + 1]; |
| 450 | 465 | } |
| 451 | const remainder = buffer[seek..]; | |
| 452 | std.mem.copyForwards(u8, buffer[0..remainder.len], remainder); | |
| 453 | br.end = remainder.len; | |
| 454 | br.seek = 0; | |
| 466 | if (seek > 0) { | |
| 467 | const remainder = buffer[seek..]; | |
| 468 | std.mem.copyForwards(u8, buffer[0..remainder.len], remainder); | |
| 469 | br.end = remainder.len; | |
| 470 | br.seek = 0; | |
| 471 | } | |
| 455 | 472 | while (br.end < br.buffer.len) { |
| 456 | 473 | const n = try br.unbuffered_reader.readVec(&.{br.buffer[br.end..]}); |
| 457 | 474 | const prev_end = br.end; |
| ... | ... | @@ -550,10 +567,12 @@ pub fn fill(br: *BufferedReader, n: usize) Reader.Error!void { |
| 550 | 567 | @branchHint(.likely); |
| 551 | 568 | return; |
| 552 | 569 | } |
| 553 | const remainder = buffer[seek..]; | |
| 554 | std.mem.copyForwards(u8, buffer[0..remainder.len], remainder); | |
| 555 | br.end = remainder.len; | |
| 556 | br.seek = 0; | |
| 570 | if (seek > 0) { | |
| 571 | const remainder = buffer[seek..]; | |
| 572 | std.mem.copyForwards(u8, buffer[0..remainder.len], remainder); | |
| 573 | br.end = remainder.len; | |
| 574 | br.seek = 0; | |
| 575 | } | |
| 557 | 576 | while (true) { |
| 558 | 577 | br.end += try br.unbuffered_reader.readVec(&.{br.buffer[br.end..]}); |
| 559 | 578 | if (n <= br.end) return; |
| ... | ... | @@ -665,15 +684,35 @@ pub fn writableSliceGreedyAlloc( |
| 665 | 684 | allocator: Allocator, |
| 666 | 685 | min_len: usize, |
| 667 | 686 | ) error{OutOfMemory}![]u8 { |
| 668 | _ = br; | |
| 669 | _ = allocator; | |
| 670 | _ = min_len; | |
| 671 | @panic("TODO"); | |
| 687 | { | |
| 688 | const unused = br.buffer[br.end..]; | |
| 689 | if (unused.len >= min_len) return unused; | |
| 690 | } | |
| 691 | const seek = br.seek; | |
| 692 | if (seek > 0) { | |
| 693 | const buffer = br.buffer[0..br.end]; | |
| 694 | const remainder = buffer[seek..]; | |
| 695 | std.mem.copyForwards(u8, buffer[0..remainder.len], remainder); | |
| 696 | br.end = remainder.len; | |
| 697 | br.seek = 0; | |
| 698 | } | |
| 699 | { | |
| 700 | var list: std.ArrayListUnmanaged(u8) = .{ | |
| 701 | .items = br.buffer[0..br.end], | |
| 702 | .capacity = br.buffer.len, | |
| 703 | }; | |
| 704 | defer br.buffer = list.allocatedSlice(); | |
| 705 | try list.ensureUnusedCapacity(allocator, min_len); | |
| 706 | } | |
| 707 | const unused = br.buffer[br.end..]; | |
| 708 | assert(unused.len >= min_len); | |
| 709 | return unused; | |
| 672 | 710 | } |
| 673 | 711 | |
| 674 | 712 | /// After writing directly into the unused capacity of `buffer`, this function |
| 675 | 713 | /// updates `end` so that users of `BufferedReader` can receive the data. |
| 676 | 714 | pub fn advanceBufferEnd(br: *BufferedReader, n: usize) void { |
| 715 | assert(n <= br.buffer.len - br.end); | |
| 677 | 716 | br.end += n; |
| 678 | 717 | } |
| 679 | 718 |
lib/std/io/BufferedWriter.zig+12-9| ... | ... | @@ -141,16 +141,19 @@ pub fn advance(bw: *BufferedWriter, n: usize) void { |
| 141 | 141 | /// The `data` parameter is mutable because this function needs to mutate the |
| 142 | 142 | /// fields in order to handle partial writes from `Writer.VTable.writeVec`. |
| 143 | 143 | pub fn writeVecAll(bw: *BufferedWriter, data: [][]const u8) Writer.Error!void { |
| 144 | var i: usize = 0; | |
| 145 | while (true) { | |
| 146 | var n = try passthruWriteSplat(bw, data[i..], 1); | |
| 147 | const len = data[i].len; | |
| 148 | while (n >= len) { | |
| 149 | n -= len; | |
| 150 | i += 1; | |
| 151 | if (i >= data.len) return; | |
| 144 | var index: usize = 0; | |
| 145 | var truncate: usize = 0; | |
| 146 | while (index < data.len) { | |
| 147 | { | |
| 148 | const untruncated = data[index]; | |
| 149 | data[index] = untruncated[truncate..]; | |
| 150 | defer data[index] = untruncated; | |
| 151 | truncate += try bw.writeVec(data[index..]); | |
| 152 | } | |
| 153 | while (index < data.len and truncate <= data[index].len) { | |
| 154 | truncate -= data[index].len; | |
| 155 | index += 1; | |
| 152 | 156 | } |
| 153 | data[i] = data[i][n..]; | |
| 154 | 157 | } |
| 155 | 158 | } |
| 156 | 159 |
lib/std/io/Reader.zig+1-1| ... | ... | @@ -94,7 +94,7 @@ pub const Limit = enum(usize) { |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | pub fn slice(l: Limit, s: []u8) []u8 { |
| 97 | return s[0..min(l, s.len)]; | |
| 97 | return s[0..l.minInt(s.len)]; | |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | pub fn toInt(l: Limit) ?usize { |
lib/std/process/Child.zig+9-10| ... | ... | @@ -348,16 +348,15 @@ pub const RunResult = struct { |
| 348 | 348 | stderr: []u8, |
| 349 | 349 | }; |
| 350 | 350 | |
| 351 | fn writeFifoDataToArrayList(allocator: Allocator, list: *std.ArrayListUnmanaged(u8), fifo: *std.io.PollFifo) !void { | |
| 352 | if (fifo.head != 0) fifo.realign(); | |
| 351 | fn writeBufferedReaderToArrayList(allocator: Allocator, list: *std.ArrayListUnmanaged(u8), br: *std.io.BufferedReader) !void { | |
| 352 | assert(br.seek == 0); | |
| 353 | 353 | if (list.capacity == 0) { |
| 354 | 354 | list.* = .{ |
| 355 | .items = fifo.buf[0..fifo.count], | |
| 356 | .capacity = fifo.buf.len, | |
| 355 | .items = br.bufferContents(), | |
| 356 | .capacity = br.buffer.len, | |
| 357 | 357 | }; |
| 358 | fifo.* = std.io.PollFifo.init(fifo.allocator); | |
| 359 | 358 | } else { |
| 360 | try list.appendSlice(allocator, fifo.buf[0..fifo.count]); | |
| 359 | try list.appendSlice(allocator, br.bufferContents()); | |
| 361 | 360 | } |
| 362 | 361 | } |
| 363 | 362 | |
| ... | ... | @@ -384,14 +383,14 @@ pub fn collectOutput( |
| 384 | 383 | defer poller.deinit(); |
| 385 | 384 | |
| 386 | 385 | while (try poller.poll()) { |
| 387 | if (poller.fifo(.stdout).count > max_output_bytes) | |
| 386 | if (poller.reader(.stdout).bufferContents().len > max_output_bytes) | |
| 388 | 387 | return error.StdoutStreamTooLong; |
| 389 | if (poller.fifo(.stderr).count > max_output_bytes) | |
| 388 | if (poller.reader(.stderr).bufferContents().len > max_output_bytes) | |
| 390 | 389 | return error.StderrStreamTooLong; |
| 391 | 390 | } |
| 392 | 391 | |
| 393 | try writeFifoDataToArrayList(allocator, stdout, poller.fifo(.stdout)); | |
| 394 | try writeFifoDataToArrayList(allocator, stderr, poller.fifo(.stderr)); | |
| 392 | try writeBufferedReaderToArrayList(allocator, stdout, poller.reader(.stdout)); | |
| 393 | try writeBufferedReaderToArrayList(allocator, stderr, poller.reader(.stderr)); | |
| 395 | 394 | } |
| 396 | 395 | |
| 397 | 396 | pub const RunError = posix.GetCwdError || posix.ReadError || SpawnError || posix.PollError || error{ |
lib/std/zig/ZonGen.zig+1-1| ... | ... | @@ -522,7 +522,7 @@ pub fn parseStrLit( |
| 522 | 522 | tree: Ast, |
| 523 | 523 | node: Ast.Node.Index, |
| 524 | 524 | writer: *std.io.BufferedWriter, |
| 525 | ) error{OutOfMemory}!std.zig.string_literal.Result { | |
| 525 | ) std.io.Writer.Error!std.zig.string_literal.Result { | |
| 526 | 526 | switch (tree.nodeTag(node)) { |
| 527 | 527 | .string_literal => { |
| 528 | 528 | const token = tree.nodeMainToken(node); |
src/Air/print.zig+3-3| ... | ... | @@ -72,9 +72,9 @@ pub fn writeInst( |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | pub fn dump(air: Air, pt: Zcu.PerThread, liveness: ?Air.Liveness) void { |
| 75 | var bw = std.debug.lockStdErr2(&.{}); | |
| 76 | defer std.debug.unlockStdErr(); | |
| 77 | air.write(&bw, pt, liveness); | |
| 75 | const stderr_bw = std.debug.lockStderrWriter(&.{}); | |
| 76 | defer std.debug.unlockStderrWriter(); | |
| 77 | air.write(stderr_bw, pt, liveness); | |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | pub fn dumpInst(air: Air, inst: Air.Inst.Index, pt: Zcu.PerThread, liveness: ?Air.Liveness) void { |
src/Compilation.zig+6-8| ... | ... | @@ -1881,14 +1881,12 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 1881 | 1881 | |
| 1882 | 1882 | if (options.verbose_llvm_cpu_features) { |
| 1883 | 1883 | if (options.root_mod.resolved_target.llvm_cpu_features) |cf| print: { |
| 1884 | var stderr = std.debug.lockStdErr2(&.{}); | |
| 1885 | defer std.debug.unlockStdErr(); | |
| 1886 | nosuspend { | |
| 1887 | stderr.print("compilation: {s}\n", .{options.root_name}) catch break :print; | |
| 1888 | stderr.print(" target: {s}\n", .{try target.zigTriple(arena)}) catch break :print; | |
| 1889 | stderr.print(" cpu: {s}\n", .{target.cpu.model.name}) catch break :print; | |
| 1890 | stderr.print(" features: {s}\n", .{cf}) catch {}; | |
| 1891 | } | |
| 1884 | const stderr_bw = std.debug.lockStderrWriter(&.{}); | |
| 1885 | defer std.debug.unlockStderrWriter(); | |
| 1886 | stderr_bw.print("compilation: {s}\n", .{options.root_name}) catch break :print; | |
| 1887 | stderr_bw.print(" target: {s}\n", .{try target.zigTriple(arena)}) catch break :print; | |
| 1888 | stderr_bw.print(" cpu: {s}\n", .{target.cpu.model.name}) catch break :print; | |
| 1889 | stderr_bw.print(" features: {s}\n", .{cf}) catch {}; | |
| 1892 | 1890 | } |
| 1893 | 1891 | } |
| 1894 | 1892 |
src/InternPool.zig+14-17| ... | ... | @@ -11263,8 +11263,8 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void { |
| 11263 | 11263 | |
| 11264 | 11264 | fn dumpAllFallible(ip: *const InternPool) anyerror!void { |
| 11265 | 11265 | var buffer: [4096]u8 = undefined; |
| 11266 | var bw = std.debug.lockStdErr2(&buffer); | |
| 11267 | defer std.debug.unlockStdErr(); | |
| 11266 | const stderr_bw = std.debug.lockStderrWriter(&buffer); | |
| 11267 | defer std.debug.unlockStderrWriter(); | |
| 11268 | 11268 | for (ip.locals, 0..) |*local, tid| { |
| 11269 | 11269 | const items = local.shared.items.view(); |
| 11270 | 11270 | for ( |
| ... | ... | @@ -11273,12 +11273,12 @@ fn dumpAllFallible(ip: *const InternPool) anyerror!void { |
| 11273 | 11273 | 0.., |
| 11274 | 11274 | ) |tag, data, index| { |
| 11275 | 11275 | const i = Index.Unwrapped.wrap(.{ .tid = @enumFromInt(tid), .index = @intCast(index) }, ip); |
| 11276 | try bw.print("${d} = {s}(", .{ i, @tagName(tag) }); | |
| 11276 | try stderr_bw.print("${d} = {s}(", .{ i, @tagName(tag) }); | |
| 11277 | 11277 | switch (tag) { |
| 11278 | 11278 | .removed => {}, |
| 11279 | 11279 | |
| 11280 | .simple_type => try bw.print("{s}", .{@tagName(@as(SimpleType, @enumFromInt(@intFromEnum(i))))}), | |
| 11281 | .simple_value => try bw.print("{s}", .{@tagName(@as(SimpleValue, @enumFromInt(@intFromEnum(i))))}), | |
| 11280 | .simple_type => try stderr_bw.print("{s}", .{@tagName(@as(SimpleType, @enumFromInt(@intFromEnum(i))))}), | |
| 11281 | .simple_value => try stderr_bw.print("{s}", .{@tagName(@as(SimpleValue, @enumFromInt(@intFromEnum(i))))}), | |
| 11282 | 11282 | |
| 11283 | 11283 | .type_int_signed, |
| 11284 | 11284 | .type_int_unsigned, |
| ... | ... | @@ -11351,17 +11351,16 @@ fn dumpAllFallible(ip: *const InternPool) anyerror!void { |
| 11351 | 11351 | .func_coerced, |
| 11352 | 11352 | .union_value, |
| 11353 | 11353 | .memoized_call, |
| 11354 | => try bw.print("{d}", .{data}), | |
| 11354 | => try stderr_bw.print("{d}", .{data}), | |
| 11355 | 11355 | |
| 11356 | 11356 | .opt_null, |
| 11357 | 11357 | .type_slice, |
| 11358 | 11358 | .only_possible_value, |
| 11359 | => try bw.print("${d}", .{data}), | |
| 11359 | => try stderr_bw.print("${d}", .{data}), | |
| 11360 | 11360 | } |
| 11361 | try bw.writeAll(")\n"); | |
| 11361 | try stderr_bw.writeAll(")\n"); | |
| 11362 | 11362 | } |
| 11363 | 11363 | } |
| 11364 | try bw.flush(); | |
| 11365 | 11364 | } |
| 11366 | 11365 | |
| 11367 | 11366 | pub fn dumpGenericInstances(ip: *const InternPool, allocator: Allocator) void { |
| ... | ... | @@ -11396,8 +11395,8 @@ pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator) |
| 11396 | 11395 | } |
| 11397 | 11396 | |
| 11398 | 11397 | var buffer: [4096]u8 = undefined; |
| 11399 | var bw = std.debug.lockStdErr2(&buffer); | |
| 11400 | defer std.debug.unlockStdErr(); | |
| 11398 | const stderr_bw = std.debug.lockStderrWriter(&buffer); | |
| 11399 | defer std.debug.unlockStderrWriter(); | |
| 11401 | 11400 | |
| 11402 | 11401 | const SortContext = struct { |
| 11403 | 11402 | values: []std.ArrayListUnmanaged(Index), |
| ... | ... | @@ -11410,23 +11409,21 @@ pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator) |
| 11410 | 11409 | var it = instances.iterator(); |
| 11411 | 11410 | while (it.next()) |entry| { |
| 11412 | 11411 | const generic_fn_owner_nav = ip.getNav(ip.funcDeclInfo(entry.key_ptr.*).owner_nav); |
| 11413 | try bw.print("{f} ({}): \n", .{ generic_fn_owner_nav.name.fmt(ip), entry.value_ptr.items.len }); | |
| 11412 | try stderr_bw.print("{f} ({}): \n", .{ generic_fn_owner_nav.name.fmt(ip), entry.value_ptr.items.len }); | |
| 11414 | 11413 | for (entry.value_ptr.items) |index| { |
| 11415 | 11414 | const unwrapped_index = index.unwrap(ip); |
| 11416 | 11415 | const func = ip.extraFuncInstance(unwrapped_index.tid, unwrapped_index.getExtra(ip), unwrapped_index.getData(ip)); |
| 11417 | 11416 | const owner_nav = ip.getNav(func.owner_nav); |
| 11418 | try bw.print(" {f}: (", .{owner_nav.name.fmt(ip)}); | |
| 11417 | try stderr_bw.print(" {f}: (", .{owner_nav.name.fmt(ip)}); | |
| 11419 | 11418 | for (func.comptime_args.get(ip)) |arg| { |
| 11420 | 11419 | if (arg != .none) { |
| 11421 | 11420 | const key = ip.indexToKey(arg); |
| 11422 | try bw.print(" {} ", .{key}); | |
| 11421 | try stderr_bw.print(" {} ", .{key}); | |
| 11423 | 11422 | } |
| 11424 | 11423 | } |
| 11425 | try bw.writeAll(")\n"); | |
| 11424 | try stderr_bw.writeAll(")\n"); | |
| 11426 | 11425 | } |
| 11427 | 11426 | } |
| 11428 | ||
| 11429 | try bw.flush(); | |
| 11430 | 11427 | } |
| 11431 | 11428 | |
| 11432 | 11429 | pub fn getNav(ip: *const InternPool, index: Nav.Index) Nav { |
src/Zcu.zig+61-140| ... | ... | @@ -1043,12 +1043,12 @@ pub const File = struct { |
| 1043 | 1043 | if (stat.size > std.math.maxInt(u32)) |
| 1044 | 1044 | return error.FileTooBig; |
| 1045 | 1045 | |
| 1046 | const source = try gpa.allocSentinel(u8, @as(usize, @intCast(stat.size)), 0); | |
| 1046 | const source = try gpa.allocSentinel(u8, @intCast(stat.size), 0); | |
| 1047 | 1047 | errdefer gpa.free(source); |
| 1048 | 1048 | |
| 1049 | const amt = try f.readAll(source); | |
| 1050 | if (amt != stat.size) | |
| 1051 | return error.UnexpectedEndOfFile; | |
| 1049 | var fr = f.reader(); | |
| 1050 | var br = fr.interface().unbuffered(); | |
| 1051 | try br.readSlice(source); | |
| 1052 | 1052 | |
| 1053 | 1053 | // Here we do not modify stat fields because this function is the one |
| 1054 | 1054 | // used for error reporting. We need to keep the stat fields stale so that |
| ... | ... | @@ -2845,34 +2845,21 @@ pub fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.F |
| 2845 | 2845 | undefined; |
| 2846 | 2846 | defer if (data_has_safety_tag) gpa.free(safety_buffer); |
| 2847 | 2847 | |
| 2848 | const data_ptr = if (data_has_safety_tag) | |
| 2849 | @as([*]u8, @ptrCast(safety_buffer.ptr)) | |
| 2850 | else | |
| 2851 | @as([*]u8, @ptrCast(zir.instructions.items(.data).ptr)); | |
| 2852 | ||
| 2853 | var iovecs = [_]std.posix.iovec{ | |
| 2854 | .{ | |
| 2855 | .base = @as([*]u8, @ptrCast(zir.instructions.items(.tag).ptr)), | |
| 2856 | .len = header.instructions_len, | |
| 2857 | }, | |
| 2858 | .{ | |
| 2859 | .base = data_ptr, | |
| 2860 | .len = header.instructions_len * 8, | |
| 2861 | }, | |
| 2862 | .{ | |
| 2863 | .base = zir.string_bytes.ptr, | |
| 2864 | .len = header.string_bytes_len, | |
| 2865 | }, | |
| 2866 | .{ | |
| 2867 | .base = @as([*]u8, @ptrCast(zir.extra.ptr)), | |
| 2868 | .len = header.extra_len * 4, | |
| 2869 | }, | |
| 2848 | var vecs = [_][]u8{ | |
| 2849 | @ptrCast(zir.instructions.items(.tag)), | |
| 2850 | if (data_has_safety_tag) | |
| 2851 | @ptrCast(safety_buffer) | |
| 2852 | else | |
| 2853 | zir.instructions.items(.data), | |
| 2854 | zir.string_bytes, | |
| 2855 | @ptrCast(zir.extra), | |
| 2856 | }; | |
| 2857 | var cache_fr = cache_file.reader(); | |
| 2858 | var cache_br = cache_fr.interface().unbuffered(); | |
| 2859 | cache_br.readVecAll(&vecs) catch |err| switch (err) { | |
| 2860 | error.ReadFailed => if (cache_fr.err) |_| unreachable else |e| return e, | |
| 2861 | error.EndOfStream => return error.UnexpectedFileSize, | |
| 2870 | 2862 | }; |
| 2871 | const amt_read = try cache_file.readvAll(&iovecs); | |
| 2872 | const amt_expected = zir.instructions.len * 9 + | |
| 2873 | zir.string_bytes.len + | |
| 2874 | zir.extra.len * 4; | |
| 2875 | if (amt_read != amt_expected) return error.UnexpectedFileSize; | |
| 2876 | 2863 | if (data_has_safety_tag) { |
| 2877 | 2864 | const tags = zir.instructions.items(.tag); |
| 2878 | 2865 | for (zir.instructions.items(.data), 0..) |*data, i| { |
| ... | ... | @@ -2895,14 +2882,6 @@ pub fn saveZirCache(gpa: Allocator, cache_file: std.fs.File, stat: std.fs.File.S |
| 2895 | 2882 | undefined; |
| 2896 | 2883 | defer if (data_has_safety_tag) gpa.free(safety_buffer); |
| 2897 | 2884 | |
| 2898 | const data_ptr: [*]const u8 = if (data_has_safety_tag) | |
| 2899 | if (zir.instructions.len == 0) | |
| 2900 | undefined | |
| 2901 | else | |
| 2902 | @ptrCast(safety_buffer.ptr) | |
| 2903 | else | |
| 2904 | @ptrCast(zir.instructions.items(.data).ptr); | |
| 2905 | ||
| 2906 | 2885 | if (data_has_safety_tag) { |
| 2907 | 2886 | // The `Data` union has a safety tag but in the file format we store it without. |
| 2908 | 2887 | for (zir.instructions.items(.data), 0..) |*data, i| { |
| ... | ... | @@ -2920,29 +2899,21 @@ pub fn saveZirCache(gpa: Allocator, cache_file: std.fs.File, stat: std.fs.File.S |
| 2920 | 2899 | .stat_inode = stat.inode, |
| 2921 | 2900 | .stat_mtime = stat.mtime, |
| 2922 | 2901 | }; |
| 2923 | var iovecs: [5]std.posix.iovec_const = .{ | |
| 2924 | .{ | |
| 2925 | .base = @ptrCast(&header), | |
| 2926 | .len = @sizeOf(Zir.Header), | |
| 2927 | }, | |
| 2928 | .{ | |
| 2929 | .base = @ptrCast(zir.instructions.items(.tag).ptr), | |
| 2930 | .len = zir.instructions.len, | |
| 2931 | }, | |
| 2932 | .{ | |
| 2933 | .base = data_ptr, | |
| 2934 | .len = zir.instructions.len * 8, | |
| 2935 | }, | |
| 2936 | .{ | |
| 2937 | .base = zir.string_bytes.ptr, | |
| 2938 | .len = zir.string_bytes.len, | |
| 2939 | }, | |
| 2940 | .{ | |
| 2941 | .base = @ptrCast(zir.extra.ptr), | |
| 2942 | .len = zir.extra.len * 4, | |
| 2943 | }, | |
| 2902 | var vecs = [_][]const u8{ | |
| 2903 | @ptrCast((&header)[0..1]), | |
| 2904 | @ptrCast(zir.instructions.items(.tag)), | |
| 2905 | if (data_has_safety_tag) | |
| 2906 | @ptrCast(safety_buffer) | |
| 2907 | else | |
| 2908 | @ptrCast(zir.instructions.items(.data)), | |
| 2909 | zir.string_bytes, | |
| 2910 | @ptrCast(zir.extra), | |
| 2911 | }; | |
| 2912 | var cache_fw = cache_file.writer(); | |
| 2913 | var cache_bw = cache_fw.interface().unbuffered(); | |
| 2914 | cache_bw.writeVecAll(&vecs) catch |err| switch (err) { | |
| 2915 | error.WriteFailed => if (cache_fw.err) |_| unreachable else |e| return e, | |
| 2944 | 2916 | }; |
| 2945 | try cache_file.writevAll(&iovecs); | |
| 2946 | 2917 | } |
| 2947 | 2918 | |
| 2948 | 2919 | pub fn saveZoirCache(cache_file: std.fs.File, stat: std.fs.File.Stat, zoir: Zoir) std.fs.File.WriteError!void { |
| ... | ... | @@ -2958,45 +2929,22 @@ pub fn saveZoirCache(cache_file: std.fs.File, stat: std.fs.File.Stat, zoir: Zoir |
| 2958 | 2929 | .stat_inode = stat.inode, |
| 2959 | 2930 | .stat_mtime = stat.mtime, |
| 2960 | 2931 | }; |
| 2961 | var iovecs: [9]std.posix.iovec_const = .{ | |
| 2962 | .{ | |
| 2963 | .base = @ptrCast(&header), | |
| 2964 | .len = @sizeOf(Zoir.Header), | |
| 2965 | }, | |
| 2966 | .{ | |
| 2967 | .base = @ptrCast(zoir.nodes.items(.tag)), | |
| 2968 | .len = zoir.nodes.len * @sizeOf(Zoir.Node.Repr.Tag), | |
| 2969 | }, | |
| 2970 | .{ | |
| 2971 | .base = @ptrCast(zoir.nodes.items(.data)), | |
| 2972 | .len = zoir.nodes.len * 4, | |
| 2973 | }, | |
| 2974 | .{ | |
| 2975 | .base = @ptrCast(zoir.nodes.items(.ast_node)), | |
| 2976 | .len = zoir.nodes.len * 4, | |
| 2977 | }, | |
| 2978 | .{ | |
| 2979 | .base = @ptrCast(zoir.extra), | |
| 2980 | .len = zoir.extra.len * 4, | |
| 2981 | }, | |
| 2982 | .{ | |
| 2983 | .base = @ptrCast(zoir.limbs), | |
| 2984 | .len = zoir.limbs.len * @sizeOf(std.math.big.Limb), | |
| 2985 | }, | |
| 2986 | .{ | |
| 2987 | .base = zoir.string_bytes.ptr, | |
| 2988 | .len = zoir.string_bytes.len, | |
| 2989 | }, | |
| 2990 | .{ | |
| 2991 | .base = @ptrCast(zoir.compile_errors), | |
| 2992 | .len = zoir.compile_errors.len * @sizeOf(Zoir.CompileError), | |
| 2993 | }, | |
| 2994 | .{ | |
| 2995 | .base = @ptrCast(zoir.error_notes), | |
| 2996 | .len = zoir.error_notes.len * @sizeOf(Zoir.CompileError.Note), | |
| 2997 | }, | |
| 2932 | var vecs = [_][]const u8{ | |
| 2933 | @ptrCast((&header)[0..1]), | |
| 2934 | @ptrCast(zoir.nodes.items(.tag)), | |
| 2935 | @ptrCast(zoir.nodes.items(.data)), | |
| 2936 | @ptrCast(zoir.nodes.items(.ast_node)), | |
| 2937 | @ptrCast(zoir.extra), | |
| 2938 | @ptrCast(zoir.limbs), | |
| 2939 | zoir.string_bytes, | |
| 2940 | @ptrCast(zoir.compile_errors), | |
| 2941 | @ptrCast(zoir.error_notes), | |
| 2942 | }; | |
| 2943 | var cache_fw = cache_file.writer(); | |
| 2944 | var cache_bw = cache_fw.interface().unbuffered(); | |
| 2945 | cache_bw.writeVecAll(&vecs) catch |err| switch (err) { | |
| 2946 | error.WriteFailed => if (cache_fw.err) |_| unreachable else |e| return e, | |
| 2998 | 2947 | }; |
| 2999 | try cache_file.writevAll(&iovecs); | |
| 3000 | 2948 | } |
| 3001 | 2949 | |
| 3002 | 2950 | pub fn loadZoirCacheBody(gpa: Allocator, header: Zoir.Header, cache_file: std.fs.File) !Zoir { |
| ... | ... | @@ -3025,49 +2973,22 @@ pub fn loadZoirCacheBody(gpa: Allocator, header: Zoir.Header, cache_file: std.fs |
| 3025 | 2973 | zoir.compile_errors = try gpa.alloc(Zoir.CompileError, header.compile_errors_len); |
| 3026 | 2974 | zoir.error_notes = try gpa.alloc(Zoir.CompileError.Note, header.error_notes_len); |
| 3027 | 2975 | |
| 3028 | var iovecs: [8]std.posix.iovec = .{ | |
| 3029 | .{ | |
| 3030 | .base = @ptrCast(zoir.nodes.items(.tag)), | |
| 3031 | .len = header.nodes_len * @sizeOf(Zoir.Node.Repr.Tag), | |
| 3032 | }, | |
| 3033 | .{ | |
| 3034 | .base = @ptrCast(zoir.nodes.items(.data)), | |
| 3035 | .len = header.nodes_len * 4, | |
| 3036 | }, | |
| 3037 | .{ | |
| 3038 | .base = @ptrCast(zoir.nodes.items(.ast_node)), | |
| 3039 | .len = header.nodes_len * 4, | |
| 3040 | }, | |
| 3041 | .{ | |
| 3042 | .base = @ptrCast(zoir.extra), | |
| 3043 | .len = header.extra_len * 4, | |
| 3044 | }, | |
| 3045 | .{ | |
| 3046 | .base = @ptrCast(zoir.limbs), | |
| 3047 | .len = header.limbs_len * @sizeOf(std.math.big.Limb), | |
| 3048 | }, | |
| 3049 | .{ | |
| 3050 | .base = zoir.string_bytes.ptr, | |
| 3051 | .len = header.string_bytes_len, | |
| 3052 | }, | |
| 3053 | .{ | |
| 3054 | .base = @ptrCast(zoir.compile_errors), | |
| 3055 | .len = header.compile_errors_len * @sizeOf(Zoir.CompileError), | |
| 3056 | }, | |
| 3057 | .{ | |
| 3058 | .base = @ptrCast(zoir.error_notes), | |
| 3059 | .len = header.error_notes_len * @sizeOf(Zoir.CompileError.Note), | |
| 3060 | }, | |
| 2976 | var vecs = [_][]u8{ | |
| 2977 | @ptrCast(zoir.nodes.items(.tag)), | |
| 2978 | @ptrCast(zoir.nodes.items(.data)), | |
| 2979 | @ptrCast(zoir.nodes.items(.ast_node)), | |
| 2980 | @ptrCast(zoir.extra), | |
| 2981 | @ptrCast(zoir.limbs), | |
| 2982 | zoir.string_bytes, | |
| 2983 | @ptrCast(zoir.compile_errors), | |
| 2984 | @ptrCast(zoir.error_notes), | |
| 3061 | 2985 | }; |
| 3062 | ||
| 3063 | const bytes_expected = expected: { | |
| 3064 | var n: usize = 0; | |
| 3065 | for (iovecs) |v| n += v.len; | |
| 3066 | break :expected n; | |
| 2986 | var cache_fr = cache_file.reader(); | |
| 2987 | var cache_br = cache_fr.interface().unbuffered(); | |
| 2988 | cache_br.readVecAll(&vecs) catch |err| switch (err) { | |
| 2989 | error.ReadFailed => if (cache_fr.err) |_| unreachable else |e| return e, | |
| 2990 | error.EndOfStream => return error.UnexpectedFileSize, | |
| 3067 | 2991 | }; |
| 3068 | ||
| 3069 | const bytes_read = try cache_file.readvAll(&iovecs); | |
| 3070 | if (bytes_read != bytes_expected) return error.UnexpectedFileSize; | |
| 3071 | 2992 | return zoir; |
| 3072 | 2993 | } |
| 3073 | 2994 |
src/Zcu/PerThread.zig+19-8| ... | ... | @@ -249,11 +249,14 @@ pub fn updateFile( |
| 249 | 249 | if (stat.size > std.math.maxInt(u32)) |
| 250 | 250 | return error.FileTooBig; |
| 251 | 251 | |
| 252 | const source = try gpa.allocSentinel(u8, @as(usize, @intCast(stat.size)), 0); | |
| 252 | const source = try gpa.allocSentinel(u8, @intCast(stat.size), 0); | |
| 253 | 253 | defer if (file.source == null) gpa.free(source); |
| 254 | const amt = try source_file.readAll(source); | |
| 255 | if (amt != stat.size) | |
| 256 | return error.UnexpectedEndOfFile; | |
| 254 | var source_fr = source_file.reader(); | |
| 255 | var source_br = source_fr.interface().unbuffered(); | |
| 256 | source_br.readSlice(source) catch |err| switch (err) { | |
| 257 | error.ReadFailed => if (source_fr.err) |_| unreachable else |e| return e, | |
| 258 | error.EndOfStream => return error.UnexpectedEndOfFile, | |
| 259 | }; | |
| 257 | 260 | |
| 258 | 261 | file.source = source; |
| 259 | 262 | |
| ... | ... | @@ -340,13 +343,17 @@ fn loadZirZoirCache( |
| 340 | 343 | .zon => Zoir.Header, |
| 341 | 344 | }; |
| 342 | 345 | |
| 346 | var buffer: [@sizeOf(Header)]u8 = undefined; | |
| 347 | var cache_fr = cache_file.reader(); | |
| 348 | var cache_br = cache_fr.interface().buffered(&buffer); | |
| 349 | ||
| 343 | 350 | // First we read the header to determine the lengths of arrays. |
| 344 | const header = cache_file.reader().readStruct(Header) catch |err| switch (err) { | |
| 351 | const header = (cache_br.takeStruct(Header) catch |err| switch (err) { | |
| 345 | 352 | // This can happen if Zig bails out of this function between creating |
| 346 | 353 | // the cached file and writing it. |
| 347 | 354 | error.EndOfStream => return .invalid, |
| 348 | 355 | else => |e| return e, |
| 349 | }; | |
| 356 | }).*; | |
| 350 | 357 | |
| 351 | 358 | const unchanged_metadata = |
| 352 | 359 | stat.size == header.stat_size and |
| ... | ... | @@ -2433,8 +2440,12 @@ fn updateEmbedFileInner( |
| 2433 | 2440 | const old_len = strings.mutate.len; |
| 2434 | 2441 | errdefer strings.shrinkRetainingCapacity(old_len); |
| 2435 | 2442 | const bytes = (try strings.addManyAsSlice(size_plus_one))[0]; |
| 2436 | const actual_read = try file.readAll(bytes[0..size]); | |
| 2437 | if (actual_read != size) return error.UnexpectedEof; | |
| 2443 | var fr = file.reader(); | |
| 2444 | var br = fr.interface().unbuffered(); | |
| 2445 | br.readSlice(bytes[0..size]) catch |err| switch (err) { | |
| 2446 | error.ReadFailed => if (fr.err) |_| unreachable else |e| return e, | |
| 2447 | error.EndOfStream => return error.UnexpectedEof, | |
| 2448 | }; | |
| 2438 | 2449 | bytes[size] = 0; |
| 2439 | 2450 | break :str try ip.getOrPutTrailingString(gpa, tid, @intCast(bytes.len), .maybe_embedded_nulls); |
| 2440 | 2451 | }; |
src/crash_report.zig+40-33| ... | ... | @@ -80,18 +80,19 @@ fn dumpStatusReport() !void { |
| 80 | 80 | var fba = std.heap.FixedBufferAllocator.init(&crash_heap); |
| 81 | 81 | const allocator = fba.allocator(); |
| 82 | 82 | |
| 83 | var stderr = std.fs.File.stderr().writer().unbuffered(); | |
| 83 | var stderr_fw = std.fs.File.stderr().writer(); | |
| 84 | var stderr_bw = stderr_fw.interface().unbuffered(); | |
| 84 | 85 | const block: *Sema.Block = anal.block; |
| 85 | 86 | const zcu = anal.sema.pt.zcu; |
| 86 | 87 | |
| 87 | 88 | const file, const src_base_node = Zcu.LazySrcLoc.resolveBaseNode(block.src_base_inst, zcu) orelse { |
| 88 | 89 | const file = zcu.fileByIndex(block.src_base_inst.resolveFile(&zcu.intern_pool)); |
| 89 | try stderr.print("Analyzing lost instruction in file '{f}'. This should not happen!\n\n", .{file.path.fmt(zcu.comp)}); | |
| 90 | try stderr_bw.print("Analyzing lost instruction in file '{f}'. This should not happen!\n\n", .{file.path.fmt(zcu.comp)}); | |
| 90 | 91 | return; |
| 91 | 92 | }; |
| 92 | 93 | |
| 93 | try stderr.writeAll("Analyzing "); | |
| 94 | try stderr.print("Analyzing '{f}'\n", .{file.path.fmt(zcu.comp)}); | |
| 94 | try stderr_bw.writeAll("Analyzing "); | |
| 95 | try stderr_bw.print("Analyzing '{f}'\n", .{file.path.fmt(zcu.comp)}); | |
| 95 | 96 | |
| 96 | 97 | print_zir.renderInstructionContext( |
| 97 | 98 | allocator, |
| ... | ... | @@ -100,12 +101,12 @@ fn dumpStatusReport() !void { |
| 100 | 101 | file, |
| 101 | 102 | src_base_node, |
| 102 | 103 | 6, // indent |
| 103 | &stderr, | |
| 104 | &stderr_bw, | |
| 104 | 105 | ) catch |err| switch (err) { |
| 105 | error.OutOfMemory => try stderr.writeAll(" <out of memory dumping zir>\n"), | |
| 106 | error.OutOfMemory => try stderr_bw.writeAll(" <out of memory dumping zir>\n"), | |
| 106 | 107 | else => |e| return e, |
| 107 | 108 | }; |
| 108 | try stderr.print( | |
| 109 | try stderr_bw.print( | |
| 109 | 110 | \\ For full context, use the command |
| 110 | 111 | \\ zig ast-check -t {f} |
| 111 | 112 | \\ |
| ... | ... | @@ -116,30 +117,30 @@ fn dumpStatusReport() !void { |
| 116 | 117 | while (parent) |curr| { |
| 117 | 118 | fba.reset(); |
| 118 | 119 | const cur_block_file = zcu.fileByIndex(curr.block.src_base_inst.resolveFile(&zcu.intern_pool)); |
| 119 | try stderr.print(" in {f}\n", .{cur_block_file.path.fmt(zcu.comp)}); | |
| 120 | try stderr_bw.print(" in {f}\n", .{cur_block_file.path.fmt(zcu.comp)}); | |
| 120 | 121 | _, const cur_block_src_base_node = Zcu.LazySrcLoc.resolveBaseNode(curr.block.src_base_inst, zcu) orelse { |
| 121 | try stderr.writeAll(" > [lost instruction; this should not happen]\n"); | |
| 122 | try stderr_bw.writeAll(" > [lost instruction; this should not happen]\n"); | |
| 122 | 123 | parent = curr.parent; |
| 123 | 124 | continue; |
| 124 | 125 | }; |
| 125 | try stderr.writeAll(" > "); | |
| 126 | try stderr_bw.writeAll(" > "); | |
| 126 | 127 | print_zir.renderSingleInstruction( |
| 127 | 128 | allocator, |
| 128 | 129 | curr.body[curr.body_index], |
| 129 | 130 | cur_block_file, |
| 130 | 131 | cur_block_src_base_node, |
| 131 | 132 | 6, // indent |
| 132 | &stderr, | |
| 133 | &stderr_bw, | |
| 133 | 134 | ) catch |err| switch (err) { |
| 134 | error.OutOfMemory => try stderr.writeAll(" <out of memory dumping zir>\n"), | |
| 135 | error.OutOfMemory => try stderr_bw.writeAll(" <out of memory dumping zir>\n"), | |
| 135 | 136 | else => |e| return e, |
| 136 | 137 | }; |
| 137 | try stderr.writeAll("\n"); | |
| 138 | try stderr_bw.writeAll("\n"); | |
| 138 | 139 | |
| 139 | 140 | parent = curr.parent; |
| 140 | 141 | } |
| 141 | 142 | |
| 142 | try stderr.writeByte('\n'); | |
| 143 | try stderr_bw.writeByte('\n'); | |
| 143 | 144 | } |
| 144 | 145 | |
| 145 | 146 | var crash_heap: [16 * 4096]u8 = undefined; |
| ... | ... | @@ -268,8 +269,9 @@ const StackContext = union(enum) { |
| 268 | 269 | debug.dumpCurrentStackTrace(ct.ret_addr); |
| 269 | 270 | }, |
| 270 | 271 | .exception => |context| { |
| 271 | var stderr = std.fs.File.stderr().writer().unbuffered(); | |
| 272 | debug.dumpStackTraceFromBase(context, &stderr); | |
| 272 | var stderr_fw = std.fs.File.stderr().writer(); | |
| 273 | var stderr_bw = stderr_fw.interface().unbuffered(); | |
| 274 | debug.dumpStackTraceFromBase(context, &stderr_bw); | |
| 273 | 275 | }, |
| 274 | 276 | .not_supported => { |
| 275 | 277 | std.fs.File.stderr().writeAll("Stack trace not supported on this platform.\n") catch {}; |
| ... | ... | @@ -379,19 +381,20 @@ const PanicSwitch = struct { |
| 379 | 381 | |
| 380 | 382 | state.recover_stage = .release_mutex; |
| 381 | 383 | |
| 382 | var stderr = std.fs.File.stderr().writer().unbuffered(); | |
| 384 | var stderr_fw = std.fs.File.stderr().writer(); | |
| 385 | var stderr_bw = stderr_fw.interface().unbuffered(); | |
| 383 | 386 | if (builtin.single_threaded) { |
| 384 | stderr.print("panic: ", .{}) catch goTo(releaseMutex, .{state}); | |
| 387 | stderr_bw.print("panic: ", .{}) catch goTo(releaseMutex, .{state}); | |
| 385 | 388 | } else { |
| 386 | 389 | const current_thread_id = std.Thread.getCurrentId(); |
| 387 | stderr.print("thread {} panic: ", .{current_thread_id}) catch goTo(releaseMutex, .{state}); | |
| 390 | stderr_bw.print("thread {} panic: ", .{current_thread_id}) catch goTo(releaseMutex, .{state}); | |
| 388 | 391 | } |
| 389 | stderr.print("{s}\n", .{msg}) catch goTo(releaseMutex, .{state}); | |
| 392 | stderr_bw.print("{s}\n", .{msg}) catch goTo(releaseMutex, .{state}); | |
| 390 | 393 | |
| 391 | 394 | state.recover_stage = .report_stack; |
| 392 | 395 | |
| 393 | 396 | dumpStatusReport() catch |err| { |
| 394 | stderr.print("\nIntercepted error.{} while dumping current state. Continuing...\n", .{err}) catch {}; | |
| 397 | stderr_bw.print("\nIntercepted error.{} while dumping current state. Continuing...\n", .{err}) catch {}; | |
| 395 | 398 | }; |
| 396 | 399 | |
| 397 | 400 | goTo(reportStack, .{state}); |
| ... | ... | @@ -406,8 +409,9 @@ const PanicSwitch = struct { |
| 406 | 409 | recover(state, trace, stack, msg); |
| 407 | 410 | |
| 408 | 411 | state.recover_stage = .release_mutex; |
| 409 | var stderr = std.fs.File.stderr().writer().unbuffered(); | |
| 410 | stderr.writeAll("\nOriginal Error:\n") catch {}; | |
| 412 | var stderr_fw = std.fs.File.stderr().writer(); | |
| 413 | var stderr_bw = stderr_fw.interface().unbuffered(); | |
| 414 | stderr_bw.writeAll("\nOriginal Error:\n") catch {}; | |
| 411 | 415 | goTo(reportStack, .{state}); |
| 412 | 416 | } |
| 413 | 417 | |
| ... | ... | @@ -477,8 +481,9 @@ const PanicSwitch = struct { |
| 477 | 481 | recover(state, trace, stack, msg); |
| 478 | 482 | |
| 479 | 483 | state.recover_stage = .silent_abort; |
| 480 | var stderr = std.fs.File.stderr().writer().unbuffered(); | |
| 481 | stderr.writeAll("Aborting...\n") catch {}; | |
| 484 | var stderr_fw = std.fs.File.stderr().writer(); | |
| 485 | var stderr_bw = stderr_fw.interface().unbuffered(); | |
| 486 | stderr_bw.writeAll("Aborting...\n") catch {}; | |
| 482 | 487 | goTo(abort, .{}); |
| 483 | 488 | } |
| 484 | 489 | |
| ... | ... | @@ -505,10 +510,11 @@ const PanicSwitch = struct { |
| 505 | 510 | // lower the verbosity, and restore it at the end if we don't panic. |
| 506 | 511 | state.recover_verbosity = .message_only; |
| 507 | 512 | |
| 508 | var stderr = std.fs.File.stderr().writer().unbuffered(); | |
| 509 | stderr.writeAll("\nPanicked during a panic: ") catch {}; | |
| 510 | stderr.writeAll(msg) catch {}; | |
| 511 | stderr.writeAll("\nInner panic stack:\n") catch {}; | |
| 513 | var stderr_fw = std.fs.File.stderr().writer(); | |
| 514 | var stderr_bw = stderr_fw.interface().unbuffered(); | |
| 515 | stderr_bw.writeAll("\nPanicked during a panic: ") catch {}; | |
| 516 | stderr_bw.writeAll(msg) catch {}; | |
| 517 | stderr_bw.writeAll("\nInner panic stack:\n") catch {}; | |
| 512 | 518 | if (trace) |t| { |
| 513 | 519 | debug.dumpStackTrace(t.*); |
| 514 | 520 | } |
| ... | ... | @@ -519,10 +525,11 @@ const PanicSwitch = struct { |
| 519 | 525 | .message_only => { |
| 520 | 526 | state.recover_verbosity = .silent; |
| 521 | 527 | |
| 522 | var stderr = std.fs.File.stderr().writer().unbuffered(); | |
| 523 | stderr.writeAll("\nPanicked while dumping inner panic stack: ") catch {}; | |
| 524 | stderr.writeAll(msg) catch {}; | |
| 525 | stderr.writeByte('\n') catch {}; | |
| 528 | var stderr_fw = std.fs.File.stderr().writer(); | |
| 529 | var stderr_bw = stderr_fw.interface().unbuffered(); | |
| 530 | stderr_bw.writeAll("\nPanicked while dumping inner panic stack: ") catch {}; | |
| 531 | stderr_bw.writeAll(msg) catch {}; | |
| 532 | stderr_bw.writeByte('\n') catch {}; | |
| 526 | 533 | |
| 527 | 534 | // If we succeed, restore all the way to dumping the stack. |
| 528 | 535 | state.recover_verbosity = .message_and_stack; |
src/print_value.zig+4-4| ... | ... | @@ -47,7 +47,7 @@ pub fn print( |
| 47 | 47 | level: u8, |
| 48 | 48 | pt: Zcu.PerThread, |
| 49 | 49 | opt_sema: ?*Sema, |
| 50 | ) std.io.Writer.Error!void { | |
| 50 | ) (std.io.Writer.Error || Zcu.CompileError)!void { | |
| 51 | 51 | const zcu = pt.zcu; |
| 52 | 52 | const ip = &zcu.intern_pool; |
| 53 | 53 | switch (ip.indexToKey(val.toIntern())) { |
| ... | ... | @@ -190,7 +190,7 @@ fn printAggregate( |
| 190 | 190 | level: u8, |
| 191 | 191 | pt: Zcu.PerThread, |
| 192 | 192 | opt_sema: ?*Sema, |
| 193 | ) std.io.Writer.Error!void { | |
| 193 | ) (std.io.Writer.Error || Zcu.CompileError)!void { | |
| 194 | 194 | if (level == 0) { |
| 195 | 195 | if (is_ref) try bw.writeByte('&'); |
| 196 | 196 | return bw.writeAll(".{ ... }"); |
| ... | ... | @@ -276,7 +276,7 @@ fn printPtr( |
| 276 | 276 | level: u8, |
| 277 | 277 | pt: Zcu.PerThread, |
| 278 | 278 | opt_sema: ?*Sema, |
| 279 | ) std.io.Writer.Error!void { | |
| 279 | ) (std.io.Writer.Error || Zcu.CompileError)!void { | |
| 280 | 280 | const ptr = switch (pt.zcu.intern_pool.indexToKey(ptr_val.toIntern())) { |
| 281 | 281 | .undef => return bw.writeAll("undefined"), |
| 282 | 282 | .ptr => |ptr| ptr, |
| ... | ... | @@ -336,7 +336,7 @@ pub fn printPtrDerivation( |
| 336 | 336 | /// The maximum recursion depth. We can never recurse infinitely here, but the depth can be arbitrary, |
| 337 | 337 | /// so at this depth we just write "..." to prevent stack overflow. |
| 338 | 338 | ptr_depth: u8, |
| 339 | ) std.io.Writer.Error!Value.PointerDeriveStep { | |
| 339 | ) (std.io.Writer.Error || Zcu.CompileError)!Value.PointerDeriveStep { | |
| 340 | 340 | const zcu = pt.zcu; |
| 341 | 341 | const ip = &zcu.intern_pool; |
| 342 | 342 |
src/print_zir.zig+1-1| ... | ... | @@ -176,7 +176,7 @@ const Writer = struct { |
| 176 | 176 | } |
| 177 | 177 | } = .{}, |
| 178 | 178 | |
| 179 | const Error = std.io.Writer.Error; | |
| 179 | const Error = std.io.Writer.Error || std.mem.Allocator.Error; | |
| 180 | 180 | |
| 181 | 181 | fn writeInstToStream( |
| 182 | 182 | self: *Writer, |