authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-02-19 11:22:06-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-01 16:35:26-07:00
log2fb6ce2f92ee79fa4171dccc6cb262db2e91d63a
treec793630e7b42ec4a2f48571f958a8fd820e812b5
parent4aed226e07a911be88ed6e2f349796364d3327f7

update some more compiler code


12 files changed, 139 insertions(+), 121 deletions(-)

lib/std/io/AllocatingWriter.zig+6
...@@ -90,6 +90,12 @@ pub fn toOwnedSlice(aw: *AllocatingWriter) error{OutOfMemory}![]u8 {...@@ -90,6 +90,12 @@ pub fn toOwnedSlice(aw: *AllocatingWriter) error{OutOfMemory}![]u8 {
90 return list.toOwnedSlice(gpa);90 return list.toOwnedSlice(gpa);
91}91}
9292
93pub fn toOwnedSliceSentinel(aw: *AllocatingWriter, comptime sentinel: u8) error{OutOfMemory}![:sentinel]u8 {
94 const gpa = aw.allocator;
95 var list = toArrayList(aw);
96 return list.toOwnedSliceSentinel(gpa, sentinel);
97}
98
93fn setArrayList(aw: *AllocatingWriter, list: std.ArrayListUnmanaged(u8)) void {99fn setArrayList(aw: *AllocatingWriter, list: std.ArrayListUnmanaged(u8)) void {
94 aw.written = list.items;100 aw.written = list.items;
95 aw.buffered_writer.buffer = list.unusedCapacitySlice();101 aw.buffered_writer.buffer = list.unusedCapacitySlice();
src/Air.zig+3-3
...@@ -960,9 +960,9 @@ pub const Inst = struct {...@@ -960,9 +960,9 @@ pub const Inst = struct {
960 pub fn format(960 pub fn format(
961 index: Index,961 index: Index,
962 comptime _: []const u8,962 comptime _: []const u8,
963 _: std.fmt.FormatOptions,963 _: std.fmt.Options,
964 writer: anytype,964 writer: *std.io.BufferedWriter,
965 ) @TypeOf(writer).Error!void {965 ) anyerror!void {
966 try writer.writeByte('%');966 try writer.writeByte('%');
967 switch (index.unwrap()) {967 switch (index.unwrap()) {
968 .ref => {},968 .ref => {},
src/Air/print.zig+72-67
...@@ -8,7 +8,7 @@ const Type = @import("../Type.zig");...@@ -8,7 +8,7 @@ const Type = @import("../Type.zig");
8const Air = @import("../Air.zig");8const Air = @import("../Air.zig");
9const InternPool = @import("../InternPool.zig");9const InternPool = @import("../InternPool.zig");
1010
11pub fn write(air: Air, stream: anytype, pt: Zcu.PerThread, liveness: ?Air.Liveness) void {11pub fn write(air: Air, stream: *std.io.BufferedWriter, pt: Zcu.PerThread, liveness: ?Air.Liveness) void {
12 comptime std.debug.assert(build_options.enable_debug_extensions);12 comptime std.debug.assert(build_options.enable_debug_extensions);
13 const instruction_bytes = air.instructions.len *13 const instruction_bytes = air.instructions.len *
14 // Here we don't use @sizeOf(Air.Inst.Data) because it would include14 // Here we don't use @sizeOf(Air.Inst.Data) because it would include
...@@ -54,7 +54,7 @@ pub fn write(air: Air, stream: anytype, pt: Zcu.PerThread, liveness: ?Air.Livene...@@ -54,7 +54,7 @@ pub fn write(air: Air, stream: anytype, pt: Zcu.PerThread, liveness: ?Air.Livene
5454
55pub fn writeInst(55pub fn writeInst(
56 air: Air,56 air: Air,
57 stream: anytype,57 stream: *std.io.BufferedWriter,
58 inst: Air.Inst.Index,58 inst: Air.Inst.Index,
59 pt: Zcu.PerThread,59 pt: Zcu.PerThread,
60 liveness: ?Air.Liveness,60 liveness: ?Air.Liveness,
...@@ -72,11 +72,15 @@ pub fn writeInst(...@@ -72,11 +72,15 @@ pub fn writeInst(
72}72}
7373
74pub fn dump(air: Air, pt: Zcu.PerThread, liveness: ?Air.Liveness) void {74pub fn dump(air: Air, pt: Zcu.PerThread, liveness: ?Air.Liveness) void {
75 air.write(std.io.getStdErr().writer(), pt, liveness);75 var bw = std.debug.lockStdErr2();
76 defer std.debug.unlockStdErr();
77 air.write(&bw, pt, liveness);
76}78}
7779
78pub fn dumpInst(air: Air, inst: Air.Inst.Index, pt: Zcu.PerThread, liveness: ?Air.Liveness) void {80pub fn dumpInst(air: Air, inst: Air.Inst.Index, pt: Zcu.PerThread, liveness: ?Air.Liveness) void {
79 air.writeInst(std.io.getStdErr().writer(), inst, pt, liveness);81 var bw = std.debug.lockStdErr2();
82 defer std.debug.unlockStdErr();
83 air.writeInst(&bw, inst, pt, liveness);
80}84}
8185
82const Writer = struct {86const Writer = struct {
...@@ -87,16 +91,16 @@ const Writer = struct {...@@ -87,16 +91,16 @@ const Writer = struct {
87 indent: usize,91 indent: usize,
88 skip_body: bool,92 skip_body: bool,
8993
90 fn writeBody(w: *Writer, s: anytype, body: []const Air.Inst.Index) @TypeOf(s).Error!void {94 fn writeBody(w: *Writer, s: *std.io.BufferedWriter, body: []const Air.Inst.Index) anyerror!void {
91 for (body) |inst| {95 for (body) |inst| {
92 try w.writeInst(s, inst);96 try w.writeInst(s, inst);
93 try s.writeByte('\n');97 try s.writeByte('\n');
94 }98 }
95 }99 }
96100
97 fn writeInst(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {101 fn writeInst(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
98 const tag = w.air.instructions.items(.tag)[@intFromEnum(inst)];102 const tag = w.air.instructions.items(.tag)[@intFromEnum(inst)];
99 try s.writeByteNTimes(' ', w.indent);103 try s.splatByteAll(' ', w.indent);
100 try s.print("{}{c}= {s}(", .{104 try s.print("{}{c}= {s}(", .{
101 inst,105 inst,
102 @as(u8, if (if (w.liveness) |liveness| liveness.isUnused(inst) else false) '!' else ' '),106 @as(u8, if (if (w.liveness) |liveness| liveness.isUnused(inst) else false) '!' else ' '),
...@@ -334,47 +338,48 @@ const Writer = struct {...@@ -334,47 +338,48 @@ const Writer = struct {
334 try s.writeByte(')');338 try s.writeByte(')');
335 }339 }
336340
337 fn writeBinOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {341 fn writeBinOp(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
338 const bin_op = w.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;342 const bin_op = w.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
339 try w.writeOperand(s, inst, 0, bin_op.lhs);343 try w.writeOperand(s, inst, 0, bin_op.lhs);
340 try s.writeAll(", ");344 try s.writeAll(", ");
341 try w.writeOperand(s, inst, 1, bin_op.rhs);345 try w.writeOperand(s, inst, 1, bin_op.rhs);
342 }346 }
343347
344 fn writeUnOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {348 fn writeUnOp(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
345 const un_op = w.air.instructions.items(.data)[@intFromEnum(inst)].un_op;349 const un_op = w.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
346 try w.writeOperand(s, inst, 0, un_op);350 try w.writeOperand(s, inst, 0, un_op);
347 }351 }
348352
349 fn writeNoOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {353 fn writeNoOp(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
350 _ = w;354 _ = w;
355 _ = s;
351 _ = inst;356 _ = inst;
352 // no-op, no argument to write357 // no-op, no argument to write
353 }358 }
354359
355 fn writeType(w: *Writer, s: anytype, ty: Type) !void {360 fn writeType(w: *Writer, s: *std.io.BufferedWriter, ty: Type) !void {
356 return ty.print(s, w.pt);361 return ty.print(s, w.pt);
357 }362 }
358363
359 fn writeTy(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {364 fn writeTy(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
360 const ty = w.air.instructions.items(.data)[@intFromEnum(inst)].ty;365 const ty = w.air.instructions.items(.data)[@intFromEnum(inst)].ty;
361 try w.writeType(s, ty);366 try w.writeType(s, ty);
362 }367 }
363368
364 fn writeArg(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {369 fn writeArg(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
365 const arg = w.air.instructions.items(.data)[@intFromEnum(inst)].arg;370 const arg = w.air.instructions.items(.data)[@intFromEnum(inst)].arg;
366 try w.writeType(s, arg.ty.toType());371 try w.writeType(s, arg.ty.toType());
367 try s.print(", {d}", .{arg.zir_param_index});372 try s.print(", {d}", .{arg.zir_param_index});
368 }373 }
369374
370 fn writeTyOp(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {375 fn writeTyOp(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
371 const ty_op = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;376 const ty_op = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
372 try w.writeType(s, ty_op.ty.toType());377 try w.writeType(s, ty_op.ty.toType());
373 try s.writeAll(", ");378 try s.writeAll(", ");
374 try w.writeOperand(s, inst, 0, ty_op.operand);379 try w.writeOperand(s, inst, 0, ty_op.operand);
375 }380 }
376381
377 fn writeBlock(w: *Writer, s: anytype, tag: Air.Inst.Tag, inst: Air.Inst.Index) @TypeOf(s).Error!void {382 fn writeBlock(w: *Writer, s: *std.io.BufferedWriter, tag: Air.Inst.Tag, inst: Air.Inst.Index) anyerror!void {
378 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;383 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
379 try w.writeType(s, ty_pl.ty.toType());384 try w.writeType(s, ty_pl.ty.toType());
380 const body: []const Air.Inst.Index = @ptrCast(switch (tag) {385 const body: []const Air.Inst.Index = @ptrCast(switch (tag) {
...@@ -407,7 +412,7 @@ const Writer = struct {...@@ -407,7 +412,7 @@ const Writer = struct {
407 w.indent += 2;412 w.indent += 2;
408 try w.writeBody(s, body);413 try w.writeBody(s, body);
409 w.indent = old_indent;414 w.indent = old_indent;
410 try s.writeByteNTimes(' ', w.indent);415 try s.splatByteAll(' ', w.indent);
411 try s.writeAll("}");416 try s.writeAll("}");
412417
413 for (liveness_block.deaths) |operand| {418 for (liveness_block.deaths) |operand| {
...@@ -415,7 +420,7 @@ const Writer = struct {...@@ -415,7 +420,7 @@ const Writer = struct {
415 }420 }
416 }421 }
417422
418 fn writeLoop(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {423 fn writeLoop(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
419 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;424 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
420 const extra = w.air.extraData(Air.Block, ty_pl.payload);425 const extra = w.air.extraData(Air.Block, ty_pl.payload);
421 const body: []const Air.Inst.Index = @ptrCast(w.air.extra.items[extra.end..][0..extra.data.body_len]);426 const body: []const Air.Inst.Index = @ptrCast(w.air.extra.items[extra.end..][0..extra.data.body_len]);
...@@ -427,11 +432,11 @@ const Writer = struct {...@@ -427,11 +432,11 @@ const Writer = struct {
427 w.indent += 2;432 w.indent += 2;
428 try w.writeBody(s, body);433 try w.writeBody(s, body);
429 w.indent = old_indent;434 w.indent = old_indent;
430 try s.writeByteNTimes(' ', w.indent);435 try s.splatByteAll(' ', w.indent);
431 try s.writeAll("}");436 try s.writeAll("}");
432 }437 }
433438
434 fn writeAggregateInit(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {439 fn writeAggregateInit(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
435 const zcu = w.pt.zcu;440 const zcu = w.pt.zcu;
436 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;441 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
437 const vector_ty = ty_pl.ty.toType();442 const vector_ty = ty_pl.ty.toType();
...@@ -447,7 +452,7 @@ const Writer = struct {...@@ -447,7 +452,7 @@ const Writer = struct {
447 try s.writeAll("]");452 try s.writeAll("]");
448 }453 }
449454
450 fn writeUnionInit(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {455 fn writeUnionInit(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
451 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;456 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
452 const extra = w.air.extraData(Air.UnionInit, ty_pl.payload).data;457 const extra = w.air.extraData(Air.UnionInit, ty_pl.payload).data;
453458
...@@ -455,7 +460,7 @@ const Writer = struct {...@@ -455,7 +460,7 @@ const Writer = struct {
455 try w.writeOperand(s, inst, 0, extra.init);460 try w.writeOperand(s, inst, 0, extra.init);
456 }461 }
457462
458 fn writeStructField(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {463 fn writeStructField(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
459 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;464 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
460 const extra = w.air.extraData(Air.StructField, ty_pl.payload).data;465 const extra = w.air.extraData(Air.StructField, ty_pl.payload).data;
461466
...@@ -463,7 +468,7 @@ const Writer = struct {...@@ -463,7 +468,7 @@ const Writer = struct {
463 try s.print(", {d}", .{extra.field_index});468 try s.print(", {d}", .{extra.field_index});
464 }469 }
465470
466 fn writeTyPlBin(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {471 fn writeTyPlBin(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
467 const data = w.air.instructions.items(.data);472 const data = w.air.instructions.items(.data);
468 const ty_pl = data[@intFromEnum(inst)].ty_pl;473 const ty_pl = data[@intFromEnum(inst)].ty_pl;
469 const extra = w.air.extraData(Air.Bin, ty_pl.payload).data;474 const extra = w.air.extraData(Air.Bin, ty_pl.payload).data;
...@@ -476,7 +481,7 @@ const Writer = struct {...@@ -476,7 +481,7 @@ const Writer = struct {
476 try w.writeOperand(s, inst, 1, extra.rhs);481 try w.writeOperand(s, inst, 1, extra.rhs);
477 }482 }
478483
479 fn writeCmpxchg(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {484 fn writeCmpxchg(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
480 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;485 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
481 const extra = w.air.extraData(Air.Cmpxchg, ty_pl.payload).data;486 const extra = w.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
482487
...@@ -490,7 +495,7 @@ const Writer = struct {...@@ -490,7 +495,7 @@ const Writer = struct {
490 });495 });
491 }496 }
492497
493 fn writeMulAdd(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {498 fn writeMulAdd(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
494 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;499 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
495 const extra = w.air.extraData(Air.Bin, pl_op.payload).data;500 const extra = w.air.extraData(Air.Bin, pl_op.payload).data;
496501
...@@ -501,7 +506,7 @@ const Writer = struct {...@@ -501,7 +506,7 @@ const Writer = struct {
501 try w.writeOperand(s, inst, 2, pl_op.operand);506 try w.writeOperand(s, inst, 2, pl_op.operand);
502 }507 }
503508
504 fn writeShuffleOne(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {509 fn writeShuffleOne(w: *Writer, s: anytype, inst: Air.Inst.Index) anyerror!void {
505 const unwrapped = w.air.unwrapShuffleOne(w.pt.zcu, inst);510 const unwrapped = w.air.unwrapShuffleOne(w.pt.zcu, inst);
506 try w.writeType(s, unwrapped.result_ty);511 try w.writeType(s, unwrapped.result_ty);
507 try s.writeAll(", ");512 try s.writeAll(", ");
...@@ -536,7 +541,7 @@ const Writer = struct {...@@ -536,7 +541,7 @@ const Writer = struct {
536 try s.writeByte(']');541 try s.writeByte(']');
537 }542 }
538543
539 fn writeSelect(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {544 fn writeSelect(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
540 const zcu = w.pt.zcu;545 const zcu = w.pt.zcu;
541 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;546 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
542 const extra = w.air.extraData(Air.Bin, pl_op.payload).data;547 const extra = w.air.extraData(Air.Bin, pl_op.payload).data;
...@@ -551,14 +556,14 @@ const Writer = struct {...@@ -551,14 +556,14 @@ const Writer = struct {
551 try w.writeOperand(s, inst, 2, extra.rhs);556 try w.writeOperand(s, inst, 2, extra.rhs);
552 }557 }
553558
554 fn writeReduce(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {559 fn writeReduce(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
555 const reduce = w.air.instructions.items(.data)[@intFromEnum(inst)].reduce;560 const reduce = w.air.instructions.items(.data)[@intFromEnum(inst)].reduce;
556561
557 try w.writeOperand(s, inst, 0, reduce.operand);562 try w.writeOperand(s, inst, 0, reduce.operand);
558 try s.print(", {s}", .{@tagName(reduce.operation)});563 try s.print(", {s}", .{@tagName(reduce.operation)});
559 }564 }
560565
561 fn writeCmpVector(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {566 fn writeCmpVector(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
562 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;567 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
563 const extra = w.air.extraData(Air.VectorCmp, ty_pl.payload).data;568 const extra = w.air.extraData(Air.VectorCmp, ty_pl.payload).data;
564569
...@@ -568,7 +573,7 @@ const Writer = struct {...@@ -568,7 +573,7 @@ const Writer = struct {
568 try w.writeOperand(s, inst, 1, extra.rhs);573 try w.writeOperand(s, inst, 1, extra.rhs);
569 }574 }
570575
571 fn writeVectorStoreElem(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {576 fn writeVectorStoreElem(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
572 const data = w.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem;577 const data = w.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem;
573 const extra = w.air.extraData(Air.VectorCmp, data.payload).data;578 const extra = w.air.extraData(Air.VectorCmp, data.payload).data;
574579
...@@ -579,21 +584,21 @@ const Writer = struct {...@@ -579,21 +584,21 @@ const Writer = struct {
579 try w.writeOperand(s, inst, 2, extra.rhs);584 try w.writeOperand(s, inst, 2, extra.rhs);
580 }585 }
581586
582 fn writeRuntimeNavPtr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {587 fn writeRuntimeNavPtr(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) std.io.Writer.Error!void {
583 const ip = &w.pt.zcu.intern_pool;588 const ip = &w.pt.zcu.intern_pool;
584 const ty_nav = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_nav;589 const ty_nav = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_nav;
585 try w.writeType(s, .fromInterned(ty_nav.ty));590 try w.writeType(s, .fromInterned(ty_nav.ty));
586 try s.print(", '{}'", .{ip.getNav(ty_nav.nav).fqn.fmt(ip)});591 try s.print(", '{}'", .{ip.getNav(ty_nav.nav).fqn.fmt(ip)});
587 }592 }
588593
589 fn writeAtomicLoad(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {594 fn writeAtomicLoad(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) std.io.Writer.Error!void {
590 const atomic_load = w.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load;595 const atomic_load = w.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load;
591596
592 try w.writeOperand(s, inst, 0, atomic_load.ptr);597 try w.writeOperand(s, inst, 0, atomic_load.ptr);
593 try s.print(", {s}", .{@tagName(atomic_load.order)});598 try s.print(", {s}", .{@tagName(atomic_load.order)});
594 }599 }
595600
596 fn writePrefetch(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {601 fn writePrefetch(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
597 const prefetch = w.air.instructions.items(.data)[@intFromEnum(inst)].prefetch;602 const prefetch = w.air.instructions.items(.data)[@intFromEnum(inst)].prefetch;
598603
599 try w.writeOperand(s, inst, 0, prefetch.ptr);604 try w.writeOperand(s, inst, 0, prefetch.ptr);
...@@ -604,10 +609,10 @@ const Writer = struct {...@@ -604,10 +609,10 @@ const Writer = struct {
604609
605 fn writeAtomicStore(610 fn writeAtomicStore(
606 w: *Writer,611 w: *Writer,
607 s: anytype,612 s: *std.io.BufferedWriter,
608 inst: Air.Inst.Index,613 inst: Air.Inst.Index,
609 order: std.builtin.AtomicOrder,614 order: std.builtin.AtomicOrder,
610 ) @TypeOf(s).Error!void {615 ) anyerror!void {
611 const bin_op = w.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;616 const bin_op = w.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
612 try w.writeOperand(s, inst, 0, bin_op.lhs);617 try w.writeOperand(s, inst, 0, bin_op.lhs);
613 try s.writeAll(", ");618 try s.writeAll(", ");
...@@ -615,7 +620,7 @@ const Writer = struct {...@@ -615,7 +620,7 @@ const Writer = struct {
615 try s.print(", {s}", .{@tagName(order)});620 try s.print(", {s}", .{@tagName(order)});
616 }621 }
617622
618 fn writeAtomicRmw(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {623 fn writeAtomicRmw(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
619 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;624 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
620 const extra = w.air.extraData(Air.AtomicRmw, pl_op.payload).data;625 const extra = w.air.extraData(Air.AtomicRmw, pl_op.payload).data;
621626
...@@ -625,7 +630,7 @@ const Writer = struct {...@@ -625,7 +630,7 @@ const Writer = struct {
625 try s.print(", {s}, {s}", .{ @tagName(extra.op()), @tagName(extra.ordering()) });630 try s.print(", {s}, {s}", .{ @tagName(extra.op()), @tagName(extra.ordering()) });
626 }631 }
627632
628 fn writeFieldParentPtr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {633 fn writeFieldParentPtr(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
629 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;634 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
630 const extra = w.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;635 const extra = w.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
631636
...@@ -633,7 +638,7 @@ const Writer = struct {...@@ -633,7 +638,7 @@ const Writer = struct {
633 try s.print(", {d}", .{extra.field_index});638 try s.print(", {d}", .{extra.field_index});
634 }639 }
635640
636 fn writeAssembly(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {641 fn writeAssembly(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
637 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;642 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
638 const extra = w.air.extraData(Air.Asm, ty_pl.payload);643 const extra = w.air.extraData(Air.Asm, ty_pl.payload);
639 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;644 const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
...@@ -706,19 +711,19 @@ const Writer = struct {...@@ -706,19 +711,19 @@ const Writer = struct {
706 try s.print(", \"{}\"", .{std.zig.fmtEscapes(asm_source)});711 try s.print(", \"{}\"", .{std.zig.fmtEscapes(asm_source)});
707 }712 }
708713
709 fn writeDbgStmt(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {714 fn writeDbgStmt(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
710 const dbg_stmt = w.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt;715 const dbg_stmt = w.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt;
711 try s.print("{d}:{d}", .{ dbg_stmt.line + 1, dbg_stmt.column + 1 });716 try s.print("{d}:{d}", .{ dbg_stmt.line + 1, dbg_stmt.column + 1 });
712 }717 }
713718
714 fn writeDbgVar(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {719 fn writeDbgVar(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
715 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;720 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
716 try w.writeOperand(s, inst, 0, pl_op.operand);721 try w.writeOperand(s, inst, 0, pl_op.operand);
717 const name: Air.NullTerminatedString = @enumFromInt(pl_op.payload);722 const name: Air.NullTerminatedString = @enumFromInt(pl_op.payload);
718 try s.print(", \"{}\"", .{std.zig.fmtEscapes(name.toSlice(w.air))});723 try s.print(", \"{}\"", .{std.zig.fmtEscapes(name.toSlice(w.air))});
719 }724 }
720725
721 fn writeCall(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {726 fn writeCall(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
722 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;727 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
723 const extra = w.air.extraData(Air.Call, pl_op.payload);728 const extra = w.air.extraData(Air.Call, pl_op.payload);
724 const args = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra.items[extra.end..][0..extra.data.args_len]));729 const args = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra.items[extra.end..][0..extra.data.args_len]));
...@@ -731,19 +736,19 @@ const Writer = struct {...@@ -731,19 +736,19 @@ const Writer = struct {
731 try s.writeAll("]");736 try s.writeAll("]");
732 }737 }
733738
734 fn writeBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {739 fn writeBr(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
735 const br = w.air.instructions.items(.data)[@intFromEnum(inst)].br;740 const br = w.air.instructions.items(.data)[@intFromEnum(inst)].br;
736 try w.writeInstIndex(s, br.block_inst, false);741 try w.writeInstIndex(s, br.block_inst, false);
737 try s.writeAll(", ");742 try s.writeAll(", ");
738 try w.writeOperand(s, inst, 0, br.operand);743 try w.writeOperand(s, inst, 0, br.operand);
739 }744 }
740745
741 fn writeRepeat(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {746 fn writeRepeat(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
742 const repeat = w.air.instructions.items(.data)[@intFromEnum(inst)].repeat;747 const repeat = w.air.instructions.items(.data)[@intFromEnum(inst)].repeat;
743 try w.writeInstIndex(s, repeat.loop_inst, false);748 try w.writeInstIndex(s, repeat.loop_inst, false);
744 }749 }
745750
746 fn writeTry(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {751 fn writeTry(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
747 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;752 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
748 const extra = w.air.extraData(Air.Try, pl_op.payload);753 const extra = w.air.extraData(Air.Try, pl_op.payload);
749 const body: []const Air.Inst.Index = @ptrCast(w.air.extra.items[extra.end..][0..extra.data.body_len]);754 const body: []const Air.Inst.Index = @ptrCast(w.air.extra.items[extra.end..][0..extra.data.body_len]);
...@@ -759,7 +764,7 @@ const Writer = struct {...@@ -759,7 +764,7 @@ const Writer = struct {
759 w.indent += 2;764 w.indent += 2;
760765
761 if (liveness_condbr.else_deaths.len != 0) {766 if (liveness_condbr.else_deaths.len != 0) {
762 try s.writeByteNTimes(' ', w.indent);767 try s.splatByteAll(' ', w.indent);
763 for (liveness_condbr.else_deaths, 0..) |operand, i| {768 for (liveness_condbr.else_deaths, 0..) |operand, i| {
764 if (i != 0) try s.writeAll(" ");769 if (i != 0) try s.writeAll(" ");
765 try s.print("{}!", .{operand});770 try s.print("{}!", .{operand});
...@@ -769,7 +774,7 @@ const Writer = struct {...@@ -769,7 +774,7 @@ const Writer = struct {
769 try w.writeBody(s, body);774 try w.writeBody(s, body);
770775
771 w.indent = old_indent;776 w.indent = old_indent;
772 try s.writeByteNTimes(' ', w.indent);777 try s.splatByteAll(' ', w.indent);
773 try s.writeAll("}");778 try s.writeAll("}");
774779
775 for (liveness_condbr.then_deaths) |operand| {780 for (liveness_condbr.then_deaths) |operand| {
...@@ -777,7 +782,7 @@ const Writer = struct {...@@ -777,7 +782,7 @@ const Writer = struct {
777 }782 }
778 }783 }
779784
780 fn writeTryPtr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {785 fn writeTryPtr(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
781 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;786 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
782 const extra = w.air.extraData(Air.TryPtr, ty_pl.payload);787 const extra = w.air.extraData(Air.TryPtr, ty_pl.payload);
783 const body: []const Air.Inst.Index = @ptrCast(w.air.extra.items[extra.end..][0..extra.data.body_len]);788 const body: []const Air.Inst.Index = @ptrCast(w.air.extra.items[extra.end..][0..extra.data.body_len]);
...@@ -796,7 +801,7 @@ const Writer = struct {...@@ -796,7 +801,7 @@ const Writer = struct {
796 w.indent += 2;801 w.indent += 2;
797802
798 if (liveness_condbr.else_deaths.len != 0) {803 if (liveness_condbr.else_deaths.len != 0) {
799 try s.writeByteNTimes(' ', w.indent);804 try s.splatByteAll(' ', w.indent);
800 for (liveness_condbr.else_deaths, 0..) |operand, i| {805 for (liveness_condbr.else_deaths, 0..) |operand, i| {
801 if (i != 0) try s.writeAll(" ");806 if (i != 0) try s.writeAll(" ");
802 try s.print("{}!", .{operand});807 try s.print("{}!", .{operand});
...@@ -806,7 +811,7 @@ const Writer = struct {...@@ -806,7 +811,7 @@ const Writer = struct {
806 try w.writeBody(s, body);811 try w.writeBody(s, body);
807812
808 w.indent = old_indent;813 w.indent = old_indent;
809 try s.writeByteNTimes(' ', w.indent);814 try s.splatByteAll(' ', w.indent);
810 try s.writeAll("}");815 try s.writeAll("}");
811816
812 for (liveness_condbr.then_deaths) |operand| {817 for (liveness_condbr.then_deaths) |operand| {
...@@ -814,7 +819,7 @@ const Writer = struct {...@@ -814,7 +819,7 @@ const Writer = struct {
814 }819 }
815 }820 }
816821
817 fn writeCondBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {822 fn writeCondBr(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
818 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;823 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
819 const extra = w.air.extraData(Air.CondBr, pl_op.payload);824 const extra = w.air.extraData(Air.CondBr, pl_op.payload);
820 const then_body: []const Air.Inst.Index = @ptrCast(w.air.extra.items[extra.end..][0..extra.data.then_body_len]);825 const then_body: []const Air.Inst.Index = @ptrCast(w.air.extra.items[extra.end..][0..extra.data.then_body_len]);
...@@ -838,7 +843,7 @@ const Writer = struct {...@@ -838,7 +843,7 @@ const Writer = struct {
838 w.indent += 2;843 w.indent += 2;
839844
840 if (liveness_condbr.then_deaths.len != 0) {845 if (liveness_condbr.then_deaths.len != 0) {
841 try s.writeByteNTimes(' ', w.indent);846 try s.splatByteAll(' ', w.indent);
842 for (liveness_condbr.then_deaths, 0..) |operand, i| {847 for (liveness_condbr.then_deaths, 0..) |operand, i| {
843 if (i != 0) try s.writeAll(" ");848 if (i != 0) try s.writeAll(" ");
844 try s.print("{}!", .{operand});849 try s.print("{}!", .{operand});
...@@ -847,7 +852,7 @@ const Writer = struct {...@@ -847,7 +852,7 @@ const Writer = struct {
847 }852 }
848853
849 try w.writeBody(s, then_body);854 try w.writeBody(s, then_body);
850 try s.writeByteNTimes(' ', old_indent);855 try s.splatByteAll(' ', old_indent);
851 try s.writeAll("},");856 try s.writeAll("},");
852 if (extra.data.branch_hints.false != .none) {857 if (extra.data.branch_hints.false != .none) {
853 try s.print(" {s}", .{@tagName(extra.data.branch_hints.false)});858 try s.print(" {s}", .{@tagName(extra.data.branch_hints.false)});
...@@ -858,7 +863,7 @@ const Writer = struct {...@@ -858,7 +863,7 @@ const Writer = struct {
858 try s.writeAll(" {\n");863 try s.writeAll(" {\n");
859864
860 if (liveness_condbr.else_deaths.len != 0) {865 if (liveness_condbr.else_deaths.len != 0) {
861 try s.writeByteNTimes(' ', w.indent);866 try s.splatByteAll(' ', w.indent);
862 for (liveness_condbr.else_deaths, 0..) |operand, i| {867 for (liveness_condbr.else_deaths, 0..) |operand, i| {
863 if (i != 0) try s.writeAll(" ");868 if (i != 0) try s.writeAll(" ");
864 try s.print("{}!", .{operand});869 try s.print("{}!", .{operand});
...@@ -869,11 +874,11 @@ const Writer = struct {...@@ -869,11 +874,11 @@ const Writer = struct {
869 try w.writeBody(s, else_body);874 try w.writeBody(s, else_body);
870 w.indent = old_indent;875 w.indent = old_indent;
871876
872 try s.writeByteNTimes(' ', old_indent);877 try s.splatByteAll(' ', old_indent);
873 try s.writeAll("}");878 try s.writeAll("}");
874 }879 }
875880
876 fn writeSwitchBr(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {881 fn writeSwitchBr(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
877 const switch_br = w.air.unwrapSwitch(inst);882 const switch_br = w.air.unwrapSwitch(inst);
878883
879 const liveness: Air.Liveness.SwitchBrTable = if (w.liveness) |liveness|884 const liveness: Air.Liveness.SwitchBrTable = if (w.liveness) |liveness|
...@@ -915,7 +920,7 @@ const Writer = struct {...@@ -915,7 +920,7 @@ const Writer = struct {
915920
916 const deaths = liveness.deaths[case.idx];921 const deaths = liveness.deaths[case.idx];
917 if (deaths.len != 0) {922 if (deaths.len != 0) {
918 try s.writeByteNTimes(' ', w.indent);923 try s.splatByteAll(' ', w.indent);
919 for (deaths, 0..) |operand, i| {924 for (deaths, 0..) |operand, i| {
920 if (i != 0) try s.writeAll(" ");925 if (i != 0) try s.writeAll(" ");
921 try s.print("{}!", .{operand});926 try s.print("{}!", .{operand});
...@@ -925,7 +930,7 @@ const Writer = struct {...@@ -925,7 +930,7 @@ const Writer = struct {
925930
926 try w.writeBody(s, case.body);931 try w.writeBody(s, case.body);
927 w.indent -= 2;932 w.indent -= 2;
928 try s.writeByteNTimes(' ', w.indent);933 try s.splatByteAll(' ', w.indent);
929 try s.writeAll("}");934 try s.writeAll("}");
930 }935 }
931936
...@@ -941,7 +946,7 @@ const Writer = struct {...@@ -941,7 +946,7 @@ const Writer = struct {
941946
942 const deaths = liveness.deaths[liveness.deaths.len - 1];947 const deaths = liveness.deaths[liveness.deaths.len - 1];
943 if (deaths.len != 0) {948 if (deaths.len != 0) {
944 try s.writeByteNTimes(' ', w.indent);949 try s.splatByteAll(' ', w.indent);
945 for (deaths, 0..) |operand, i| {950 for (deaths, 0..) |operand, i| {
946 if (i != 0) try s.writeAll(" ");951 if (i != 0) try s.writeAll(" ");
947 try s.print("{}!", .{operand});952 try s.print("{}!", .{operand});
...@@ -951,37 +956,37 @@ const Writer = struct {...@@ -951,37 +956,37 @@ const Writer = struct {
951956
952 try w.writeBody(s, else_body);957 try w.writeBody(s, else_body);
953 w.indent -= 2;958 w.indent -= 2;
954 try s.writeByteNTimes(' ', w.indent);959 try s.splatByteAll(' ', w.indent);
955 try s.writeAll("}");960 try s.writeAll("}");
956 }961 }
957962
958 try s.writeAll("\n");963 try s.writeAll("\n");
959 try s.writeByteNTimes(' ', old_indent);964 try s.splatByteAll(' ', old_indent);
960 }965 }
961966
962 fn writeWasmMemorySize(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {967 fn writeWasmMemorySize(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
963 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;968 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
964 try s.print("{d}", .{pl_op.payload});969 try s.print("{d}", .{pl_op.payload});
965 }970 }
966971
967 fn writeWasmMemoryGrow(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {972 fn writeWasmMemoryGrow(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
968 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;973 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
969 try s.print("{d}, ", .{pl_op.payload});974 try s.print("{d}, ", .{pl_op.payload});
970 try w.writeOperand(s, inst, 0, pl_op.operand);975 try w.writeOperand(s, inst, 0, pl_op.operand);
971 }976 }
972977
973 fn writeWorkDimension(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {978 fn writeWorkDimension(w: *Writer, s: *std.io.BufferedWriter, inst: Air.Inst.Index) anyerror!void {
974 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;979 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
975 try s.print("{d}", .{pl_op.payload});980 try s.print("{d}", .{pl_op.payload});
976 }981 }
977982
978 fn writeOperand(983 fn writeOperand(
979 w: *Writer,984 w: *Writer,
980 s: anytype,985 s: *std.io.BufferedWriter,
981 inst: Air.Inst.Index,986 inst: Air.Inst.Index,
982 op_index: usize,987 op_index: usize,
983 operand: Air.Inst.Ref,988 operand: Air.Inst.Ref,
984 ) @TypeOf(s).Error!void {989 ) anyerror!void {
985 const small_tomb_bits = Air.Liveness.bpi - 1;990 const small_tomb_bits = Air.Liveness.bpi - 1;
986 const dies = if (w.liveness) |liveness| blk: {991 const dies = if (w.liveness) |liveness| blk: {
987 if (op_index < small_tomb_bits)992 if (op_index < small_tomb_bits)
...@@ -1006,7 +1011,7 @@ const Writer = struct {...@@ -1006,7 +1011,7 @@ const Writer = struct {
1006 s: anytype,1011 s: anytype,
1007 operand: Air.Inst.Ref,1012 operand: Air.Inst.Ref,
1008 dies: bool,1013 dies: bool,
1009 ) @TypeOf(s).Error!void {1014 ) anyerror!void {
1010 if (@intFromEnum(operand) < InternPool.static_len) {1015 if (@intFromEnum(operand) < InternPool.static_len) {
1011 return s.print("@{}", .{operand});1016 return s.print("@{}", .{operand});
1012 } else if (operand.toInterned()) |ip_index| {1017 } else if (operand.toInterned()) |ip_index| {
...@@ -1023,10 +1028,10 @@ const Writer = struct {...@@ -1023,10 +1028,10 @@ const Writer = struct {
10231028
1024 fn writeInstIndex(1029 fn writeInstIndex(
1025 w: *Writer,1030 w: *Writer,
1026 s: anytype,1031 s: *std.io.BufferedWriter,
1027 inst: Air.Inst.Index,1032 inst: Air.Inst.Index,
1028 dies: bool,1033 dies: bool,
1029 ) @TypeOf(s).Error!void {1034 ) anyerror!void {
1030 _ = w;1035 _ = w;
1031 try s.print("{}", .{inst});1036 try s.print("{}", .{inst});
1032 if (dies) try s.writeByte('!');1037 if (dies) try s.writeByte('!');
src/Package/Fetch/git.zig+14-10
...@@ -825,9 +825,9 @@ pub const Session = struct {...@@ -825,9 +825,9 @@ pub const Session = struct {
825 upload_pack_uri.query = null;825 upload_pack_uri.query = null;
826 upload_pack_uri.fragment = null;826 upload_pack_uri.fragment = null;
827827
828 var body: std.ArrayListUnmanaged(u8) = .empty;828 var body: std.io.AllocatingWriter = undefined;
829 defer body.deinit(session.allocator);829 const body_writer = body.init(session.allocator);
830 const body_writer = body.writer(session.allocator);830 defer body.deinit();
831 try Packet.write(.{ .data = "command=ls-refs\n" }, body_writer);831 try Packet.write(.{ .data = "command=ls-refs\n" }, body_writer);
832 if (session.supports_agent) {832 if (session.supports_agent) {
833 try Packet.write(.{ .data = agent_capability }, body_writer);833 try Packet.write(.{ .data = agent_capability }, body_writer);
...@@ -860,9 +860,11 @@ pub const Session = struct {...@@ -860,9 +860,11 @@ pub const Session = struct {
860 },860 },
861 });861 });
862 errdefer request.deinit();862 errdefer request.deinit();
863 request.transfer_encoding = .{ .content_length = body.items.len };863 const written = body.getWritten();
864 request.transfer_encoding = .{ .content_length = written.len };
864 try request.send();865 try request.send();
865 try request.writeAll(body.items);866 var w = request.writer().unbuffered();
867 try w.writeAll(written);
866 try request.finish();868 try request.finish();
867869
868 try request.wait();870 try request.wait();
...@@ -940,9 +942,9 @@ pub const Session = struct {...@@ -940,9 +942,9 @@ pub const Session = struct {
940 upload_pack_uri.query = null;942 upload_pack_uri.query = null;
941 upload_pack_uri.fragment = null;943 upload_pack_uri.fragment = null;
942944
943 var body: std.ArrayListUnmanaged(u8) = .empty;945 var body: std.io.AllocatingWriter = undefined;
944 defer body.deinit(session.allocator);946 const body_writer = body.init(session.allocator);
945 const body_writer = body.writer(session.allocator);947 defer body.deinit();
946 try Packet.write(.{ .data = "command=fetch\n" }, body_writer);948 try Packet.write(.{ .data = "command=fetch\n" }, body_writer);
947 if (session.supports_agent) {949 if (session.supports_agent) {
948 try Packet.write(.{ .data = agent_capability }, body_writer);950 try Packet.write(.{ .data = agent_capability }, body_writer);
...@@ -977,9 +979,11 @@ pub const Session = struct {...@@ -977,9 +979,11 @@ pub const Session = struct {
977 },979 },
978 });980 });
979 errdefer request.deinit();981 errdefer request.deinit();
980 request.transfer_encoding = .{ .content_length = body.items.len };982 const written = body.getWritten();
983 request.transfer_encoding = .{ .content_length = written.len };
981 try request.send();984 try request.send();
982 try request.writeAll(body.items);985 var w = request.writer().unbuffered();
986 try w.writeAll(written);
983 try request.finish();987 try request.finish();
984988
985 try request.wait();989 try request.wait();
src/Package/Manifest.zig+5-4
...@@ -471,10 +471,11 @@ const Parse = struct {...@@ -471,10 +471,11 @@ const Parse = struct {
471 offset: u32,471 offset: u32,
472 ) InnerError!void {472 ) InnerError!void {
473 const raw_string = bytes[offset..];473 const raw_string = bytes[offset..];
474 var buf_managed = buf.toManaged(p.gpa);474 var aw: std.io.AllocatingWriter = undefined;
475 const result = std.zig.string_literal.parseWrite(buf_managed.writer(), raw_string);475 const bw = aw.fromArrayList(p.gpa, buf);
476 buf.* = buf_managed.moveToUnmanaged();476 const result = std.zig.string_literal.parseWrite(bw, raw_string);
477 switch (try result) {477 buf.* = aw.toArrayList();
478 switch (result catch return error.OutOfMemory) {
478 .success => {},479 .success => {},
479 .failure => |err| try p.appendStrLitError(err, token, bytes, offset),480 .failure => |err| try p.appendStrLitError(err, token, bytes, offset),
480 }481 }
src/Type.zig+1-1
...@@ -173,7 +173,7 @@ pub fn dump(...@@ -173,7 +173,7 @@ pub fn dump(
173173
174/// Prints a name suitable for `@typeName`.174/// Prints a name suitable for `@typeName`.
175/// TODO: take an `opt_sema` to pass to `fmtValue` when printing sentinels.175/// TODO: take an `opt_sema` to pass to `fmtValue` when printing sentinels.
176pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error!void {176pub fn print(ty: Type, writer: *std.io.BufferedWriter, pt: Zcu.PerThread) anyerror!void {
177 const zcu = pt.zcu;177 const zcu = pt.zcu;
178 const ip = &zcu.intern_pool;178 const ip = &zcu.intern_pool;
179 switch (ip.indexToKey(ty.toIntern())) {179 switch (ip.indexToKey(ty.toIntern())) {
src/codegen/llvm.zig+9-8
...@@ -239,12 +239,12 @@ pub fn targetTriple(allocator: Allocator, target: *const std.Target) ![]const u8...@@ -239,12 +239,12 @@ pub fn targetTriple(allocator: Allocator, target: *const std.Target) ![]const u8
239 .none,239 .none,
240 .windows,240 .windows,
241 => {},241 => {},
242 .semver => |ver| try llvm_triple.writer().print("{d}.{d}.{d}", .{242 .semver => |ver| try llvm_triple.print("{d}.{d}.{d}", .{
243 ver.min.major,243 ver.min.major,
244 ver.min.minor,244 ver.min.minor,
245 ver.min.patch,245 ver.min.patch,
246 }),246 }),
247 inline .linux, .hurd => |ver| try llvm_triple.writer().print("{d}.{d}.{d}", .{247 inline .linux, .hurd => |ver| try llvm_triple.print("{d}.{d}.{d}", .{
248 ver.range.min.major,248 ver.range.min.major,
249 ver.range.min.minor,249 ver.range.min.minor,
250 ver.range.min.patch,250 ver.range.min.patch,
...@@ -295,13 +295,13 @@ pub fn targetTriple(allocator: Allocator, target: *const std.Target) ![]const u8...@@ -295,13 +295,13 @@ pub fn targetTriple(allocator: Allocator, target: *const std.Target) ![]const u8
295 .windows,295 .windows,
296 => {},296 => {},
297 inline .hurd, .linux => |ver| if (target.abi.isGnu()) {297 inline .hurd, .linux => |ver| if (target.abi.isGnu()) {
298 try llvm_triple.writer().print("{d}.{d}.{d}", .{298 try llvm_triple.print("{d}.{d}.{d}", .{
299 ver.glibc.major,299 ver.glibc.major,
300 ver.glibc.minor,300 ver.glibc.minor,
301 ver.glibc.patch,301 ver.glibc.patch,
302 });302 });
303 } else if (@TypeOf(ver) == std.Target.Os.LinuxVersionRange and target.abi.isAndroid()) {303 } else if (@TypeOf(ver) == std.Target.Os.LinuxVersionRange and target.abi.isAndroid()) {
304 try llvm_triple.writer().print("{d}", .{ver.android});304 try llvm_triple.print("{d}", .{ver.android});
305 },305 },
306 }306 }
307307
...@@ -2676,10 +2676,11 @@ pub const Object = struct {...@@ -2676,10 +2676,11 @@ pub const Object = struct {
2676 }2676 }
26772677
2678 fn allocTypeName(o: *Object, ty: Type) Allocator.Error![:0]const u8 {2678 fn allocTypeName(o: *Object, ty: Type) Allocator.Error![:0]const u8 {
2679 var buffer = std.ArrayList(u8).init(o.gpa);2679 var aw: std.io.AllocatingWriter = undefined;
2680 errdefer buffer.deinit();2680 const bw = aw.init(o.gpa);
2681 try ty.print(buffer.writer(), o.pt);2681 defer aw.deinit();
2682 return buffer.toOwnedSliceSentinel(0);2682 try ty.print(bw, o.pt);
2683 return aw.toOwnedSliceSentinel(0);
2683 }2684 }
26842685
2685 /// If the llvm function does not exist, create it.2686 /// If the llvm function does not exist, create it.
src/libs/mingw.zig+1-2
...@@ -304,9 +304,8 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {...@@ -304,9 +304,8 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
304 const include_dir = try comp.dirs.zig_lib.join(arena, &.{ "libc", "mingw", "def-include" });304 const include_dir = try comp.dirs.zig_lib.join(arena, &.{ "libc", "mingw", "def-include" });
305305
306 if (comp.verbose_cc) print: {306 if (comp.verbose_cc) print: {
307 std.debug.lockStdErr();307 var stderr = std.debug.lockStdErr2();
308 defer std.debug.unlockStdErr();308 defer std.debug.unlockStdErr();
309 const stderr = std.io.getStdErr().writer();
310 nosuspend stderr.print("def file: {s}\n", .{def_file_path}) catch break :print;309 nosuspend stderr.print("def file: {s}\n", .{def_file_path}) catch break :print;
311 nosuspend stderr.print("include dir: {s}\n", .{include_dir}) catch break :print;310 nosuspend stderr.print("include dir: {s}\n", .{include_dir}) catch break :print;
312 nosuspend stderr.print("output path: {s}\n", .{def_final_path}) catch break :print;311 nosuspend stderr.print("output path: {s}\n", .{def_final_path}) catch break :print;
src/link/Elf/eh_frame.zig+7-7
...@@ -51,7 +51,7 @@ pub const Fde = struct {...@@ -51,7 +51,7 @@ pub const Fde = struct {
51 fde: Fde,51 fde: Fde,
52 comptime unused_fmt_string: []const u8,52 comptime unused_fmt_string: []const u8,
53 options: std.fmt.FormatOptions,53 options: std.fmt.FormatOptions,
54 writer: anytype,54 writer: *std.io.BufferedWriter,
55 ) !void {55 ) !void {
56 _ = fde;56 _ = fde;
57 _ = unused_fmt_string;57 _ = unused_fmt_string;
...@@ -76,7 +76,7 @@ pub const Fde = struct {...@@ -76,7 +76,7 @@ pub const Fde = struct {
76 ctx: FdeFormatContext,76 ctx: FdeFormatContext,
77 comptime unused_fmt_string: []const u8,77 comptime unused_fmt_string: []const u8,
78 options: std.fmt.FormatOptions,78 options: std.fmt.FormatOptions,
79 writer: anytype,79 writer: *std.io.BufferedWriter,
80 ) !void {80 ) !void {
81 _ = unused_fmt_string;81 _ = unused_fmt_string;
82 _ = options;82 _ = options;
...@@ -154,7 +154,7 @@ pub const Cie = struct {...@@ -154,7 +154,7 @@ pub const Cie = struct {
154 cie: Cie,154 cie: Cie,
155 comptime unused_fmt_string: []const u8,155 comptime unused_fmt_string: []const u8,
156 options: std.fmt.FormatOptions,156 options: std.fmt.FormatOptions,
157 writer: anytype,157 writer: *std.io.BufferedWriter,
158 ) !void {158 ) !void {
159 _ = cie;159 _ = cie;
160 _ = unused_fmt_string;160 _ = unused_fmt_string;
...@@ -179,7 +179,7 @@ pub const Cie = struct {...@@ -179,7 +179,7 @@ pub const Cie = struct {
179 ctx: CieFormatContext,179 ctx: CieFormatContext,
180 comptime unused_fmt_string: []const u8,180 comptime unused_fmt_string: []const u8,
181 options: std.fmt.FormatOptions,181 options: std.fmt.FormatOptions,
182 writer: anytype,182 writer: *std.io.BufferedWriter,
183 ) !void {183 ) !void {
184 _ = unused_fmt_string;184 _ = unused_fmt_string;
185 _ = options;185 _ = options;
...@@ -332,7 +332,7 @@ fn resolveReloc(rec: anytype, sym: *const Symbol, rel: elf.Elf64_Rela, elf_file:...@@ -332,7 +332,7 @@ fn resolveReloc(rec: anytype, sym: *const Symbol, rel: elf.Elf64_Rela, elf_file:
332 }332 }
333}333}
334334
335pub fn writeEhFrame(elf_file: *Elf, writer: anytype) !void {335pub fn writeEhFrame(elf_file: *Elf, writer: *std.io.BufferedWriter) !void {
336 relocs_log.debug("{x}: .eh_frame", .{336 relocs_log.debug("{x}: .eh_frame", .{
337 elf_file.sections.items(.shdr)[elf_file.section_indexes.eh_frame.?].sh_addr,337 elf_file.sections.items(.shdr)[elf_file.section_indexes.eh_frame.?].sh_addr,
338 });338 });
...@@ -393,7 +393,7 @@ pub fn writeEhFrame(elf_file: *Elf, writer: anytype) !void {...@@ -393,7 +393,7 @@ pub fn writeEhFrame(elf_file: *Elf, writer: anytype) !void {
393 if (has_reloc_errors) return error.RelocFailure;393 if (has_reloc_errors) return error.RelocFailure;
394}394}
395395
396pub fn writeEhFrameRelocatable(elf_file: *Elf, writer: anytype) !void {396pub fn writeEhFrameRelocatable(elf_file: *Elf, writer: *std.io.BufferedWriter) !void {
397 for (elf_file.objects.items) |index| {397 for (elf_file.objects.items) |index| {
398 const object = elf_file.file(index).?.object;398 const object = elf_file.file(index).?.object;
399399
...@@ -495,7 +495,7 @@ pub fn writeEhFrameRelocs(elf_file: *Elf, relocs: *std.ArrayList(elf.Elf64_Rela)...@@ -495,7 +495,7 @@ pub fn writeEhFrameRelocs(elf_file: *Elf, relocs: *std.ArrayList(elf.Elf64_Rela)
495 }495 }
496}496}
497497
498pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void {498pub fn writeEhFrameHdr(elf_file: *Elf, writer: *std.io.BufferedWriter) !void {
499 const comp = elf_file.base.comp;499 const comp = elf_file.base.comp;
500 const gpa = comp.gpa;500 const gpa = comp.gpa;
501501
src/link/Elf/relocatable.zig+6-4
...@@ -407,15 +407,17 @@ fn writeSyntheticSections(elf_file: *Elf) !void {...@@ -407,15 +407,17 @@ fn writeSyntheticSections(elf_file: *Elf) !void {
407 };407 };
408 const shdr = slice.items(.shdr)[shndx];408 const shdr = slice.items(.shdr)[shndx];
409 const sh_size = math.cast(usize, shdr.sh_size) orelse return error.Overflow;409 const sh_size = math.cast(usize, shdr.sh_size) orelse return error.Overflow;
410 var buffer = try std.ArrayList(u8).initCapacity(gpa, @intCast(sh_size - existing_size));410 var buffer: std.io.AllocatingWriter = undefined;
411 const bw = buffer.init(gpa);
411 defer buffer.deinit();412 defer buffer.deinit();
412 try eh_frame.writeEhFrameRelocatable(elf_file, buffer.writer());413 try buffer.ensureTotalCapacity(gpa, sh_size - existing_size);
414 try eh_frame.writeEhFrameRelocatable(elf_file, bw);
413 log.debug("writing .eh_frame from 0x{x} to 0x{x}", .{415 log.debug("writing .eh_frame from 0x{x} to 0x{x}", .{
414 shdr.sh_offset + existing_size,416 shdr.sh_offset + existing_size,
415 shdr.sh_offset + sh_size,417 shdr.sh_offset + sh_size,
416 });418 });
417 assert(buffer.items.len == sh_size - existing_size);419 assert(buffer.getWritten().len == sh_size - existing_size);
418 try elf_file.base.file.?.pwriteAll(buffer.items, shdr.sh_offset + existing_size);420 try elf_file.base.file.?.pwriteAll(buffer.getWritten(), shdr.sh_offset + existing_size);
419 }421 }
420 if (elf_file.section_indexes.eh_frame_rela) |shndx| {422 if (elf_file.section_indexes.eh_frame_rela) |shndx| {
421 const shdr = slice.items(.shdr)[shndx];423 const shdr = slice.items(.shdr)[shndx];
src/link/Wasm/Object.zig+1-1
...@@ -1460,7 +1460,7 @@ fn parseFeatures(...@@ -1460,7 +1460,7 @@ fn parseFeatures(
1460}1460}
14611461
1462fn readLeb(comptime T: type, bytes: []const u8, pos: usize) struct { T, usize } {1462fn readLeb(comptime T: type, bytes: []const u8, pos: usize) struct { T, usize } {
1463 var fbr = std.io.fixedBufferStream(bytes[pos..]);1463 var fbr: std.io.FixedBufferStream = .{ .buffer = bytes[pos..] };
1464 return .{1464 return .{
1465 switch (@typeInfo(T).int.signedness) {1465 switch (@typeInfo(T).int.signedness) {
1466 .signed => std.leb.readIleb128(T, fbr.reader()) catch unreachable,1466 .signed => std.leb.readIleb128(T, fbr.reader()) catch unreachable,
src/print_value.zig+14-14
...@@ -23,9 +23,9 @@ pub const FormatContext = struct {...@@ -23,9 +23,9 @@ pub const FormatContext = struct {
23pub fn formatSema(23pub fn formatSema(
24 ctx: FormatContext,24 ctx: FormatContext,
25 comptime fmt: []const u8,25 comptime fmt: []const u8,
26 options: std.fmt.FormatOptions,26 options: std.fmt.Options,
27 writer: anytype,27 writer: *std.io.BufferedWriter,
28) !void {28) anyerror!void {
29 _ = options;29 _ = options;
30 const sema = ctx.opt_sema.?;30 const sema = ctx.opt_sema.?;
31 comptime std.debug.assert(fmt.len == 0);31 comptime std.debug.assert(fmt.len == 0);
...@@ -40,9 +40,9 @@ pub fn formatSema(...@@ -40,9 +40,9 @@ pub fn formatSema(
40pub fn format(40pub fn format(
41 ctx: FormatContext,41 ctx: FormatContext,
42 comptime fmt: []const u8,42 comptime fmt: []const u8,
43 options: std.fmt.FormatOptions,43 options: std.fmt.Options,
44 writer: anytype,44 writer: *std.io.BufferedWriter,
45) !void {45) anyerror!void {
46 _ = options;46 _ = options;
47 std.debug.assert(ctx.opt_sema == null);47 std.debug.assert(ctx.opt_sema == null);
48 comptime std.debug.assert(fmt.len == 0);48 comptime std.debug.assert(fmt.len == 0);
...@@ -55,11 +55,11 @@ pub fn format(...@@ -55,11 +55,11 @@ pub fn format(
5555
56pub fn print(56pub fn print(
57 val: Value,57 val: Value,
58 writer: anytype,58 writer: *std.io.BufferedWriter,
59 level: u8,59 level: u8,
60 pt: Zcu.PerThread,60 pt: Zcu.PerThread,
61 opt_sema: ?*Sema,61 opt_sema: ?*Sema,
62) (@TypeOf(writer).Error || Zcu.CompileError)!void {62) anyerror!void {
63 const zcu = pt.zcu;63 const zcu = pt.zcu;
64 const ip = &zcu.intern_pool;64 const ip = &zcu.intern_pool;
65 switch (ip.indexToKey(val.toIntern())) {65 switch (ip.indexToKey(val.toIntern())) {
...@@ -197,11 +197,11 @@ fn printAggregate(...@@ -197,11 +197,11 @@ fn printAggregate(
197 val: Value,197 val: Value,
198 aggregate: InternPool.Key.Aggregate,198 aggregate: InternPool.Key.Aggregate,
199 is_ref: bool,199 is_ref: bool,
200 writer: anytype,200 writer: *std.io.BufferedWriter,
201 level: u8,201 level: u8,
202 pt: Zcu.PerThread,202 pt: Zcu.PerThread,
203 opt_sema: ?*Sema,203 opt_sema: ?*Sema,
204) (@TypeOf(writer).Error || Zcu.CompileError)!void {204) anyerror!void {
205 if (level == 0) {205 if (level == 0) {
206 if (is_ref) try writer.writeByte('&');206 if (is_ref) try writer.writeByte('&');
207 return writer.writeAll(".{ ... }");207 return writer.writeAll(".{ ... }");
...@@ -283,11 +283,11 @@ fn printPtr(...@@ -283,11 +283,11 @@ fn printPtr(
283 ptr_val: Value,283 ptr_val: Value,
284 /// Whether to print `derivation` as an lvalue or rvalue. If `null`, the more concise option is chosen.284 /// Whether to print `derivation` as an lvalue or rvalue. If `null`, the more concise option is chosen.
285 want_kind: ?PrintPtrKind,285 want_kind: ?PrintPtrKind,
286 writer: anytype,286 writer: *std.io.BufferedWriter,
287 level: u8,287 level: u8,
288 pt: Zcu.PerThread,288 pt: Zcu.PerThread,
289 opt_sema: ?*Sema,289 opt_sema: ?*Sema,
290) (@TypeOf(writer).Error || Zcu.CompileError)!void {290) anyerror!void {
291 const ptr = switch (pt.zcu.intern_pool.indexToKey(ptr_val.toIntern())) {291 const ptr = switch (pt.zcu.intern_pool.indexToKey(ptr_val.toIntern())) {
292 .undef => return writer.writeAll("undefined"),292 .undef => return writer.writeAll("undefined"),
293 .ptr => |ptr| ptr,293 .ptr => |ptr| ptr,
...@@ -329,7 +329,7 @@ const PrintPtrKind = enum { lvalue, rvalue };...@@ -329,7 +329,7 @@ const PrintPtrKind = enum { lvalue, rvalue };
329/// Returns the root derivation, which may be ignored.329/// Returns the root derivation, which may be ignored.
330pub fn printPtrDerivation(330pub fn printPtrDerivation(
331 derivation: Value.PointerDeriveStep,331 derivation: Value.PointerDeriveStep,
332 writer: anytype,332 writer: *std.io.BufferedWriter,
333 pt: Zcu.PerThread,333 pt: Zcu.PerThread,
334 /// Whether to print `derivation` as an lvalue or rvalue. If `null`, the more concise option is chosen.334 /// Whether to print `derivation` as an lvalue or rvalue. If `null`, the more concise option is chosen.
335 /// If this is `.rvalue`, the result may look like `&foo`, so it's not necessarily valid to treat it as335 /// If this is `.rvalue`, the result may look like `&foo`, so it's not necessarily valid to treat it as
...@@ -347,7 +347,7 @@ pub fn printPtrDerivation(...@@ -347,7 +347,7 @@ pub fn printPtrDerivation(
347 /// The maximum recursion depth. We can never recurse infinitely here, but the depth can be arbitrary,347 /// The maximum recursion depth. We can never recurse infinitely here, but the depth can be arbitrary,
348 /// so at this depth we just write "..." to prevent stack overflow.348 /// so at this depth we just write "..." to prevent stack overflow.
349 ptr_depth: u8,349 ptr_depth: u8,
350) !Value.PointerDeriveStep {350) anyerror!Value.PointerDeriveStep {
351 const zcu = pt.zcu;351 const zcu = pt.zcu;
352 const ip = &zcu.intern_pool;352 const ip = &zcu.intern_pool;
353353