Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ pub fn build(b: *std.Build) !void {
if (enable_llvm) {
const cmake_cfg = if (static_llvm) null else blk: {
if (findConfigH(b, config_h_path_option)) |config_h_path| {
const file_contents = fs.cwd().readFileAlloc(b.allocator, config_h_path, max_config_h_bytes) catch unreachable;
const file_contents = fs.cwd().readFileAlloc(config_h_path, b.allocator, .limited(max_config_h_bytes)) catch unreachable;
break :blk parseConfigH(b, file_contents);
} else {
std.log.warn("config.h could not be located automatically. Consider providing it explicitly via \"-Dconfig_h\"", .{});
Expand Down
5 changes: 2 additions & 3 deletions lib/compiler/aro/aro/Attribute/names.zig
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,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 @@ -140,7 +139,7 @@ pub fn nameFromUniqueIndex(index: u16, buf: []u8) []u8 {
if (count == 0) break;
}

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

const Node = packed struct(u32) {
Expand Down
30 changes: 6 additions & 24 deletions lib/compiler/aro/aro/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1308,13 +1308,7 @@ fn addSourceFromPathExtra(comp: *Compilation, path: []const u8, kind: Source.Kin
return error.FileNotFound;
}

const file = try comp.cwd.openFile(path, .{});
defer file.close();

const contents = file.readToEndAlloc(comp.gpa, std.math.maxInt(u32)) catch |err| switch (err) {
error.FileTooBig => return error.StreamTooLong,
else => |e| return e,
};
const contents = try comp.cwd.readFileAlloc(path, comp.gpa, .limited(std.math.maxInt(u32)));
errdefer comp.gpa.free(contents);

return comp.addSourceFromOwnedBuffer(contents, path, kind);
Expand Down Expand Up @@ -1433,19 +1427,7 @@ fn getFileContents(comp: *Compilation, path: []const u8, limit: ?u32) ![]const u
return error.FileNotFound;
}

const file = try comp.cwd.openFile(path, .{});
defer file.close();

var buf = std.array_list.Managed(u8).init(comp.gpa);
defer buf.deinit();

const max = limit orelse std.math.maxInt(u32);
file.deprecatedReader().readAllArrayList(&buf, max) catch |e| switch (e) {
error.StreamTooLong => if (limit == null) return e,
else => return e,
};

return buf.toOwnedSlice();
return comp.cwd.readFileAlloc(path, comp.gpa, .limited(limit orelse std.math.maxInt(u32)));
}

pub fn findEmbed(
Expand Down Expand Up @@ -1645,8 +1627,8 @@ test "addSourceFromReader" {
var comp = Compilation.init(std.testing.allocator, std.fs.cwd());
defer comp.deinit();

var buf_reader = std.io.fixedBufferStream(str);
const source = try comp.addSourceFromReader(buf_reader.reader(), "path", .user);
var buf_reader: std.Io.Reader = .fixed(str);
const source = try comp.addSourceFromReader(&buf_reader, "path", .user);

try std.testing.expectEqualStrings(expected, source.buf);
try std.testing.expectEqual(warning_count, @as(u32, @intCast(comp.diagnostics.list.items.len)));
Expand Down Expand Up @@ -1727,8 +1709,8 @@ test "ignore BOM at beginning of file" {
var comp = Compilation.init(std.testing.allocator, std.fs.cwd());
defer comp.deinit();

var buf_reader = std.io.fixedBufferStream(buf);
const source = try comp.addSourceFromReader(buf_reader.reader(), "file.c", .user);
var buf_reader: std.Io.Reader = .fixed(buf);
const source = try comp.addSourceFromReader(&buf_reader, "file.c", .user);
const expected_output = if (mem.startsWith(u8, buf, BOM)) buf[BOM.len..] else buf;
try std.testing.expectEqualStrings(expected_output, source.buf);
}
Expand Down
14 changes: 7 additions & 7 deletions lib/compiler/aro/aro/Diagnostics.zig
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,14 @@ pub fn addExtra(
return error.FatalError;
}

pub fn render(comp: *Compilation, config: std.io.tty.Config) void {
pub fn render(comp: *Compilation, config: std.Io.tty.Config) void {
if (comp.diagnostics.list.items.len == 0) return;
var buffer: [1000]u8 = undefined;
var m = defaultMsgWriter(config, &buffer);
defer m.deinit();
renderMessages(comp, &m);
}
pub fn defaultMsgWriter(config: std.io.tty.Config, buffer: []u8) MsgWriter {
pub fn defaultMsgWriter(config: std.Io.tty.Config, buffer: []u8) MsgWriter {
return MsgWriter.init(config, buffer);
}

Expand Down Expand Up @@ -451,7 +451,7 @@ pub fn renderMessage(comp: *Compilation, m: anytype, msg: Message) void {
},
.normalized => {
const f = struct {
pub fn f(bytes: []const u8, writer: *std.io.Writer) std.io.Writer.Error!void {
pub fn f(bytes: []const u8, writer: *std.Io.Writer) std.Io.Writer.Error!void {
var it: std.unicode.Utf8Iterator = .{
.bytes = bytes,
.i = 0,
Expand Down Expand Up @@ -526,10 +526,10 @@ fn tagKind(d: *Diagnostics, tag: Tag, langopts: LangOpts) Kind {
}

const MsgWriter = struct {
writer: *std.io.Writer,
config: std.io.tty.Config,
writer: *std.Io.Writer,
config: std.Io.tty.Config,

fn init(config: std.io.tty.Config, buffer: []u8) MsgWriter {
fn init(config: std.Io.tty.Config, buffer: []u8) MsgWriter {
return .{
.writer = std.debug.lockStderrWriter(buffer),
.config = config,
Expand All @@ -549,7 +549,7 @@ const MsgWriter = struct {
m.writer.writeAll(msg) catch {};
}

fn setColor(m: *MsgWriter, color: std.io.tty.Color) void {
fn setColor(m: *MsgWriter, color: std.Io.tty.Color) void {
m.config.setColor(m.writer, color) catch {};
}

Expand Down
6 changes: 3 additions & 3 deletions lib/compiler/aro/aro/Driver.zig
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,8 @@ fn option(arg: []const u8, name: []const u8) ?[]const u8 {

fn addSource(d: *Driver, path: []const u8) !Source {
if (mem.eql(u8, "-", path)) {
const stdin = std.fs.File.stdin().deprecatedReader();
const input = try stdin.readAllAlloc(d.comp.gpa, std.math.maxInt(u32));
var stdin_reader: std.fs.File.Reader = .initStreaming(.stdin(), &.{});
const input = try stdin_reader.interface.allocRemaining(d.comp.gpa, .limited(std.math.maxInt(u32)));
defer d.comp.gpa.free(input);
return d.comp.addSourceFromBuffer("<stdin>", input);
}
Expand All @@ -544,7 +544,7 @@ pub fn renderErrors(d: *Driver) void {
Diagnostics.render(d.comp, d.detectConfig(std.fs.File.stderr()));
}

pub fn detectConfig(d: *Driver, file: std.fs.File) std.io.tty.Config {
pub fn detectConfig(d: *Driver, file: std.fs.File) std.Io.tty.Config {
if (d.color == true) return .escape_codes;
if (d.color == false) return .no_color;

Expand Down
16 changes: 8 additions & 8 deletions lib/compiler/aro/aro/Tree.zig
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ pub fn nodeLoc(tree: *const Tree, node: NodeIndex) ?Source.Location {
return tree.tokens.items(.loc)[@intFromEnum(tok_i)];
}

pub fn dump(tree: *const Tree, config: std.io.tty.Config, writer: anytype) !void {
pub fn dump(tree: *const Tree, config: std.Io.tty.Config, writer: anytype) !void {
const mapper = tree.comp.string_interner.getFastTypeMapper(tree.comp.gpa) catch tree.comp.string_interner.getSlowTypeMapper();
defer mapper.deinit(tree.comp.gpa);

Expand Down Expand Up @@ -855,17 +855,17 @@ fn dumpNode(
node: NodeIndex,
level: u32,
mapper: StringInterner.TypeMapper,
config: std.io.tty.Config,
config: std.Io.tty.Config,
w: anytype,
) !void {
const delta = 2;
const half = delta / 2;
const TYPE = std.io.tty.Color.bright_magenta;
const TAG = std.io.tty.Color.bright_cyan;
const IMPLICIT = std.io.tty.Color.bright_blue;
const NAME = std.io.tty.Color.bright_red;
const LITERAL = std.io.tty.Color.bright_green;
const ATTRIBUTE = std.io.tty.Color.bright_yellow;
const TYPE = std.Io.tty.Color.bright_magenta;
const TAG = std.Io.tty.Color.bright_cyan;
const IMPLICIT = std.Io.tty.Color.bright_blue;
const NAME = std.Io.tty.Color.bright_red;
const LITERAL = std.Io.tty.Color.bright_green;
const ATTRIBUTE = std.Io.tty.Color.bright_yellow;
std.debug.assert(node != .none);

const tag = tree.nodes.items(.tag)[@intFromEnum(node)];
Expand Down
5 changes: 2 additions & 3 deletions lib/compiler/aro/aro/target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,7 @@ pub fn toLLVMTriple(target: std.Target, buf: []u8) []const u8 {
// 64 bytes is assumed to be large enough to hold any target triple; increase if necessary
std.debug.assert(buf.len >= 64);

var stream = std.io.fixedBufferStream(buf);
const writer = stream.writer();
var writer: std.Io.Writer = .fixed(buf);

const llvm_arch = switch (target.cpu.arch) {
.arm => "arm",
Expand Down Expand Up @@ -718,7 +717,7 @@ pub fn toLLVMTriple(target: std.Target, buf: []u8) []const u8 {
.ohoseabi => "ohoseabi",
};
writer.writeAll(llvm_abi) catch unreachable;
return stream.getWritten();
return writer.buffered();
}

test "alignment functions - smoke test" {
Expand Down
24 changes: 12 additions & 12 deletions lib/compiler/aro/backend/Ir.zig
Original file line number Diff line number Diff line change
Expand Up @@ -374,21 +374,21 @@ pub fn deinit(ir: *Ir, gpa: std.mem.Allocator) void {
ir.* = undefined;
}

const TYPE = std.io.tty.Color.bright_magenta;
const INST = std.io.tty.Color.bright_cyan;
const REF = std.io.tty.Color.bright_blue;
const LITERAL = std.io.tty.Color.bright_green;
const ATTRIBUTE = std.io.tty.Color.bright_yellow;
const TYPE = std.Io.tty.Color.bright_magenta;
const INST = std.Io.tty.Color.bright_cyan;
const REF = std.Io.tty.Color.bright_blue;
const LITERAL = std.Io.tty.Color.bright_green;
const ATTRIBUTE = std.Io.tty.Color.bright_yellow;

const RefMap = std.AutoArrayHashMap(Ref, void);

pub fn dump(ir: *const Ir, gpa: Allocator, config: std.io.tty.Config, w: anytype) !void {
pub fn dump(ir: *const Ir, gpa: Allocator, config: std.Io.tty.Config, w: anytype) !void {
for (ir.decls.keys(), ir.decls.values()) |name, *decl| {
try ir.dumpDecl(decl, gpa, name, config, w);
}
}

fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8, config: std.io.tty.Config, w: anytype) !void {
fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8, config: std.Io.tty.Config, w: anytype) !void {
const tags = decl.instructions.items(.tag);
const data = decl.instructions.items(.data);

Expand Down Expand Up @@ -609,7 +609,7 @@ fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8,
try w.writeAll("}\n\n");
}

fn writeType(ir: Ir, ty_ref: Interner.Ref, config: std.io.tty.Config, w: anytype) !void {
fn writeType(ir: Ir, ty_ref: Interner.Ref, config: std.Io.tty.Config, w: anytype) !void {
const ty = ir.interner.get(ty_ref);
try config.setColor(w, TYPE);
switch (ty) {
Expand Down Expand Up @@ -639,7 +639,7 @@ fn writeType(ir: Ir, ty_ref: Interner.Ref, config: std.io.tty.Config, w: anytype
}
}

fn writeValue(ir: Ir, val: Interner.Ref, config: std.io.tty.Config, w: anytype) !void {
fn writeValue(ir: Ir, val: Interner.Ref, config: std.Io.tty.Config, w: anytype) !void {
try config.setColor(w, LITERAL);
const key = ir.interner.get(val);
switch (key) {
Expand All @@ -655,7 +655,7 @@ fn writeValue(ir: Ir, val: Interner.Ref, config: std.io.tty.Config, w: anytype)
}
}

fn writeRef(ir: Ir, decl: *const Decl, ref_map: *RefMap, ref: Ref, config: std.io.tty.Config, w: anytype) !void {
fn writeRef(ir: Ir, decl: *const Decl, ref_map: *RefMap, ref: Ref, config: std.Io.tty.Config, w: anytype) !void {
assert(ref != .none);
const index = @intFromEnum(ref);
const ty_ref = decl.instructions.items(.ty)[index];
Expand All @@ -678,7 +678,7 @@ fn writeRef(ir: Ir, decl: *const Decl, ref_map: *RefMap, ref: Ref, config: std.i
try w.print(" %{d}", .{ref_index});
}

fn writeNewRef(ir: Ir, decl: *const Decl, ref_map: *RefMap, ref: Ref, config: std.io.tty.Config, w: anytype) !void {
fn writeNewRef(ir: Ir, decl: *const Decl, ref_map: *RefMap, ref: Ref, config: std.Io.tty.Config, w: anytype) !void {
try ref_map.put(ref, {});
try w.writeAll(" ");
try ir.writeRef(decl, ref_map, ref, config, w);
Expand All @@ -687,7 +687,7 @@ fn writeNewRef(ir: Ir, decl: *const Decl, ref_map: *RefMap, ref: Ref, config: st
try config.setColor(w, INST);
}

fn writeLabel(decl: *const Decl, label_map: *RefMap, ref: Ref, config: std.io.tty.Config, w: anytype) !void {
fn writeLabel(decl: *const Decl, label_map: *RefMap, ref: Ref, config: std.Io.tty.Config, w: anytype) !void {
assert(ref != .none);
const index = @intFromEnum(ref);
const label = decl.instructions.items(.data)[index].label;
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler/aro_translate_c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1783,7 +1783,7 @@ fn renderErrorsAndExit(comp: *aro.Compilation) noreturn {
defer std.process.exit(1);

var buffer: [1000]u8 = undefined;
var writer = aro.Diagnostics.defaultMsgWriter(std.io.tty.detectConfig(std.fs.File.stderr()), &buffer);
var writer = aro.Diagnostics.defaultMsgWriter(std.Io.tty.detectConfig(std.fs.File.stderr()), &buffer);
defer writer.deinit(); // writer deinit must run *before* exit so that stderr is flushed

var saw_error = false;
Expand Down
20 changes: 10 additions & 10 deletions lib/compiler/build_runner.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const std = @import("std");
const builtin = @import("builtin");
const assert = std.debug.assert;
const io = std.io;
const fmt = std.fmt;
const mem = std.mem;
const process = std.process;
Expand All @@ -11,8 +10,9 @@ const Watch = std.Build.Watch;
const WebServer = std.Build.WebServer;
const Allocator = std.mem.Allocator;
const fatal = std.process.fatal;
const Writer = std.io.Writer;
const Writer = std.Io.Writer;
const runner = @This();
const tty = std.Io.tty;

pub const root = @import("@build");
pub const dependencies = @import("@dependencies");
Expand Down Expand Up @@ -576,7 +576,7 @@ const Run = struct {

claimed_rss: usize,
summary: Summary,
ttyconf: std.io.tty.Config,
ttyconf: tty.Config,
stderr: File,

fn cleanExit(run: Run) void {
Expand Down Expand Up @@ -819,7 +819,7 @@ const PrintNode = struct {
last: bool = false,
};

fn printPrefix(node: *PrintNode, stderr: *Writer, ttyconf: std.io.tty.Config) !void {
fn printPrefix(node: *PrintNode, stderr: *Writer, ttyconf: tty.Config) !void {
const parent = node.parent orelse return;
if (parent.parent == null) return;
try printPrefix(parent, stderr, ttyconf);
Expand All @@ -833,7 +833,7 @@ fn printPrefix(node: *PrintNode, stderr: *Writer, ttyconf: std.io.tty.Config) !v
}
}

fn printChildNodePrefix(stderr: *Writer, ttyconf: std.io.tty.Config) !void {
fn printChildNodePrefix(stderr: *Writer, ttyconf: tty.Config) !void {
try stderr.writeAll(switch (ttyconf) {
.no_color, .windows_api => "+- ",
.escape_codes => "\x1B\x28\x30\x6d\x71\x1B\x28\x42 ", // └─
Expand All @@ -843,7 +843,7 @@ fn printChildNodePrefix(stderr: *Writer, ttyconf: std.io.tty.Config) !void {
fn printStepStatus(
s: *Step,
stderr: *Writer,
ttyconf: std.io.tty.Config,
ttyconf: tty.Config,
run: *const Run,
) !void {
switch (s.state) {
Expand Down Expand Up @@ -923,7 +923,7 @@ fn printStepStatus(
fn printStepFailure(
s: *Step,
stderr: *Writer,
ttyconf: std.io.tty.Config,
ttyconf: tty.Config,
) !void {
if (s.result_error_bundle.errorMessageCount() > 0) {
try ttyconf.setColor(stderr, .red);
Expand Down Expand Up @@ -977,7 +977,7 @@ fn printTreeStep(
s: *Step,
run: *const Run,
stderr: *Writer,
ttyconf: std.io.tty.Config,
ttyconf: tty.Config,
parent_node: *PrintNode,
step_stack: *std.AutoArrayHashMapUnmanaged(*Step, void),
) !void {
Expand Down Expand Up @@ -1494,9 +1494,9 @@ fn uncleanExit() error{UncleanExit} {
const Color = std.zig.Color;
const Summary = enum { all, new, failures, none };

fn get_tty_conf(color: Color, stderr: File) std.io.tty.Config {
fn get_tty_conf(color: Color, stderr: File) tty.Config {
return switch (color) {
.auto => std.io.tty.detectConfig(stderr),
.auto => tty.detectConfig(stderr),
.on => .escape_codes,
.off => .no_color,
};
Expand Down
1 change: 0 additions & 1 deletion lib/compiler/libc.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const std = @import("std");
const mem = std.mem;
const io = std.io;
const LibCInstallation = std.zig.LibCInstallation;

const usage_libc =
Expand Down
Loading