Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
57dbc9e
std.Io: delete GenericWriter
andrewrk Aug 8, 2025
c8b983c
link.Wasm: update for new writer API
andrewrk Aug 12, 2025
2dc6ddd
std.Io.Writer: add toArrayList/fromArrayList
andrewrk Aug 12, 2025
cc93166
link.MachO: update to not use GenericWriter
andrewrk Aug 17, 2025
6713745
link.Elf: update to not use GenericWriter
andrewrk Aug 17, 2025
379d7bc
compiler: update to not use GenericWriter
andrewrk Aug 17, 2025
2151b10
more updates to not use GenericWriter
andrewrk Aug 21, 2025
5d75072
aro: update to not use GenericWriter
andrewrk Aug 27, 2025
8f4cb46
compiler: update not to use GenericWriter
andrewrk Aug 27, 2025
9860dd4
std: delete most remaining uses of GenericWriter
andrewrk Aug 27, 2025
e9a271c
std.tz: update to new Reader API
andrewrk Aug 27, 2025
888f00e
std.crypto.ml_kem: update to not use GenericWriter
andrewrk Aug 27, 2025
ea34712
update GenericWriter usage found by test-cases
andrewrk Aug 27, 2025
4f510db
behavior tests: remove "variadic functions" dependency on std lib
andrewrk Aug 27, 2025
f788496
update more to avoid GenericWriter
andrewrk Aug 27, 2025
8d80d67
resinator: some updates to avoid GenericWriter
andrewrk Aug 27, 2025
5be9df7
32-bit fixes
andrewrk Aug 28, 2025
e418197
link.MachO: code sig size grows when emitting it
andrewrk Aug 28, 2025
8023f3d
fix not discarding delimiter
andrewrk Aug 28, 2025
9b47dd2
update langref and docs to avoid GenericWriter
andrewrk Aug 28, 2025
46b60dc
resinator: Complete the update to the new Reader/Writer
squeek502 Aug 28, 2025
530cc2c
std.Io.Reader: work around llvm backend bug
andrewrk Aug 29, 2025
7da9e4b
std.tz: fix redundant endian handling
andrewrk Aug 29, 2025
43fbc37
std.debug.Pdb: migrate more towards new Reader API
andrewrk Aug 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/compiler/aro/aro/Attribute.zig
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ fn ignoredAttrErr(p: *Parser, tok: TokenIndex, attr: Attribute.Tag, context: []c
const strings_top = p.strings.items.len;
defer p.strings.items.len = strings_top;

try p.strings.writer().print("attribute '{s}' ignored on {s}", .{ @tagName(attr), context });
try p.strings.print("attribute '{s}' ignored on {s}", .{ @tagName(attr), context });
const str = try p.comp.diagnostics.arena.allocator().dupe(u8, p.strings.items[strings_top..]);
try p.errStr(.ignored_attribute, tok, str);
}
Expand Down
5 changes: 2 additions & 3 deletions lib/compiler/aro/aro/Builtins/Builtin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ pub fn nameFromUniqueIndex(index: u16, buf: []u8) []u8 {

var node_index: u16 = 0;
var count: u16 = index;
var fbs = std.io.fixedBufferStream(buf);
const w = fbs.writer();
var w: std.Io.Writer = .fixed(buf);

while (true) {
var sibling_index = dafsa[node_index].child_index;
Expand All @@ -142,7 +141,7 @@ pub fn nameFromUniqueIndex(index: u16, buf: []u8) []u8 {
if (count == 0) break;
}

return fbs.getWritten();
return w.buffered();
}

/// We're 1 bit shy of being able to fit this in a u32:
Expand Down
64 changes: 36 additions & 28 deletions lib/compiler/aro/aro/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const Pragma = @import("Pragma.zig");
const StrInt = @import("StringInterner.zig");
const record_layout = @import("record_layout.zig");
const target_util = @import("target.zig");
const Writer = std.Io.Writer;

pub const Error = error{
/// A fatal error has ocurred and compilation has stopped.
Expand Down Expand Up @@ -199,7 +200,7 @@ fn getTimestamp(comp: *Compilation) !u47 {
return @intCast(std.math.clamp(timestamp, 0, max_timestamp));
}

fn generateDateAndTime(w: anytype, timestamp: u47) !void {
fn generateDateAndTime(w: *Writer, timestamp: u47) !void {
const epoch_seconds = EpochSeconds{ .secs = timestamp };
const epoch_day = epoch_seconds.getEpochDay();
const day_seconds = epoch_seconds.getDaySeconds();
Expand Down Expand Up @@ -242,7 +243,7 @@ pub const SystemDefinesMode = enum {
include_system_defines,
};

fn generateSystemDefines(comp: *Compilation, w: anytype) !void {
fn generateSystemDefines(comp: *Compilation, w: *Writer) !void {
const ptr_width = comp.target.ptrBitWidth();

if (comp.langopts.gnuc_version > 0) {
Expand Down Expand Up @@ -533,23 +534,32 @@ fn generateSystemDefines(comp: *Compilation, w: anytype) !void {
pub fn generateBuiltinMacros(comp: *Compilation, system_defines_mode: SystemDefinesMode) !Source {
try comp.generateBuiltinTypes();

var buf = std.array_list.Managed(u8).init(comp.gpa);
defer buf.deinit();
var allocating: std.Io.Writer.Allocating = .init(comp.gpa);
defer allocating.deinit();

generateBuiltinMacrosWriter(comp, system_defines_mode, &allocating.writer) catch |err| switch (err) {
error.WriteFailed => return error.OutOfMemory,
else => |e| return e,
};

return comp.addSourceFromBuffer("<builtin>", allocating.written());
}

pub fn generateBuiltinMacrosWriter(comp: *Compilation, system_defines_mode: SystemDefinesMode, buf: *Writer) !void {
if (system_defines_mode == .include_system_defines) {
try buf.appendSlice(
try buf.writeAll(
\\#define __VERSION__ "Aro
++ " " ++ @import("../backend.zig").version_str ++ "\"\n" ++
\\#define __Aro__
\\
);
}

try buf.appendSlice("#define __STDC__ 1\n");
try buf.writer().print("#define __STDC_HOSTED__ {d}\n", .{@intFromBool(comp.target.os.tag != .freestanding)});
try buf.writeAll("#define __STDC__ 1\n");
try buf.print("#define __STDC_HOSTED__ {d}\n", .{@intFromBool(comp.target.os.tag != .freestanding)});

// standard macros
try buf.appendSlice(
try buf.writeAll(
\\#define __STDC_NO_COMPLEX__ 1
\\#define __STDC_NO_THREADS__ 1
\\#define __STDC_NO_VLA__ 1
Expand All @@ -561,23 +571,21 @@ pub fn generateBuiltinMacros(comp: *Compilation, system_defines_mode: SystemDefi
\\
);
if (comp.langopts.standard.StdCVersionMacro()) |stdc_version| {
try buf.appendSlice("#define __STDC_VERSION__ ");
try buf.appendSlice(stdc_version);
try buf.append('\n');
try buf.writeAll("#define __STDC_VERSION__ ");
try buf.writeAll(stdc_version);
try buf.writeByte('\n');
}

// timestamps
const timestamp = try comp.getTimestamp();
try generateDateAndTime(buf.writer(), timestamp);
try generateDateAndTime(buf, timestamp);

if (system_defines_mode == .include_system_defines) {
try comp.generateSystemDefines(buf.writer());
try comp.generateSystemDefines(buf);
}

return comp.addSourceFromBuffer("<builtin>", buf.items);
}

fn generateFloatMacros(w: anytype, prefix: []const u8, semantics: target_util.FPSemantics, ext: []const u8) !void {
fn generateFloatMacros(w: *Writer, prefix: []const u8, semantics: target_util.FPSemantics, ext: []const u8) !void {
const denormMin = semantics.chooseValue(
[]const u8,
.{
Expand Down Expand Up @@ -656,7 +664,7 @@ fn generateFloatMacros(w: anytype, prefix: []const u8, semantics: target_util.FP
try w.print("#define {s}MIN__ {s}{s}\n", .{ prefix_slice, min, ext });
}

fn generateTypeMacro(w: anytype, mapper: StrInt.TypeMapper, name: []const u8, ty: Type, langopts: LangOpts) !void {
fn generateTypeMacro(w: *Writer, mapper: StrInt.TypeMapper, name: []const u8, ty: Type, langopts: LangOpts) !void {
try w.print("#define {s} ", .{name});
try ty.print(mapper, langopts, w);
try w.writeByte('\n');
Expand Down Expand Up @@ -762,7 +770,7 @@ fn generateFastOrLeastType(
bits: usize,
kind: enum { least, fast },
signedness: std.builtin.Signedness,
w: anytype,
w: *Writer,
mapper: StrInt.TypeMapper,
) !void {
const ty = comp.intLeastN(bits, signedness); // defining the fast types as the least types is permitted
Expand Down Expand Up @@ -793,7 +801,7 @@ fn generateFastOrLeastType(
try comp.generateFmt(prefix, w, ty);
}

fn generateFastAndLeastWidthTypes(comp: *Compilation, w: anytype, mapper: StrInt.TypeMapper) !void {
fn generateFastAndLeastWidthTypes(comp: *Compilation, w: *Writer, mapper: StrInt.TypeMapper) !void {
const sizes = [_]usize{ 8, 16, 32, 64 };
for (sizes) |size| {
try comp.generateFastOrLeastType(size, .least, .signed, w, mapper);
Expand All @@ -803,7 +811,7 @@ fn generateFastAndLeastWidthTypes(comp: *Compilation, w: anytype, mapper: StrInt
}
}

fn generateExactWidthTypes(comp: *const Compilation, w: anytype, mapper: StrInt.TypeMapper) !void {
fn generateExactWidthTypes(comp: *const Compilation, w: *Writer, mapper: StrInt.TypeMapper) !void {
try comp.generateExactWidthType(w, mapper, .schar);

if (comp.intSize(.short) > comp.intSize(.char)) {
Expand Down Expand Up @@ -851,7 +859,7 @@ fn generateExactWidthTypes(comp: *const Compilation, w: anytype, mapper: StrInt.
}
}

fn generateFmt(comp: *const Compilation, prefix: []const u8, w: anytype, ty: Type) !void {
fn generateFmt(comp: *const Compilation, prefix: []const u8, w: *Writer, ty: Type) !void {
const unsigned = ty.isUnsignedInt(comp);
const modifier = ty.formatModifier();
const formats = if (unsigned) "ouxX" else "di";
Expand All @@ -860,15 +868,15 @@ fn generateFmt(comp: *const Compilation, prefix: []const u8, w: anytype, ty: Typ
}
}

fn generateSuffixMacro(comp: *const Compilation, prefix: []const u8, w: anytype, ty: Type) !void {
fn generateSuffixMacro(comp: *const Compilation, prefix: []const u8, w: *Writer, ty: Type) !void {
return w.print("#define {s}_C_SUFFIX__ {s}\n", .{ prefix, ty.intValueSuffix(comp) });
}

/// Generate the following for ty:
/// Name macro (e.g. #define __UINT32_TYPE__ unsigned int)
/// Format strings (e.g. #define __UINT32_FMTu__ "u")
/// Suffix macro (e.g. #define __UINT32_C_SUFFIX__ U)
fn generateExactWidthType(comp: *const Compilation, w: anytype, mapper: StrInt.TypeMapper, specifier: Type.Specifier) !void {
fn generateExactWidthType(comp: *const Compilation, w: *Writer, mapper: StrInt.TypeMapper, specifier: Type.Specifier) !void {
var ty = Type{ .specifier = specifier };
const width = 8 * ty.sizeof(comp).?;
const unsigned = ty.isUnsignedInt(comp);
Expand Down Expand Up @@ -998,7 +1006,7 @@ fn generateVaListType(comp: *Compilation) !Type {
return ty;
}

fn generateIntMax(comp: *const Compilation, w: anytype, name: []const u8, ty: Type) !void {
fn generateIntMax(comp: *const Compilation, w: *Writer, name: []const u8, ty: Type) !void {
const bit_count: u8 = @intCast(ty.sizeof(comp).? * 8);
const unsigned = ty.isUnsignedInt(comp);
const max: u128 = switch (bit_count) {
Expand All @@ -1023,7 +1031,7 @@ pub fn wcharMax(comp: *const Compilation) u32 {
};
}

fn generateExactWidthIntMax(comp: *const Compilation, w: anytype, specifier: Type.Specifier) !void {
fn generateExactWidthIntMax(comp: *const Compilation, w: *Writer, specifier: Type.Specifier) !void {
var ty = Type{ .specifier = specifier };
const bit_count: u8 = @intCast(ty.sizeof(comp).? * 8);
const unsigned = ty.isUnsignedInt(comp);
Expand All @@ -1040,16 +1048,16 @@ fn generateExactWidthIntMax(comp: *const Compilation, w: anytype, specifier: Typ
return comp.generateIntMax(w, name, ty);
}

fn generateIntWidth(comp: *Compilation, w: anytype, name: []const u8, ty: Type) !void {
fn generateIntWidth(comp: *Compilation, w: *Writer, name: []const u8, ty: Type) !void {
try w.print("#define __{s}_WIDTH__ {d}\n", .{ name, 8 * ty.sizeof(comp).? });
}

fn generateIntMaxAndWidth(comp: *Compilation, w: anytype, name: []const u8, ty: Type) !void {
fn generateIntMaxAndWidth(comp: *Compilation, w: *Writer, name: []const u8, ty: Type) !void {
try comp.generateIntMax(w, name, ty);
try comp.generateIntWidth(w, name, ty);
}

fn generateSizeofType(comp: *Compilation, w: anytype, name: []const u8, ty: Type) !void {
fn generateSizeofType(comp: *Compilation, w: *Writer, name: []const u8, ty: Type) !void {
try w.print("#define {s} {d}\n", .{ name, ty.sizeof(comp).? });
}

Expand Down
Loading