authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-06 17:23:07-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:07-08:00
log3204fb756980c19b7a95534acdd7a1bba837fbc3
tree45b5525ead2923de83ea85eacca351da64d55c46
parent1b1fb7fab623e40f4ddc24d7b5ef7e48949e8a17

update all occurrences of std.fs.File to std.Io.File


70 files changed, 399 insertions(+), 359 deletions(-)

lib/compiler/aro/aro/Compilation.zig+2-2
...@@ -1646,7 +1646,7 @@ fn addSourceFromPathExtra(comp: *Compilation, path: []const u8, kind: Source.Kin...@@ -1646,7 +1646,7 @@ fn addSourceFromPathExtra(comp: *Compilation, path: []const u8, kind: Source.Kin
1646 return comp.addSourceFromFile(file, path, kind);1646 return comp.addSourceFromFile(file, path, kind);
1647}1647}
16481648
1649pub fn addSourceFromFile(comp: *Compilation, file: std.fs.File, path: []const u8, kind: Source.Kind) !Source {1649pub fn addSourceFromFile(comp: *Compilation, file: Io.File, path: []const u8, kind: Source.Kind) !Source {
1650 const contents = try comp.getFileContents(file, .unlimited);1650 const contents = try comp.getFileContents(file, .unlimited);
1651 errdefer comp.gpa.free(contents);1651 errdefer comp.gpa.free(contents);
1652 return comp.addSourceFromOwnedBuffer(path, contents, kind);1652 return comp.addSourceFromOwnedBuffer(path, contents, kind);
...@@ -1980,7 +1980,7 @@ fn getPathContents(comp: *Compilation, path: []const u8, limit: Io.Limit) ![]u8...@@ -1980,7 +1980,7 @@ fn getPathContents(comp: *Compilation, path: []const u8, limit: Io.Limit) ![]u8
1980 return comp.getFileContents(file, limit);1980 return comp.getFileContents(file, limit);
1981}1981}
19821982
1983fn getFileContents(comp: *Compilation, file: std.fs.File, limit: Io.Limit) ![]u8 {1983fn getFileContents(comp: *Compilation, file: Io.File, limit: Io.Limit) ![]u8 {
1984 var file_buf: [4096]u8 = undefined;1984 var file_buf: [4096]u8 = undefined;
1985 var file_reader = file.reader(comp.io, &file_buf);1985 var file_reader = file.reader(comp.io, &file_buf);
19861986
lib/compiler/aro/aro/Driver.zig+8-7
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const Io = std.Io;
2const mem = std.mem;3const mem = std.mem;
3const Allocator = mem.Allocator;4const Allocator = mem.Allocator;
4const process = std.process;5const process = std.process;
...@@ -1061,7 +1062,7 @@ pub fn printDiagnosticsStats(d: *Driver) void {...@@ -1061,7 +1062,7 @@ pub fn printDiagnosticsStats(d: *Driver) void {
1061 }1062 }
1062}1063}
10631064
1064pub fn detectConfig(d: *Driver, file: std.fs.File) std.Io.tty.Config {1065pub fn detectConfig(d: *Driver, file: Io.File) std.Io.tty.Config {
1065 if (d.diagnostics.color == false) return .no_color;1066 if (d.diagnostics.color == false) return .no_color;
1066 const force_color = d.diagnostics.color == true;1067 const force_color = d.diagnostics.color == true;
10671068
...@@ -1109,7 +1110,7 @@ pub fn main(d: *Driver, tc: *Toolchain, args: []const []const u8, comptime fast_...@@ -1109,7 +1110,7 @@ pub fn main(d: *Driver, tc: *Toolchain, args: []const []const u8, comptime fast_
1109 defer macro_buf.deinit(d.comp.gpa);1110 defer macro_buf.deinit(d.comp.gpa);
11101111
1111 var stdout_buf: [256]u8 = undefined;1112 var stdout_buf: [256]u8 = undefined;
1112 var stdout = std.fs.File.stdout().writer(&stdout_buf);1113 var stdout = Io.File.stdout().writer(&stdout_buf);
1113 if (parseArgs(d, &stdout.interface, &macro_buf, args) catch |er| switch (er) {1114 if (parseArgs(d, &stdout.interface, &macro_buf, args) catch |er| switch (er) {
1114 error.WriteFailed => return d.fatal("failed to write to stdout: {s}", .{errorDescription(er)}),1115 error.WriteFailed => return d.fatal("failed to write to stdout: {s}", .{errorDescription(er)}),
1115 error.OutOfMemory => return error.OutOfMemory,1116 error.OutOfMemory => return error.OutOfMemory,
...@@ -1329,7 +1330,7 @@ fn processSource(...@@ -1329,7 +1330,7 @@ fn processSource(
1329 d.comp.cwd.createFile(path, .{}) catch |er|1330 d.comp.cwd.createFile(path, .{}) catch |er|
1330 return d.fatal("unable to create dependency file '{s}': {s}", .{ path, errorDescription(er) })1331 return d.fatal("unable to create dependency file '{s}': {s}", .{ path, errorDescription(er) })
1331 else1332 else
1332 std.fs.File.stdout();1333 Io.File.stdout();
1333 defer if (dep_file_name != null) file.close(io);1334 defer if (dep_file_name != null) file.close(io);
13341335
1335 var file_writer = file.writer(&writer_buf);1336 var file_writer = file.writer(&writer_buf);
...@@ -1354,7 +1355,7 @@ fn processSource(...@@ -1354,7 +1355,7 @@ fn processSource(
1354 d.comp.cwd.createFile(some, .{}) catch |er|1355 d.comp.cwd.createFile(some, .{}) catch |er|
1355 return d.fatal("unable to create output file '{s}': {s}", .{ some, errorDescription(er) })1356 return d.fatal("unable to create output file '{s}': {s}", .{ some, errorDescription(er) })
1356 else1357 else
1357 std.fs.File.stdout();1358 Io.File.stdout();
1358 defer if (d.output_name != null) file.close(io);1359 defer if (d.output_name != null) file.close(io);
13591360
1360 var file_writer = file.writer(&writer_buf);1361 var file_writer = file.writer(&writer_buf);
...@@ -1369,7 +1370,7 @@ fn processSource(...@@ -1369,7 +1370,7 @@ fn processSource(
1369 defer tree.deinit();1370 defer tree.deinit();
13701371
1371 if (d.verbose_ast) {1372 if (d.verbose_ast) {
1372 var stdout = std.fs.File.stdout().writer(&writer_buf);1373 var stdout = Io.File.stdout().writer(&writer_buf);
1373 tree.dump(d.detectConfig(stdout.file), &stdout.interface) catch {};1374 tree.dump(d.detectConfig(stdout.file), &stdout.interface) catch {};
1374 }1375 }
13751376
...@@ -1433,7 +1434,7 @@ fn processSource(...@@ -1433,7 +1434,7 @@ fn processSource(
1433 defer ir.deinit(gpa);1434 defer ir.deinit(gpa);
14341435
1435 if (d.verbose_ir) {1436 if (d.verbose_ir) {
1436 var stdout = std.fs.File.stdout().writer(&writer_buf);1437 var stdout = Io.File.stdout().writer(&writer_buf);
1437 ir.dump(gpa, d.detectConfig(stdout.file), &stdout.interface) catch {};1438 ir.dump(gpa, d.detectConfig(stdout.file), &stdout.interface) catch {};
1438 }1439 }
14391440
...@@ -1499,7 +1500,7 @@ pub fn invokeLinker(d: *Driver, tc: *Toolchain, comptime fast_exit: bool) Compil...@@ -1499,7 +1500,7 @@ pub fn invokeLinker(d: *Driver, tc: *Toolchain, comptime fast_exit: bool) Compil
14991500
1500 if (d.verbose_linker_args) {1501 if (d.verbose_linker_args) {
1501 var stdout_buf: [4096]u8 = undefined;1502 var stdout_buf: [4096]u8 = undefined;
1502 var stdout = std.fs.File.stdout().writer(&stdout_buf);1503 var stdout = Io.File.stdout().writer(&stdout_buf);
1503 dumpLinkerArgs(&stdout.interface, argv.items) catch {1504 dumpLinkerArgs(&stdout.interface, argv.items) catch {
1504 return d.fatal("unable to dump linker args: {s}", .{errorDescription(stdout.err.?)});1505 return d.fatal("unable to dump linker args: {s}", .{errorDescription(stdout.err.?)});
1505 };1506 };
lib/compiler/aro/aro/Preprocessor.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const Io = std.Io;
2const mem = std.mem;3const mem = std.mem;
3const Allocator = mem.Allocator;4const Allocator = mem.Allocator;
4const assert = std.debug.assert;5const assert = std.debug.assert;
...@@ -1068,7 +1069,7 @@ fn verboseLog(pp: *Preprocessor, raw: RawToken, comptime fmt: []const u8, args:...@@ -1068,7 +1069,7 @@ fn verboseLog(pp: *Preprocessor, raw: RawToken, comptime fmt: []const u8, args:
1068 const line_col = source.lineCol(.{ .id = raw.source, .line = raw.line, .byte_offset = raw.start });1069 const line_col = source.lineCol(.{ .id = raw.source, .line = raw.line, .byte_offset = raw.start });
10691070
1070 var stderr_buf: [4096]u8 = undefined;1071 var stderr_buf: [4096]u8 = undefined;
1071 var stderr = std.fs.File.stderr().writer(&stderr_buf);1072 var stderr = Io.File.stderr().writer(&stderr_buf);
1072 const w = &stderr.interface;1073 const w = &stderr.interface;
10731074
1074 w.print("{s}:{d}:{d}: ", .{ source.path, line_col.line_no, line_col.col }) catch return;1075 w.print("{s}:{d}:{d}: ", .{ source.path, line_col.line_no, line_col.col }) catch return;
lib/compiler/aro/backend/Assembly.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const Io = std.Io;
2const Allocator = std.mem.Allocator;3const Allocator = std.mem.Allocator;
34
4data: []const u8,5data: []const u8,
...@@ -11,7 +12,7 @@ pub fn deinit(self: *const Assembly, gpa: Allocator) void {...@@ -11,7 +12,7 @@ pub fn deinit(self: *const Assembly, gpa: Allocator) void {
11 gpa.free(self.text);12 gpa.free(self.text);
12}13}
1314
14pub fn writeToFile(self: Assembly, file: std.fs.File) !void {15pub fn writeToFile(self: Assembly, file: Io.File) !void {
15 var file_writer = file.writer(&.{});16 var file_writer = file.writer(&.{});
1617
17 var buffers = [_][]const u8{ self.data, self.text };18 var buffers = [_][]const u8{ self.data, self.text };
lib/compiler/aro/main.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const Io = std.Io;
2const Allocator = mem.Allocator;3const Allocator = mem.Allocator;
3const mem = std.mem;4const mem = std.mem;
4const process = std.process;5const process = std.process;
...@@ -50,7 +51,7 @@ pub fn main() u8 {...@@ -50,7 +51,7 @@ pub fn main() u8 {
50 defer gpa.free(aro_name);51 defer gpa.free(aro_name);
5152
52 var stderr_buf: [1024]u8 = undefined;53 var stderr_buf: [1024]u8 = undefined;
53 var stderr = std.fs.File.stderr().writer(&stderr_buf);54 var stderr = Io.File.stderr().writer(&stderr_buf);
54 var diagnostics: Diagnostics = .{55 var diagnostics: Diagnostics = .{
55 .output = .{ .to_writer = .{56 .output = .{ .to_writer = .{
56 .color = .detect(stderr.file),57 .color = .detect(stderr.file),
lib/compiler/build_runner.zig+3-3
...@@ -7,7 +7,7 @@ const assert = std.debug.assert;...@@ -7,7 +7,7 @@ const assert = std.debug.assert;
7const fmt = std.fmt;7const fmt = std.fmt;
8const mem = std.mem;8const mem = std.mem;
9const process = std.process;9const process = std.process;
10const File = std.fs.File;10const File = std.Io.File;
11const Step = std.Build.Step;11const Step = std.Build.Step;
12const Watch = std.Build.Watch;12const Watch = std.Build.Watch;
13const WebServer = std.Build.WebServer;13const WebServer = std.Build.WebServer;
...@@ -1845,9 +1845,9 @@ fn createModuleDependenciesForStep(step: *Step) Allocator.Error!void {...@@ -1845,9 +1845,9 @@ fn createModuleDependenciesForStep(step: *Step) Allocator.Error!void {
1845}1845}
18461846
1847var stdio_buffer_allocation: [256]u8 = undefined;1847var stdio_buffer_allocation: [256]u8 = undefined;
1848var stdout_writer_allocation: std.fs.File.Writer = undefined;1848var stdout_writer_allocation: Io.File.Writer = undefined;
18491849
1850fn initStdoutWriter() *Writer {1850fn initStdoutWriter() *Writer {
1851 stdout_writer_allocation = std.fs.File.stdout().writerStreaming(&stdio_buffer_allocation);1851 stdout_writer_allocation = Io.File.stdout().writerStreaming(&stdio_buffer_allocation);
1852 return &stdout_writer_allocation.interface;1852 return &stdout_writer_allocation.interface;
1853}1853}
lib/compiler/libc.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const Io = std.Io;
2const mem = std.mem;3const mem = std.mem;
3const LibCInstallation = std.zig.LibCInstallation;4const LibCInstallation = std.zig.LibCInstallation;
45
...@@ -39,7 +40,7 @@ pub fn main() !void {...@@ -39,7 +40,7 @@ pub fn main() !void {
39 var input_file: ?[]const u8 = null;40 var input_file: ?[]const u8 = null;
40 var target_arch_os_abi: []const u8 = "native";41 var target_arch_os_abi: []const u8 = "native";
41 var print_includes: bool = false;42 var print_includes: bool = false;
42 var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);43 var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
43 const stdout = &stdout_writer.interface;44 const stdout = &stdout_writer.interface;
44 {45 {
45 var i: usize = 2;46 var i: usize = 2;
lib/compiler/objcopy.zig+7-6
...@@ -1,12 +1,13 @@...@@ -1,12 +1,13 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2
2const std = @import("std");3const std = @import("std");
4const Io = std.Io;
3const mem = std.mem;5const mem = std.mem;
4const fs = std.fs;6const fs = std.fs;
5const elf = std.elf;7const elf = std.elf;
6const Allocator = std.mem.Allocator;8const Allocator = std.mem.Allocator;
7const File = std.fs.File;9const File = std.Io.File;
8const assert = std.debug.assert;10const assert = std.debug.assert;
9
10const fatal = std.process.fatal;11const fatal = std.process.fatal;
11const Server = std.zig.Server;12const Server = std.zig.Server;
1213
...@@ -56,7 +57,7 @@ fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void...@@ -56,7 +57,7 @@ fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
56 fatal("unexpected positional argument: '{s}'", .{arg});57 fatal("unexpected positional argument: '{s}'", .{arg});
57 }58 }
58 } else if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {59 } else if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
59 return std.fs.File.stdout().writeAll(usage);60 return Io.File.stdout().writeAll(usage);
60 } else if (mem.eql(u8, arg, "-O") or mem.eql(u8, arg, "--output-target")) {61 } else if (mem.eql(u8, arg, "-O") or mem.eql(u8, arg, "--output-target")) {
61 i += 1;62 i += 1;
62 if (i >= args.len) fatal("expected another argument after '{s}'", .{arg});63 if (i >= args.len) fatal("expected another argument after '{s}'", .{arg});
...@@ -177,7 +178,7 @@ fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void...@@ -177,7 +178,7 @@ fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
177 }178 }
178 };179 };
179180
180 const mode = if (out_fmt != .elf or only_keep_debug) fs.File.default_mode else stat.mode;181 const mode = if (out_fmt != .elf or only_keep_debug) Io.File.default_mode else stat.mode;
181182
182 var output_file = try fs.cwd().createFile(output, .{ .mode = mode });183 var output_file = try fs.cwd().createFile(output, .{ .mode = mode });
183 defer output_file.close(io);184 defer output_file.close(io);
...@@ -221,8 +222,8 @@ fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void...@@ -221,8 +222,8 @@ fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
221 try out.end();222 try out.end();
222223
223 if (listen) {224 if (listen) {
224 var stdin_reader = fs.File.stdin().reader(io, &stdin_buffer);225 var stdin_reader = Io.File.stdin().reader(io, &stdin_buffer);
225 var stdout_writer = fs.File.stdout().writer(&stdout_buffer);226 var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
226 var server = try Server.init(.{227 var server = try Server.init(.{
227 .in = &stdin_reader.interface,228 .in = &stdin_reader.interface,
228 .out = &stdout_writer.interface,229 .out = &stdout_writer.interface,
lib/compiler/reduce.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const Io = std.Io;
2const mem = std.mem;3const mem = std.mem;
3const Allocator = std.mem.Allocator;4const Allocator = std.mem.Allocator;
4const assert = std.debug.assert;5const assert = std.debug.assert;
...@@ -68,7 +69,7 @@ pub fn main() !void {...@@ -68,7 +69,7 @@ pub fn main() !void {
68 const arg = args[i];69 const arg = args[i];
69 if (mem.startsWith(u8, arg, "-")) {70 if (mem.startsWith(u8, arg, "-")) {
70 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {71 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
71 const stdout = std.fs.File.stdout();72 const stdout = Io.File.stdout();
72 try stdout.writeAll(usage);73 try stdout.writeAll(usage);
73 return std.process.cleanExit();74 return std.process.cleanExit();
74 } else if (mem.eql(u8, arg, "--")) {75 } else if (mem.eql(u8, arg, "--")) {
lib/compiler/resinator/cli.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const Io = std.Io;
2const code_pages = @import("code_pages.zig");3const code_pages = @import("code_pages.zig");
3const SupportedCodePage = code_pages.SupportedCodePage;4const SupportedCodePage = code_pages.SupportedCodePage;
4const lang = @import("lang.zig");5const lang = @import("lang.zig");
...@@ -169,7 +170,7 @@ pub const Options = struct {...@@ -169,7 +170,7 @@ pub const Options = struct {
169 coff_options: cvtres.CoffOptions = .{},170 coff_options: cvtres.CoffOptions = .{},
170171
171 pub const IoSource = union(enum) {172 pub const IoSource = union(enum) {
172 stdio: std.fs.File,173 stdio: Io.File,
173 filename: []const u8,174 filename: []const u8,
174 };175 };
175 pub const AutoIncludes = enum { any, msvc, gnu, none };176 pub const AutoIncludes = enum { any, msvc, gnu, none };
lib/compiler/resinator/errors.zig+4-4
...@@ -169,9 +169,9 @@ pub const ErrorDetails = struct {...@@ -169,9 +169,9 @@ pub const ErrorDetails = struct {
169 filename_string_index: FilenameStringIndex,169 filename_string_index: FilenameStringIndex,
170170
171 pub const FilenameStringIndex = std.meta.Int(.unsigned, 32 - @bitSizeOf(FileOpenErrorEnum));171 pub const FilenameStringIndex = std.meta.Int(.unsigned, 32 - @bitSizeOf(FileOpenErrorEnum));
172 pub const FileOpenErrorEnum = std.meta.FieldEnum(std.fs.File.OpenError || std.fs.File.StatError);172 pub const FileOpenErrorEnum = std.meta.FieldEnum(Io.File.OpenError || Io.File.StatError);
173173
174 pub fn enumFromError(err: (std.fs.File.OpenError || std.fs.File.StatError)) FileOpenErrorEnum {174 pub fn enumFromError(err: (Io.File.OpenError || Io.File.StatError)) FileOpenErrorEnum {
175 return switch (err) {175 return switch (err) {
176 inline else => |e| @field(ErrorDetails.FileOpenError.FileOpenErrorEnum, @errorName(e)),176 inline else => |e| @field(ErrorDetails.FileOpenError.FileOpenErrorEnum, @errorName(e)),
177 };177 };
...@@ -1094,8 +1094,8 @@ const CorrespondingLines = struct {...@@ -1094,8 +1094,8 @@ const CorrespondingLines = struct {
1094 last_byte: u8 = 0,1094 last_byte: u8 = 0,
1095 at_eof: bool = false,1095 at_eof: bool = false,
1096 span: SourceMappings.CorrespondingSpan,1096 span: SourceMappings.CorrespondingSpan,
1097 file: std.fs.File,1097 file: Io.File,
1098 file_reader: std.fs.File.Reader,1098 file_reader: Io.File.Reader,
1099 code_page: SupportedCodePage,1099 code_page: SupportedCodePage,
11001100
1101 pub fn init(1101 pub fn init(
lib/compiler/resinator/main.zig+5-5
...@@ -45,7 +45,7 @@ pub fn main() !void {...@@ -45,7 +45,7 @@ pub fn main() !void {
45 }45 }
4646
47 var stdout_buffer: [1024]u8 = undefined;47 var stdout_buffer: [1024]u8 = undefined;
48 var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);48 var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
49 const stdout = &stdout_writer.interface;49 const stdout = &stdout_writer.interface;
50 var error_handler: ErrorHandler = switch (zig_integration) {50 var error_handler: ErrorHandler = switch (zig_integration) {
51 true => .{51 true => .{
...@@ -447,8 +447,8 @@ const IoStream = struct {...@@ -447,8 +447,8 @@ const IoStream = struct {
447 }447 }
448448
449 pub const Source = union(enum) {449 pub const Source = union(enum) {
450 file: std.fs.File,450 file: Io.File,
451 stdio: std.fs.File,451 stdio: Io.File,
452 memory: std.ArrayList(u8),452 memory: std.ArrayList(u8),
453 /// The source has been closed and any usage of the Source in this state is illegal (except deinit).453 /// The source has been closed and any usage of the Source in this state is illegal (except deinit).
454 closed: void,454 closed: void,
...@@ -500,10 +500,10 @@ const IoStream = struct {...@@ -500,10 +500,10 @@ const IoStream = struct {
500 }500 }
501501
502 pub const Writer = union(enum) {502 pub const Writer = union(enum) {
503 file: std.fs.File.Writer,503 file: Io.File.Writer,
504 allocating: std.Io.Writer.Allocating,504 allocating: std.Io.Writer.Allocating,
505505
506 pub const Error = Allocator.Error || std.fs.File.WriteError;506 pub const Error = Allocator.Error || Io.File.WriteError;
507507
508 pub fn interface(this: *@This()) *std.Io.Writer {508 pub fn interface(this: *@This()) *std.Io.Writer {
509 return switch (this.*) {509 return switch (this.*) {
lib/compiler/resinator/utils.zig+2-2
...@@ -32,8 +32,8 @@ pub fn openFileNotDir(...@@ -32,8 +32,8 @@ pub fn openFileNotDir(
32 cwd: std.fs.Dir,32 cwd: std.fs.Dir,
33 io: Io,33 io: Io,
34 path: []const u8,34 path: []const u8,
35 flags: std.fs.File.OpenFlags,35 flags: Io.File.OpenFlags,
36) (std.fs.File.OpenError || std.fs.File.StatError)!std.fs.File {36) (Io.File.OpenError || Io.File.StatError)!Io.File {
37 const file = try cwd.openFile(io, path, flags);37 const file = try cwd.openFile(io, path, flags);
38 errdefer file.close(io);38 errdefer file.close(io);
39 // https://github.com/ziglang/zig/issues/573239 // https://github.com/ziglang/zig/issues/5732
lib/compiler/test_runner.zig+5-5
...@@ -74,8 +74,8 @@ pub fn main() void {...@@ -74,8 +74,8 @@ pub fn main() void {
7474
75fn mainServer() !void {75fn mainServer() !void {
76 @disableInstrumentation();76 @disableInstrumentation();
77 var stdin_reader = std.fs.File.stdin().readerStreaming(runner_threaded_io.io(), &stdin_buffer);77 var stdin_reader = Io.File.stdin().readerStreaming(runner_threaded_io.io(), &stdin_buffer);
78 var stdout_writer = std.fs.File.stdout().writerStreaming(&stdout_buffer);78 var stdout_writer = Io.File.stdout().writerStreaming(&stdout_buffer);
79 var server = try std.zig.Server.init(.{79 var server = try std.zig.Server.init(.{
80 .in = &stdin_reader.interface,80 .in = &stdin_reader.interface,
81 .out = &stdout_writer.interface,81 .out = &stdout_writer.interface,
...@@ -228,7 +228,7 @@ fn mainTerminal() void {...@@ -228,7 +228,7 @@ fn mainTerminal() void {
228 .root_name = "Test",228 .root_name = "Test",
229 .estimated_total_items = test_fn_list.len,229 .estimated_total_items = test_fn_list.len,
230 });230 });
231 const have_tty = std.fs.File.stderr().isTty();231 const have_tty = Io.File.stderr().isTty();
232232
233 var leaks: usize = 0;233 var leaks: usize = 0;
234 for (test_fn_list, 0..) |test_fn, i| {234 for (test_fn_list, 0..) |test_fn, i| {
...@@ -318,7 +318,7 @@ pub fn log(...@@ -318,7 +318,7 @@ pub fn log(
318/// work-in-progress backends can handle it.318/// work-in-progress backends can handle it.
319pub fn mainSimple() anyerror!void {319pub fn mainSimple() anyerror!void {
320 @disableInstrumentation();320 @disableInstrumentation();
321 // is the backend capable of calling `std.fs.File.writeAll`?321 // is the backend capable of calling `Io.File.writeAll`?
322 const enable_write = switch (builtin.zig_backend) {322 const enable_write = switch (builtin.zig_backend) {
323 .stage2_aarch64, .stage2_riscv64 => true,323 .stage2_aarch64, .stage2_riscv64 => true,
324 else => false,324 else => false,
...@@ -334,7 +334,7 @@ pub fn mainSimple() anyerror!void {...@@ -334,7 +334,7 @@ pub fn mainSimple() anyerror!void {
334 var failed: u64 = 0;334 var failed: u64 = 0;
335335
336 // we don't want to bring in File and Writer if the backend doesn't support it336 // we don't want to bring in File and Writer if the backend doesn't support it
337 const stdout = if (enable_write) std.fs.File.stdout() else {};337 const stdout = if (enable_write) Io.File.stdout() else {};
338338
339 for (builtin.test_functions) |test_fn| {339 for (builtin.test_functions) |test_fn| {
340 if (enable_write) {340 if (enable_write) {
lib/compiler/translate-c/main.zig+7-6
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const Io = std.Io;
2const assert = std.debug.assert;3const assert = std.debug.assert;
3const mem = std.mem;4const mem = std.mem;
4const process = std.process;5const process = std.process;
...@@ -34,7 +35,7 @@ pub fn main() u8 {...@@ -34,7 +35,7 @@ pub fn main() u8 {
34 }35 }
3536
36 var stderr_buf: [1024]u8 = undefined;37 var stderr_buf: [1024]u8 = undefined;
37 var stderr = std.fs.File.stderr().writer(&stderr_buf);38 var stderr = Io.File.stderr().writer(&stderr_buf);
38 var diagnostics: aro.Diagnostics = switch (zig_integration) {39 var diagnostics: aro.Diagnostics = switch (zig_integration) {
39 false => .{ .output = .{ .to_writer = .{40 false => .{ .output = .{ .to_writer = .{
40 .color = .detect(stderr.file),41 .color = .detect(stderr.file),
...@@ -99,7 +100,7 @@ fn serveErrorBundle(arena: std.mem.Allocator, diagnostics: *const aro.Diagnostic...@@ -99,7 +100,7 @@ fn serveErrorBundle(arena: std.mem.Allocator, diagnostics: *const aro.Diagnostic
99 "translation failure",100 "translation failure",
100 );101 );
101 var stdout_buffer: [1024]u8 = undefined;102 var stdout_buffer: [1024]u8 = undefined;
102 var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);103 var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
103 var server: std.zig.Server = .{104 var server: std.zig.Server = .{
104 .out = &stdout_writer.interface,105 .out = &stdout_writer.interface,
105 .in = undefined,106 .in = undefined,
...@@ -129,13 +130,13 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8, zig_integration...@@ -129,13 +130,13 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8, zig_integration
129 args[i] = arg;130 args[i] = arg;
130 if (mem.eql(u8, arg, "--help")) {131 if (mem.eql(u8, arg, "--help")) {
131 var stdout_buf: [512]u8 = undefined;132 var stdout_buf: [512]u8 = undefined;
132 var stdout = std.fs.File.stdout().writer(&stdout_buf);133 var stdout = Io.File.stdout().writer(&stdout_buf);
133 try stdout.interface.print(usage, .{args[0]});134 try stdout.interface.print(usage, .{args[0]});
134 try stdout.interface.flush();135 try stdout.interface.flush();
135 return;136 return;
136 } else if (mem.eql(u8, arg, "--version")) {137 } else if (mem.eql(u8, arg, "--version")) {
137 var stdout_buf: [512]u8 = undefined;138 var stdout_buf: [512]u8 = undefined;
138 var stdout = std.fs.File.stdout().writer(&stdout_buf);139 var stdout = Io.File.stdout().writer(&stdout_buf);
139 // TODO add version140 // TODO add version
140 try stdout.interface.writeAll("0.0.0-dev\n");141 try stdout.interface.writeAll("0.0.0-dev\n");
141 try stdout.interface.flush();142 try stdout.interface.flush();
...@@ -228,7 +229,7 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8, zig_integration...@@ -228,7 +229,7 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8, zig_integration
228 d.comp.cwd.createFile(path, .{}) catch |er|229 d.comp.cwd.createFile(path, .{}) catch |er|
229 return d.fatal("unable to create dependency file '{s}': {s}", .{ path, aro.Driver.errorDescription(er) })230 return d.fatal("unable to create dependency file '{s}': {s}", .{ path, aro.Driver.errorDescription(er) })
230 else231 else
231 std.fs.File.stdout();232 Io.File.stdout();
232 defer if (dep_file_name != null) file.close(io);233 defer if (dep_file_name != null) file.close(io);
233234
234 var file_writer = file.writer(&out_buf);235 var file_writer = file.writer(&out_buf);
...@@ -246,7 +247,7 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8, zig_integration...@@ -246,7 +247,7 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8, zig_integration
246247
247 var close_out_file = false;248 var close_out_file = false;
248 var out_file_path: []const u8 = "<stdout>";249 var out_file_path: []const u8 = "<stdout>";
249 var out_file: std.fs.File = .stdout();250 var out_file: Io.File = .stdout();
250 defer if (close_out_file) out_file.close(io);251 defer if (close_out_file) out_file.close(io);
251252
252 if (d.output_name) |path| blk: {253 if (d.output_name) |path| blk: {
lib/std/Build.zig+3-3
...@@ -1,3 +1,4 @@...@@ -1,3 +1,4 @@
1const Build = @This();
1const builtin = @import("builtin");2const builtin = @import("builtin");
23
3const std = @import("std.zig");4const std = @import("std.zig");
...@@ -9,13 +10,12 @@ const panic = std.debug.panic;...@@ -9,13 +10,12 @@ const panic = std.debug.panic;
9const assert = debug.assert;10const assert = debug.assert;
10const log = std.log;11const log = std.log;
11const StringHashMap = std.StringHashMap;12const StringHashMap = std.StringHashMap;
12const Allocator = mem.Allocator;13const Allocator = std.mem.Allocator;
13const Target = std.Target;14const Target = std.Target;
14const process = std.process;15const process = std.process;
15const EnvMap = std.process.EnvMap;16const EnvMap = std.process.EnvMap;
16const File = fs.File;17const File = std.Io.File;
17const Sha256 = std.crypto.hash.sha2.Sha256;18const Sha256 = std.crypto.hash.sha2.Sha256;
18const Build = @This();
19const ArrayList = std.ArrayList;19const ArrayList = std.ArrayList;
2020
21pub const Cache = @import("Build/Cache.zig");21pub const Cache = @import("Build/Cache.zig");
lib/std/Build/Step.zig+1-1
...@@ -667,7 +667,7 @@ fn clearZigProcess(s: *Step, gpa: Allocator) void {...@@ -667,7 +667,7 @@ fn clearZigProcess(s: *Step, gpa: Allocator) void {
667 }667 }
668}668}
669669
670fn sendMessage(file: std.fs.File, tag: std.zig.Client.Message.Tag) !void {670fn sendMessage(file: Io.File, tag: std.zig.Client.Message.Tag) !void {
671 const header: std.zig.Client.Message.Header = .{671 const header: std.zig.Client.Message.Header = .{
672 .tag = tag,672 .tag = tag,
673 .bytes_len = 0,673 .bytes_len = 0,
lib/std/Build/Step/ObjCopy.zig+1-1
...@@ -3,7 +3,7 @@ const ObjCopy = @This();...@@ -3,7 +3,7 @@ const ObjCopy = @This();
33
4const Allocator = std.mem.Allocator;4const Allocator = std.mem.Allocator;
5const ArenaAllocator = std.heap.ArenaAllocator;5const ArenaAllocator = std.heap.ArenaAllocator;
6const File = std.fs.File;6const File = std.Io.File;
7const InstallDir = std.Build.InstallDir;7const InstallDir = std.Build.InstallDir;
8const Step = std.Build.Step;8const Step = std.Build.Step;
9const elf = std.elf;9const elf = std.elf;
lib/std/Build/Step/Run.zig+11-10
...@@ -1,15 +1,16 @@...@@ -1,15 +1,16 @@
1const std = @import("std");1const Run = @This();
2const builtin = @import("builtin");2const builtin = @import("builtin");
3
4const std = @import("std");
5const Io = std.Io;
3const Build = std.Build;6const Build = std.Build;
4const Step = Build.Step;7const Step = std.Build.Step;
5const fs = std.fs;8const fs = std.fs;
6const mem = std.mem;9const mem = std.mem;
7const process = std.process;10const process = std.process;
8const EnvMap = process.EnvMap;11const EnvMap = std.process.EnvMap;
9const assert = std.debug.assert;12const assert = std.debug.assert;
10const Path = Build.Cache.Path;13const Path = std.Build.Cache.Path;
11
12const Run = @This();
1314
14pub const base_id: Step.Id = .run;15pub const base_id: Step.Id = .run;
1516
...@@ -2095,7 +2096,7 @@ pub const CachedTestMetadata = struct {...@@ -2095,7 +2096,7 @@ pub const CachedTestMetadata = struct {
2095 }2096 }
2096};2097};
20972098
2098fn requestNextTest(in: fs.File, metadata: *TestMetadata, sub_prog_node: *?std.Progress.Node) !void {2099fn requestNextTest(in: Io.File, metadata: *TestMetadata, sub_prog_node: *?std.Progress.Node) !void {
2099 while (metadata.next_index < metadata.names.len) {2100 while (metadata.next_index < metadata.names.len) {
2100 const i = metadata.next_index;2101 const i = metadata.next_index;
2101 metadata.next_index += 1;2102 metadata.next_index += 1;
...@@ -2114,7 +2115,7 @@ fn requestNextTest(in: fs.File, metadata: *TestMetadata, sub_prog_node: *?std.Pr...@@ -2114,7 +2115,7 @@ fn requestNextTest(in: fs.File, metadata: *TestMetadata, sub_prog_node: *?std.Pr
2114 }2115 }
2115}2116}
21162117
2117fn sendMessage(file: std.fs.File, tag: std.zig.Client.Message.Tag) !void {2118fn sendMessage(file: Io.File, tag: std.zig.Client.Message.Tag) !void {
2118 const header: std.zig.Client.Message.Header = .{2119 const header: std.zig.Client.Message.Header = .{
2119 .tag = tag,2120 .tag = tag,
2120 .bytes_len = 0,2121 .bytes_len = 0,
...@@ -2125,7 +2126,7 @@ fn sendMessage(file: std.fs.File, tag: std.zig.Client.Message.Tag) !void {...@@ -2125,7 +2126,7 @@ fn sendMessage(file: std.fs.File, tag: std.zig.Client.Message.Tag) !void {
2125 };2126 };
2126}2127}
21272128
2128fn sendRunTestMessage(file: std.fs.File, tag: std.zig.Client.Message.Tag, index: u32) !void {2129fn sendRunTestMessage(file: Io.File, tag: std.zig.Client.Message.Tag, index: u32) !void {
2129 const header: std.zig.Client.Message.Header = .{2130 const header: std.zig.Client.Message.Header = .{
2130 .tag = tag,2131 .tag = tag,
2131 .bytes_len = 4,2132 .bytes_len = 4,
...@@ -2140,7 +2141,7 @@ fn sendRunTestMessage(file: std.fs.File, tag: std.zig.Client.Message.Tag, index:...@@ -2140,7 +2141,7 @@ fn sendRunTestMessage(file: std.fs.File, tag: std.zig.Client.Message.Tag, index:
2140}2141}
21412142
2142fn sendRunFuzzTestMessage(2143fn sendRunFuzzTestMessage(
2143 file: std.fs.File,2144 file: Io.File,
2144 index: u32,2145 index: u32,
2145 kind: std.Build.abi.fuzz.LimitKind,2146 kind: std.Build.abi.fuzz.LimitKind,
2146 amount_or_instance: u64,2147 amount_or_instance: u64,
lib/std/Io.zig+1-1
...@@ -528,7 +528,7 @@ pub fn Poller(comptime StreamEnum: type) type {...@@ -528,7 +528,7 @@ pub fn Poller(comptime StreamEnum: type) type {
528/// Given an enum, returns a struct with fields of that enum, each field528/// Given an enum, returns a struct with fields of that enum, each field
529/// representing an I/O stream for polling.529/// representing an I/O stream for polling.
530pub fn PollFiles(comptime StreamEnum: type) type {530pub fn PollFiles(comptime StreamEnum: type) type {
531 return @Struct(.auto, null, std.meta.fieldNames(StreamEnum), &@splat(std.fs.File), &@splat(.{}));531 return @Struct(.auto, null, std.meta.fieldNames(StreamEnum), &@splat(Io.File), &@splat(.{}));
532}532}
533533
534test {534test {
lib/std/Io/Writer.zig+5-4
...@@ -1,7 +1,8 @@...@@ -1,7 +1,8 @@
1const Writer = @This();
2
1const builtin = @import("builtin");3const builtin = @import("builtin");
2const native_endian = builtin.target.cpu.arch.endian();4const native_endian = builtin.target.cpu.arch.endian();
35
4const Writer = @This();
5const std = @import("../std.zig");6const std = @import("../std.zig");
6const assert = std.debug.assert;7const assert = std.debug.assert;
7const Limit = std.Io.Limit;8const Limit = std.Io.Limit;
...@@ -2837,7 +2838,7 @@ test "discarding sendFile" {...@@ -2837,7 +2838,7 @@ test "discarding sendFile" {
2837 const file = try tmp_dir.dir.createFile("input.txt", .{ .read = true });2838 const file = try tmp_dir.dir.createFile("input.txt", .{ .read = true });
2838 defer file.close(io);2839 defer file.close(io);
2839 var r_buffer: [256]u8 = undefined;2840 var r_buffer: [256]u8 = undefined;
2840 var file_writer: std.fs.File.Writer = .init(file, &r_buffer);2841 var file_writer: File.Writer = .init(file, &r_buffer);
2841 try file_writer.interface.writeByte('h');2842 try file_writer.interface.writeByte('h');
2842 try file_writer.interface.flush();2843 try file_writer.interface.flush();
28432844
...@@ -2859,7 +2860,7 @@ test "allocating sendFile" {...@@ -2859,7 +2860,7 @@ test "allocating sendFile" {
2859 const file = try tmp_dir.dir.createFile("input.txt", .{ .read = true });2860 const file = try tmp_dir.dir.createFile("input.txt", .{ .read = true });
2860 defer file.close(io);2861 defer file.close(io);
2861 var r_buffer: [2]u8 = undefined;2862 var r_buffer: [2]u8 = undefined;
2862 var file_writer: std.fs.File.Writer = .init(file, &r_buffer);2863 var file_writer: File.Writer = .init(file, &r_buffer);
2863 try file_writer.interface.writeAll("abcd");2864 try file_writer.interface.writeAll("abcd");
2864 try file_writer.interface.flush();2865 try file_writer.interface.flush();
28652866
...@@ -2883,7 +2884,7 @@ test sendFileReading {...@@ -2883,7 +2884,7 @@ test sendFileReading {
2883 const file = try tmp_dir.dir.createFile("input.txt", .{ .read = true });2884 const file = try tmp_dir.dir.createFile("input.txt", .{ .read = true });
2884 defer file.close(io);2885 defer file.close(io);
2885 var r_buffer: [2]u8 = undefined;2886 var r_buffer: [2]u8 = undefined;
2886 var file_writer: std.fs.File.Writer = .init(file, &r_buffer);2887 var file_writer: File.Writer = .init(file, &r_buffer);
2887 try file_writer.interface.writeAll("abcd");2888 try file_writer.interface.writeAll("abcd");
2888 try file_writer.interface.flush();2889 try file_writer.interface.flush();
28892890
lib/std/Io/test.zig+1-1
...@@ -10,7 +10,7 @@ const expectError = std.testing.expectError;...@@ -10,7 +10,7 @@ const expectError = std.testing.expectError;
10const DefaultPrng = std.Random.DefaultPrng;10const DefaultPrng = std.Random.DefaultPrng;
11const mem = std.mem;11const mem = std.mem;
12const fs = std.fs;12const fs = std.fs;
13const File = std.fs.File;13const File = std.Io.File;
14const assert = std.debug.assert;14const assert = std.debug.assert;
1515
16const tmpDir = std.testing.tmpDir;16const tmpDir = std.testing.tmpDir;
lib/std/Io/tty.zig+4-3
...@@ -1,9 +1,10 @@...@@ -1,9 +1,10 @@
1const std = @import("std");
2const builtin = @import("builtin");1const builtin = @import("builtin");
3const File = std.fs.File;2const native_os = builtin.os.tag;
3
4const std = @import("std");
5const File = std.Io.File;
4const process = std.process;6const process = std.process;
5const windows = std.os.windows;7const windows = std.os.windows;
6const native_os = builtin.os.tag;
78
8pub const Color = enum {9pub const Color = enum {
9 black,10 black,
lib/std/Progress.zig+10-8
...@@ -1,19 +1,21 @@...@@ -1,19 +1,21 @@
1//! This API is non-allocating, non-fallible, thread-safe, and lock-free.1//! This API is non-allocating, non-fallible, thread-safe, and lock-free.
2const Progress = @This();
23
3const std = @import("std");
4const builtin = @import("builtin");4const builtin = @import("builtin");
5const is_big_endian = builtin.cpu.arch.endian() == .big;
6const is_windows = builtin.os.tag == .windows;
7
8const std = @import("std");
9const Io = std.Io;
5const windows = std.os.windows;10const windows = std.os.windows;
6const testing = std.testing;11const testing = std.testing;
7const assert = std.debug.assert;12const assert = std.debug.assert;
8const Progress = @This();
9const posix = std.posix;13const posix = std.posix;
10const is_big_endian = builtin.cpu.arch.endian() == .big;
11const is_windows = builtin.os.tag == .windows;
12const Writer = std.Io.Writer;14const Writer = std.Io.Writer;
1315
14/// `null` if the current node (and its children) should16/// `null` if the current node (and its children) should
15/// not print on update()17/// not print on update()
16terminal: std.fs.File,18terminal: Io.File,
1719
18terminal_mode: TerminalMode,20terminal_mode: TerminalMode,
1921
...@@ -472,7 +474,7 @@ pub fn start(options: Options) Node {...@@ -472,7 +474,7 @@ pub fn start(options: Options) Node {
472 if (options.disable_printing) {474 if (options.disable_printing) {
473 return Node.none;475 return Node.none;
474 }476 }
475 const stderr: std.fs.File = .stderr();477 const stderr: Io.File = .stderr();
476 global_progress.terminal = stderr;478 global_progress.terminal = stderr;
477 if (stderr.enableAnsiEscapeCodes()) |_| {479 if (stderr.enableAnsiEscapeCodes()) |_| {
478 global_progress.terminal_mode = .ansi_escape_codes;480 global_progress.terminal_mode = .ansi_escape_codes;
...@@ -633,8 +635,8 @@ pub fn unlockStdErr() void {...@@ -633,8 +635,8 @@ pub fn unlockStdErr() void {
633/// Protected by `stderr_mutex`.635/// Protected by `stderr_mutex`.
634const stderr_writer: *Writer = &stderr_file_writer.interface;636const stderr_writer: *Writer = &stderr_file_writer.interface;
635/// Protected by `stderr_mutex`.637/// Protected by `stderr_mutex`.
636var stderr_file_writer: std.fs.File.Writer = .{638var stderr_file_writer: Io.File.Writer = .{
637 .interface = std.fs.File.Writer.initInterface(&.{}),639 .interface = Io.File.Writer.initInterface(&.{}),
638 .file = if (is_windows) undefined else .stderr(),640 .file = if (is_windows) undefined else .stderr(),
639 .mode = .streaming,641 .mode = .streaming,
640};642};
lib/std/Random/benchmark.zig+4-2
...@@ -1,7 +1,9 @@...@@ -1,7 +1,9 @@
1// zig run -O ReleaseFast --zig-lib-dir ../.. benchmark.zig1// zig run -O ReleaseFast --zig-lib-dir ../.. benchmark.zig
22
3const std = @import("std");
4const builtin = @import("builtin");3const builtin = @import("builtin");
4
5const std = @import("std");
6const Io = std.Io;
5const time = std.time;7const time = std.time;
6const Timer = time.Timer;8const Timer = time.Timer;
7const Random = std.Random;9const Random = std.Random;
...@@ -123,7 +125,7 @@ fn mode(comptime x: comptime_int) comptime_int {...@@ -123,7 +125,7 @@ fn mode(comptime x: comptime_int) comptime_int {
123125
124pub fn main() !void {126pub fn main() !void {
125 var stdout_buffer: [0x100]u8 = undefined;127 var stdout_buffer: [0x100]u8 = undefined;
126 var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);128 var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
127 const stdout = &stdout_writer.interface;129 const stdout = &stdout_writer.interface;
128130
129 var buffer: [1024]u8 = undefined;131 var buffer: [1024]u8 = undefined;
lib/std/Thread.zig+2-2
...@@ -175,7 +175,7 @@ pub const SetNameError = error{...@@ -175,7 +175,7 @@ pub const SetNameError = error{
175 Unsupported,175 Unsupported,
176 Unexpected,176 Unexpected,
177 InvalidWtf8,177 InvalidWtf8,
178} || posix.PrctlError || posix.WriteError || std.fs.File.OpenError || std.fmt.BufPrintError;178} || posix.PrctlError || posix.WriteError || Io.File.OpenError || std.fmt.BufPrintError;
179179
180pub fn setName(self: Thread, io: Io, name: []const u8) SetNameError!void {180pub fn setName(self: Thread, io: Io, name: []const u8) SetNameError!void {
181 if (name.len > max_name_len) return error.NameTooLong;181 if (name.len > max_name_len) return error.NameTooLong;
...@@ -293,7 +293,7 @@ pub fn setName(self: Thread, io: Io, name: []const u8) SetNameError!void {...@@ -293,7 +293,7 @@ pub fn setName(self: Thread, io: Io, name: []const u8) SetNameError!void {
293pub const GetNameError = error{293pub const GetNameError = error{
294 Unsupported,294 Unsupported,
295 Unexpected,295 Unexpected,
296} || posix.PrctlError || posix.ReadError || std.fs.File.OpenError || std.fmt.BufPrintError;296} || posix.PrctlError || posix.ReadError || Io.File.OpenError || std.fmt.BufPrintError;
297297
298/// On Windows, the result is encoded as [WTF-8](https://wtf-8.codeberg.page/).298/// On Windows, the result is encoded as [WTF-8](https://wtf-8.codeberg.page/).
299/// On other platforms, the result is an opaque sequence of bytes with no particular encoding.299/// On other platforms, the result is an opaque sequence of bytes with no particular encoding.
lib/std/crypto/Certificate/Bundle.zig+4-4
...@@ -171,7 +171,7 @@ fn rescanWindows(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp) RescanW...@@ -171,7 +171,7 @@ fn rescanWindows(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp) RescanW
171 cb.bytes.shrinkAndFree(gpa, cb.bytes.items.len);171 cb.bytes.shrinkAndFree(gpa, cb.bytes.items.len);
172}172}
173173
174pub const AddCertsFromDirPathError = fs.File.OpenError || AddCertsFromDirError;174pub const AddCertsFromDirPathError = Io.File.OpenError || AddCertsFromDirError;
175175
176pub fn addCertsFromDirPath(176pub fn addCertsFromDirPath(
177 cb: *Bundle,177 cb: *Bundle,
...@@ -212,7 +212,7 @@ pub fn addCertsFromDir(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp, i...@@ -212,7 +212,7 @@ pub fn addCertsFromDir(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp, i
212 }212 }
213}213}
214214
215pub const AddCertsFromFilePathError = fs.File.OpenError || AddCertsFromFileError || Io.Clock.Error;215pub const AddCertsFromFilePathError = Io.File.OpenError || AddCertsFromFileError || Io.Clock.Error;
216216
217pub fn addCertsFromFilePathAbsolute(217pub fn addCertsFromFilePathAbsolute(
218 cb: *Bundle,218 cb: *Bundle,
...@@ -242,8 +242,8 @@ pub fn addCertsFromFilePath(...@@ -242,8 +242,8 @@ pub fn addCertsFromFilePath(
242}242}
243243
244pub const AddCertsFromFileError = Allocator.Error ||244pub const AddCertsFromFileError = Allocator.Error ||
245 fs.File.GetSeekPosError ||245 Io.File.GetSeekPosError ||
246 fs.File.ReadError ||246 Io.File.ReadError ||
247 ParseCertError ||247 ParseCertError ||
248 std.base64.Error ||248 std.base64.Error ||
249 error{ CertificateAuthorityBundleTooBig, MissingEndCertificateMarker, Streaming };249 error{ CertificateAuthorityBundleTooBig, MissingEndCertificateMarker, Streaming };
lib/std/crypto/Certificate/Bundle/macos.zig+1-1
...@@ -6,7 +6,7 @@ const mem = std.mem;...@@ -6,7 +6,7 @@ const mem = std.mem;
6const Allocator = std.mem.Allocator;6const Allocator = std.mem.Allocator;
7const Bundle = @import("../Bundle.zig");7const Bundle = @import("../Bundle.zig");
88
9pub const RescanMacError = Allocator.Error || fs.File.OpenError || fs.File.ReadError || fs.File.SeekError || Bundle.ParseCertError || error{EndOfStream};9pub const RescanMacError = Allocator.Error || Io.File.OpenError || Io.File.ReadError || Io.File.SeekError || Bundle.ParseCertError || error{EndOfStream};
1010
11pub fn rescanMac(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp) RescanMacError!void {11pub fn rescanMac(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp) RescanMacError!void {
12 cb.bytes.clearRetainingCapacity();12 cb.bytes.clearRetainingCapacity();
lib/std/crypto/benchmark.zig+5-3
...@@ -1,10 +1,12 @@...@@ -1,10 +1,12 @@
1// zig run -O ReleaseFast --zig-lib-dir ../.. benchmark.zig1// zig run -O ReleaseFast --zig-lib-dir ../.. benchmark.zig
22
3const std = @import("std");
4const builtin = @import("builtin");3const builtin = @import("builtin");
4
5const std = @import("std");
6const Io = std.Io;
5const mem = std.mem;7const mem = std.mem;
6const time = std.time;8const time = std.time;
7const Timer = time.Timer;9const Timer = std.time.Timer;
8const crypto = std.crypto;10const crypto = std.crypto;
911
10const KiB = 1024;12const KiB = 1024;
...@@ -504,7 +506,7 @@ fn mode(comptime x: comptime_int) comptime_int {...@@ -504,7 +506,7 @@ fn mode(comptime x: comptime_int) comptime_int {
504pub fn main() !void {506pub fn main() !void {
505 // Size of buffer is about size of printed message.507 // Size of buffer is about size of printed message.
506 var stdout_buffer: [0x100]u8 = undefined;508 var stdout_buffer: [0x100]u8 = undefined;
507 var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);509 var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
508 const stdout = &stdout_writer.interface;510 const stdout = &stdout_writer.interface;
509511
510 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);512 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
lib/std/debug.zig+3-3
...@@ -8,7 +8,7 @@ const posix = std.posix;...@@ -8,7 +8,7 @@ const posix = std.posix;
8const fs = std.fs;8const fs = std.fs;
9const testing = std.testing;9const testing = std.testing;
10const Allocator = mem.Allocator;10const Allocator = mem.Allocator;
11const File = std.fs.File;11const File = std.Io.File;
12const windows = std.os.windows;12const windows = std.os.windows;
1313
14const builtin = @import("builtin");14const builtin = @import("builtin");
...@@ -575,7 +575,7 @@ pub fn defaultPanic(...@@ -575,7 +575,7 @@ pub fn defaultPanic(
575 // A panic happened while trying to print a previous panic message.575 // A panic happened while trying to print a previous panic message.
576 // We're still holding the mutex but that's fine as we're going to576 // We're still holding the mutex but that's fine as we're going to
577 // call abort().577 // call abort().
578 fs.File.stderr().writeAll("aborting due to recursive panic\n") catch {};578 File.stderr().writeAll("aborting due to recursive panic\n") catch {};
579 },579 },
580 else => {}, // Panicked while printing the recursive panic message.580 else => {}, // Panicked while printing the recursive panic message.
581 }581 }
...@@ -1596,7 +1596,7 @@ pub fn defaultHandleSegfault(addr: ?usize, name: []const u8, opt_ctx: ?CpuContex...@@ -1596,7 +1596,7 @@ pub fn defaultHandleSegfault(addr: ?usize, name: []const u8, opt_ctx: ?CpuContex
1596 // A segfault happened while trying to print a previous panic message.1596 // A segfault happened while trying to print a previous panic message.
1597 // We're still holding the mutex but that's fine as we're going to1597 // We're still holding the mutex but that's fine as we're going to
1598 // call abort().1598 // call abort().
1599 fs.File.stderr().writeAll("aborting due to recursive panic\n") catch {};1599 File.stderr().writeAll("aborting due to recursive panic\n") catch {};
1600 },1600 },
1601 else => {}, // Panicked while printing the recursive panic message.1601 else => {}, // Panicked while printing the recursive panic message.
1602 }1602 }
lib/std/debug/ElfFile.zig+2-2
...@@ -123,7 +123,7 @@ pub const LoadError = error{...@@ -123,7 +123,7 @@ pub const LoadError = error{
123123
124pub fn load(124pub fn load(
125 gpa: Allocator,125 gpa: Allocator,
126 elf_file: std.fs.File,126 elf_file: Io.File,
127 opt_build_id: ?[]const u8,127 opt_build_id: ?[]const u8,
128 di_search_paths: *const DebugInfoSearchPaths,128 di_search_paths: *const DebugInfoSearchPaths,
129) LoadError!ElfFile {129) LoadError!ElfFile {
...@@ -423,7 +423,7 @@ const LoadInnerResult = struct {...@@ -423,7 +423,7 @@ const LoadInnerResult = struct {
423};423};
424fn loadInner(424fn loadInner(
425 arena: Allocator,425 arena: Allocator,
426 elf_file: std.fs.File,426 elf_file: Io.File,
427 opt_crc: ?u32,427 opt_crc: ?u32,
428) (LoadError || error{ CrcMismatch, Streaming, Canceled })!LoadInnerResult {428) (LoadError || error{ CrcMismatch, Streaming, Canceled })!LoadInnerResult {
429 const mapped_mem: []align(std.heap.page_size_min) const u8 = mapped: {429 const mapped_mem: []align(std.heap.page_size_min) const u8 = mapped: {
lib/std/debug/Info.zig+1-1
...@@ -27,7 +27,7 @@ coverage: *Coverage,...@@ -27,7 +27,7 @@ coverage: *Coverage,
27pub const LoadError = error{27pub const LoadError = error{
28 MissingDebugInfo,28 MissingDebugInfo,
29 UnsupportedDebugInfo,29 UnsupportedDebugInfo,
30} || std.fs.File.OpenError || ElfFile.LoadError || MachOFile.Error || std.debug.Dwarf.ScanError;30} || Io.File.OpenError || ElfFile.LoadError || MachOFile.Error || std.debug.Dwarf.ScanError;
3131
32pub fn load(32pub fn load(
33 gpa: Allocator,33 gpa: Allocator,
lib/std/debug/Pdb.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const File = std.fs.File;2const File = std.Io.File;
3const Allocator = std.mem.Allocator;3const Allocator = std.mem.Allocator;
4const pdb = std.pdb;4const pdb = std.pdb;
5const assert = std.debug.assert;5const assert = std.debug.assert;
lib/std/debug/SelfInfo/Windows.zig+1-1
...@@ -204,7 +204,7 @@ const Module = struct {...@@ -204,7 +204,7 @@ const Module = struct {
204 coff_section_headers: []coff.SectionHeader,204 coff_section_headers: []coff.SectionHeader,
205205
206 const MappedFile = struct {206 const MappedFile = struct {
207 file: fs.File,207 file: Io.File,
208 section_handle: windows.HANDLE,208 section_handle: windows.HANDLE,
209 section_view: []const u8,209 section_view: []const u8,
210 fn deinit(mf: *const MappedFile, io: Io) void {210 fn deinit(mf: *const MappedFile, io: Io) void {
lib/std/debug/simple_panic.zig+1-1
...@@ -15,7 +15,7 @@ pub fn call(msg: []const u8, ra: ?usize) noreturn {...@@ -15,7 +15,7 @@ pub fn call(msg: []const u8, ra: ?usize) noreturn {
15 @branchHint(.cold);15 @branchHint(.cold);
16 _ = ra;16 _ = ra;
17 std.debug.lockStdErr();17 std.debug.lockStdErr();
18 const stderr: std.fs.File = .stderr();18 const stderr: std.Io.File = .stderr();
19 stderr.writeAll(msg) catch {};19 stderr.writeAll(msg) catch {};
20 @trap();20 @trap();
21}21}
lib/std/dynamic_library.zig+1-1
...@@ -225,7 +225,7 @@ pub const ElfDynLib = struct {...@@ -225,7 +225,7 @@ pub const ElfDynLib = struct {
225 const fd = try resolveFromName(io, path);225 const fd = try resolveFromName(io, path);
226 defer posix.close(fd);226 defer posix.close(fd);
227227
228 const file: std.fs.File = .{ .handle = fd };228 const file: Io.File = .{ .handle = fd };
229 const stat = try file.stat();229 const stat = try file.stat();
230 const size = std.math.cast(usize, stat.size) orelse return error.FileTooBig;230 const size = std.math.cast(usize, stat.size) orelse return error.FileTooBig;
231231
lib/std/fs/test.zig+4-4
...@@ -12,7 +12,7 @@ const posix = std.posix;...@@ -12,7 +12,7 @@ const posix = std.posix;
1212
13const ArenaAllocator = std.heap.ArenaAllocator;13const ArenaAllocator = std.heap.ArenaAllocator;
14const Dir = std.fs.Dir;14const Dir = std.fs.Dir;
15const File = std.fs.File;15const File = std.Io.File;
16const tmpDir = testing.tmpDir;16const tmpDir = testing.tmpDir;
17const SymLinkFlags = std.fs.Dir.SymLinkFlags;17const SymLinkFlags = std.fs.Dir.SymLinkFlags;
1818
...@@ -2231,7 +2231,7 @@ test "read file non vectored" {...@@ -2231,7 +2231,7 @@ test "read file non vectored" {
2231 const file = try tmp_dir.dir.createFile("input.txt", .{ .read = true });2231 const file = try tmp_dir.dir.createFile("input.txt", .{ .read = true });
2232 defer file.close(io);2232 defer file.close(io);
2233 {2233 {
2234 var file_writer: std.fs.File.Writer = .init(file, &.{});2234 var file_writer: File.Writer = .init(file, &.{});
2235 try file_writer.interface.writeAll(contents);2235 try file_writer.interface.writeAll(contents);
2236 try file_writer.interface.flush();2236 try file_writer.interface.flush();
2237 }2237 }
...@@ -2263,7 +2263,7 @@ test "seek keeping partial buffer" {...@@ -2263,7 +2263,7 @@ test "seek keeping partial buffer" {
2263 const file = try tmp_dir.dir.createFile("input.txt", .{ .read = true });2263 const file = try tmp_dir.dir.createFile("input.txt", .{ .read = true });
2264 defer file.close(io);2264 defer file.close(io);
2265 {2265 {
2266 var file_writer: std.fs.File.Writer = .init(file, &.{});2266 var file_writer: File.Writer = .init(file, &.{});
2267 try file_writer.interface.writeAll(contents);2267 try file_writer.interface.writeAll(contents);
2268 try file_writer.interface.flush();2268 try file_writer.interface.flush();
2269 }2269 }
...@@ -2325,7 +2325,7 @@ test "seekTo flushes buffered data" {...@@ -2325,7 +2325,7 @@ test "seekTo flushes buffered data" {
2325 defer file.close(io);2325 defer file.close(io);
2326 {2326 {
2327 var buf: [16]u8 = undefined;2327 var buf: [16]u8 = undefined;
2328 var file_writer = std.fs.File.writer(file, &buf);2328 var file_writer = File.writer(file, &buf);
23292329
2330 try file_writer.interface.writeAll(contents);2330 try file_writer.interface.writeAll(contents);
2331 try file_writer.seekTo(8);2331 try file_writer.seekTo(8);
lib/std/hash/benchmark.zig+3-2
...@@ -1,7 +1,8 @@...@@ -1,7 +1,8 @@
1// zig run -O ReleaseFast --zig-lib-dir ../.. benchmark.zig1// zig run -O ReleaseFast --zig-lib-dir ../.. benchmark.zig
2const builtin = @import("builtin");
23
3const std = @import("std");4const std = @import("std");
4const builtin = @import("builtin");5const Io = std.Io;
5const time = std.time;6const time = std.time;
6const Timer = time.Timer;7const Timer = time.Timer;
7const hash = std.hash;8const hash = std.hash;
...@@ -354,7 +355,7 @@ fn mode(comptime x: comptime_int) comptime_int {...@@ -354,7 +355,7 @@ fn mode(comptime x: comptime_int) comptime_int {
354355
355pub fn main() !void {356pub fn main() !void {
356 var stdout_buffer: [0x100]u8 = undefined;357 var stdout_buffer: [0x100]u8 = undefined;
357 var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);358 var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
358 const stdout = &stdout_writer.interface;359 const stdout = &stdout_writer.interface;
359360
360 var buffer: [1024]u8 = undefined;361 var buffer: [1024]u8 = undefined;
lib/std/http.zig+1-1
...@@ -2,7 +2,7 @@ const builtin = @import("builtin");...@@ -2,7 +2,7 @@ const builtin = @import("builtin");
2const std = @import("std.zig");2const std = @import("std.zig");
3const assert = std.debug.assert;3const assert = std.debug.assert;
4const Writer = std.Io.Writer;4const Writer = std.Io.Writer;
5const File = std.fs.File;5const File = std.Io.File;
66
7pub const Client = @import("http/Client.zig");7pub const Client = @import("http/Client.zig");
8pub const Server = @import("http/Server.zig");8pub const Server = @import("http/Server.zig");
lib/std/pdb.zig+1-1
...@@ -12,7 +12,7 @@ const math = std.math;...@@ -12,7 +12,7 @@ const math = std.math;
12const mem = std.mem;12const mem = std.mem;
13const coff = std.coff;13const coff = std.coff;
14const fs = std.fs;14const fs = std.fs;
15const File = std.fs.File;15const File = std.Io.File;
16const debug = std.debug;16const debug = std.debug;
1717
18const ArrayList = std.ArrayList;18const ArrayList = std.ArrayList;
lib/std/posix/test.zig+9-9
...@@ -1,20 +1,20 @@...@@ -1,20 +1,20 @@
1const builtin = @import("builtin");
2const native_os = builtin.target.os.tag;
3
1const std = @import("../std.zig");4const std = @import("../std.zig");
5const Io = std.Io;
2const posix = std.posix;6const posix = std.posix;
3const testing = std.testing;7const testing = std.testing;
4const expect = testing.expect;8const expect = std.testing.expect;
5const expectEqual = testing.expectEqual;9const expectEqual = std.testing.expectEqual;
6const expectError = testing.expectError;10const expectError = std.testing.expectError;
7const fs = std.fs;11const fs = std.fs;
8const mem = std.mem;12const mem = std.mem;
9const elf = std.elf;13const elf = std.elf;
10const linux = std.os.linux;14const linux = std.os.linux;
11
12const a = std.testing.allocator;15const a = std.testing.allocator;
13
14const builtin = @import("builtin");
15const AtomicRmwOp = std.builtin.AtomicRmwOp;16const AtomicRmwOp = std.builtin.AtomicRmwOp;
16const AtomicOrder = std.builtin.AtomicOrder;17const AtomicOrder = std.builtin.AtomicOrder;
17const native_os = builtin.target.os.tag;
18const tmpDir = std.testing.tmpDir;18const tmpDir = std.testing.tmpDir;
19const AT = posix.AT;19const AT = posix.AT;
2020
...@@ -663,14 +663,14 @@ test "dup & dup2" {...@@ -663,14 +663,14 @@ test "dup & dup2" {
663 var file = try tmp.dir.createFile("os_dup_test", .{});663 var file = try tmp.dir.createFile("os_dup_test", .{});
664 defer file.close(io);664 defer file.close(io);
665665
666 var duped = std.fs.File{ .handle = try posix.dup(file.handle) };666 var duped = Io.File{ .handle = try posix.dup(file.handle) };
667 defer duped.close(io);667 defer duped.close(io);
668 try duped.writeAll("dup");668 try duped.writeAll("dup");
669669
670 // Tests aren't run in parallel so using the next fd shouldn't be an issue.670 // Tests aren't run in parallel so using the next fd shouldn't be an issue.
671 const new_fd = duped.handle + 1;671 const new_fd = duped.handle + 1;
672 try posix.dup2(file.handle, new_fd);672 try posix.dup2(file.handle, new_fd);
673 var dup2ed = std.fs.File{ .handle = new_fd };673 var dup2ed = Io.File{ .handle = new_fd };
674 defer dup2ed.close(io);674 defer dup2ed.close(io);
675 try dup2ed.writeAll("dup2");675 try dup2ed.writeAll("dup2");
676 }676 }
lib/std/process/Child.zig+2-2
...@@ -8,7 +8,7 @@ const Io = std.Io;...@@ -8,7 +8,7 @@ const Io = std.Io;
8const unicode = std.unicode;8const unicode = std.unicode;
9const fs = std.fs;9const fs = std.fs;
10const process = std.process;10const process = std.process;
11const File = std.fs.File;11const File = std.Io.File;
12const windows = std.os.windows;12const windows = std.os.windows;
13const linux = std.os.linux;13const linux = std.os.linux;
14const posix = std.posix;14const posix = std.posix;
...@@ -1055,7 +1055,7 @@ fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn {...@@ -1055,7 +1055,7 @@ fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn {
10551055
1056fn writeIntFd(fd: i32, value: ErrInt) !void {1056fn writeIntFd(fd: i32, value: ErrInt) !void {
1057 var buffer: [8]u8 = undefined;1057 var buffer: [8]u8 = undefined;
1058 var fw: std.fs.File.Writer = .initStreaming(.{ .handle = fd }, &buffer);1058 var fw: File.Writer = .initStreaming(.{ .handle = fd }, &buffer);
1059 fw.interface.writeInt(u64, value, .little) catch unreachable;1059 fw.interface.writeInt(u64, value, .little) catch unreachable;
1060 fw.interface.flush() catch return error.SystemResources;1060 fw.interface.flush() catch return error.SystemResources;
1061}1061}
lib/std/unicode/throughput_test.zig+3-3
...@@ -1,8 +1,8 @@...@@ -1,8 +1,8 @@
1const std = @import("std");1const std = @import("std");
2const Io = std.Io;
2const time = std.time;3const time = std.time;
3const unicode = std.unicode;4const unicode = std.unicode;
45const Timer = std.time.Timer;
5const Timer = time.Timer;
66
7const N = 1_000_000;7const N = 1_000_000;
88
...@@ -41,7 +41,7 @@ fn benchmarkCodepointCount(buf: []const u8) !ResultCount {...@@ -41,7 +41,7 @@ fn benchmarkCodepointCount(buf: []const u8) !ResultCount {
41pub fn main() !void {41pub fn main() !void {
42 // Size of buffer is about size of printed message.42 // Size of buffer is about size of printed message.
43 var stdout_buffer: [0x100]u8 = undefined;43 var stdout_buffer: [0x100]u8 = undefined;
44 var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);44 var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
45 const stdout = &stdout_writer.interface;45 const stdout = &stdout_writer.interface;
4646
47 try stdout.print("short ASCII strings\n", .{});47 try stdout.print("short ASCII strings\n", .{});
lib/std/zig/Zir.zig+4-4
...@@ -11,9 +11,11 @@...@@ -11,9 +11,11 @@
11//! * In the future, possibly inline assembly, which needs to get parsed and11//! * In the future, possibly inline assembly, which needs to get parsed and
12//! handled by the codegen backend, and errors reported there. However for now,12//! handled by the codegen backend, and errors reported there. However for now,
13//! inline assembly is not an exception.13//! inline assembly is not an exception.
14const Zir = @This();
15const builtin = @import("builtin");
1416
15const std = @import("std");17const std = @import("std");
16const builtin = @import("builtin");18const Io = std.Io;
17const mem = std.mem;19const mem = std.mem;
18const Allocator = std.mem.Allocator;20const Allocator = std.mem.Allocator;
19const assert = std.debug.assert;21const assert = std.debug.assert;
...@@ -21,8 +23,6 @@ const BigIntConst = std.math.big.int.Const;...@@ -21,8 +23,6 @@ const BigIntConst = std.math.big.int.Const;
21const BigIntMutable = std.math.big.int.Mutable;23const BigIntMutable = std.math.big.int.Mutable;
22const Ast = std.zig.Ast;24const Ast = std.zig.Ast;
2325
24const Zir = @This();
25
26instructions: std.MultiArrayList(Inst).Slice,26instructions: std.MultiArrayList(Inst).Slice,
27/// In order to store references to strings in fewer bytes, we copy all27/// In order to store references to strings in fewer bytes, we copy all
28/// string bytes into here. String bytes can be null. It is up to whomever28/// string bytes into here. String bytes can be null. It is up to whomever
...@@ -45,7 +45,7 @@ pub const Header = extern struct {...@@ -45,7 +45,7 @@ pub const Header = extern struct {
45 /// it's essentially free to have a zero field here and makes the warning go away,45 /// it's essentially free to have a zero field here and makes the warning go away,
46 /// making it more likely that following Valgrind warnings will be taken seriously.46 /// making it more likely that following Valgrind warnings will be taken seriously.
47 unused: u32 = 0,47 unused: u32 = 0,
48 stat_inode: std.fs.File.INode,48 stat_inode: Io.File.INode,
49 stat_size: u64,49 stat_size: u64,
50 stat_mtime: i128,50 stat_mtime: i128,
51};51};
lib/std/zig/Zoir.zig+8-7
...@@ -1,6 +1,13 @@...@@ -1,6 +1,13 @@
1//! Zig Object Intermediate Representation.1//! Zig Object Intermediate Representation.
2//! Simplified AST for the ZON (Zig Object Notation) format.2//! Simplified AST for the ZON (Zig Object Notation) format.
3//! `ZonGen` converts `Ast` to `Zoir`.3//! `ZonGen` converts `Ast` to `Zoir`.
4const Zoir = @This();
5
6const std = @import("std");
7const Io = std.Io;
8const assert = std.debug.assert;
9const Allocator = std.mem.Allocator;
10const Ast = std.zig.Ast;
411
5nodes: std.MultiArrayList(Node.Repr).Slice,12nodes: std.MultiArrayList(Node.Repr).Slice,
6extra: []u32,13extra: []u32,
...@@ -25,7 +32,7 @@ pub const Header = extern struct {...@@ -25,7 +32,7 @@ pub const Header = extern struct {
25 /// making it more likely that following Valgrind warnings will be taken seriously.32 /// making it more likely that following Valgrind warnings will be taken seriously.
26 unused: u64 = 0,33 unused: u64 = 0,
2734
28 stat_inode: std.fs.File.INode,35 stat_inode: Io.File.INode,
29 stat_size: u64,36 stat_size: u64,
30 stat_mtime: i128,37 stat_mtime: i128,
3138
...@@ -254,9 +261,3 @@ pub const CompileError = extern struct {...@@ -254,9 +261,3 @@ pub const CompileError = extern struct {
254 assert(std.meta.hasUniqueRepresentation(Note));261 assert(std.meta.hasUniqueRepresentation(Note));
255 }262 }
256};263};
257
258const std = @import("std");
259const assert = std.debug.assert;
260const Allocator = std.mem.Allocator;
261const Ast = std.zig.Ast;
262const Zoir = @This();
lib/std/zig/llvm/Builder.zig+2-2
...@@ -9578,7 +9578,7 @@ pub fn asmValue(...@@ -9578,7 +9578,7 @@ pub fn asmValue(
95789578
9579pub fn dump(b: *Builder) void {9579pub fn dump(b: *Builder) void {
9580 var buffer: [4000]u8 = undefined;9580 var buffer: [4000]u8 = undefined;
9581 const stderr: std.fs.File = .stderr();9581 const stderr: Io.File = .stderr();
9582 b.printToFile(stderr, &buffer) catch {};9582 b.printToFile(stderr, &buffer) catch {};
9583}9583}
95849584
...@@ -9589,7 +9589,7 @@ pub fn printToFilePath(b: *Builder, io: Io, dir: std.fs.Dir, path: []const u8) !...@@ -9589,7 +9589,7 @@ pub fn printToFilePath(b: *Builder, io: Io, dir: std.fs.Dir, path: []const u8) !
9589 try b.printToFile(io, file, &buffer);9589 try b.printToFile(io, file, &buffer);
9590}9590}
95919591
9592pub fn printToFile(b: *Builder, file: std.fs.File, buffer: []u8) !void {9592pub fn printToFile(b: *Builder, file: Io.File, buffer: []u8) !void {
9593 var fw = file.writer(buffer);9593 var fw = file.writer(buffer);
9594 try print(b, &fw.interface);9594 try print(b, &fw.interface);
9595 try fw.interface.flush();9595 try fw.interface.flush();
lib/std/zig/perf_test.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const Io = std.Io;
2const mem = std.mem;3const mem = std.mem;
3const Tokenizer = std.zig.Tokenizer;4const Tokenizer = std.zig.Tokenizer;
4const fmtIntSizeBin = std.fmt.fmtIntSizeBin;5const fmtIntSizeBin = std.fmt.fmtIntSizeBin;
...@@ -22,7 +23,7 @@ pub fn main() !void {...@@ -22,7 +23,7 @@ pub fn main() !void {
22 const bytes_per_sec = @as(u64, @intFromFloat(@floor(bytes_per_sec_float)));23 const bytes_per_sec = @as(u64, @intFromFloat(@floor(bytes_per_sec_float)));
2324
24 var stdout_buffer: [1024]u8 = undefined;25 var stdout_buffer: [1024]u8 = undefined;
25 var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);26 var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
26 const stdout = &stdout_writer.interface;27 const stdout = &stdout_writer.interface;
27 try stdout.print("parsing speed: {Bi:.2}/s, {Bi:.2} used \n", .{ bytes_per_sec, memory_used });28 try stdout.print("parsing speed: {Bi:.2}/s, {Bi:.2} used \n", .{ bytes_per_sec, memory_used });
28 try stdout.flush();29 try stdout.flush();
lib/std/zip.zig+3-2
...@@ -4,9 +4,10 @@...@@ -4,9 +4,10 @@
4//! Note that this file uses the abbreviation "cd" for "central directory"4//! Note that this file uses the abbreviation "cd" for "central directory"
55
6const builtin = @import("builtin");6const builtin = @import("builtin");
7const std = @import("std");
8const File = std.fs.File;
9const is_le = builtin.target.cpu.arch.endian() == .little;7const is_le = builtin.target.cpu.arch.endian() == .little;
8
9const std = @import("std");
10const File = std.Io.File;
10const Writer = std.Io.Writer;11const Writer = std.Io.Writer;
11const Reader = std.Io.Reader;12const Reader = std.Io.Reader;
12const flate = std.compress.flate;13const flate = std.compress.flate;
src/Compilation.zig+2-2
...@@ -5325,7 +5325,7 @@ fn docsCopyModule(...@@ -5325,7 +5325,7 @@ fn docsCopyModule(
5325 comp: *Compilation,5325 comp: *Compilation,
5326 module: *Package.Module,5326 module: *Package.Module,
5327 name: []const u8,5327 name: []const u8,
5328 tar_file_writer: *fs.File.Writer,5328 tar_file_writer: *Io.File.Writer,
5329) !void {5329) !void {
5330 const io = comp.io;5330 const io = comp.io;
5331 const root = module.root;5331 const root = module.root;
...@@ -5361,7 +5361,7 @@ fn docsCopyModule(...@@ -5361,7 +5361,7 @@ fn docsCopyModule(
5361 };5361 };
5362 defer file.close(io);5362 defer file.close(io);
5363 const stat = try file.stat();5363 const stat = try file.stat();
5364 var file_reader: fs.File.Reader = .initSize(file.adaptToNewApi(), io, &buffer, stat.size);5364 var file_reader: Io.File.Reader = .initSize(file.adaptToNewApi(), io, &buffer, stat.size);
53655365
5366 archiver.writeFileTimestamp(entry.path, &file_reader, stat.mtime) catch |err| {5366 archiver.writeFileTimestamp(entry.path, &file_reader, stat.mtime) catch |err| {
5367 return comp.lockAndSetMiscFailure(.docs_copy, "unable to archive {f}{s}: {t}", .{5367 return comp.lockAndSetMiscFailure(.docs_copy, "unable to archive {f}{s}: {t}", .{
src/Package/Fetch.zig+8-8
...@@ -882,7 +882,7 @@ fn fail(f: *Fetch, msg_tok: std.zig.Ast.TokenIndex, msg_str: u32) RunError {...@@ -882,7 +882,7 @@ fn fail(f: *Fetch, msg_tok: std.zig.Ast.TokenIndex, msg_str: u32) RunError {
882}882}
883883
884const Resource = union(enum) {884const Resource = union(enum) {
885 file: fs.File.Reader,885 file: Io.File.Reader,
886 http_request: HttpRequest,886 http_request: HttpRequest,
887 git: Git,887 git: Git,
888 dir: Io.Dir,888 dir: Io.Dir,
...@@ -1653,7 +1653,7 @@ fn computeHash(f: *Fetch, pkg_path: Cache.Path, filter: Filter) RunError!Compute...@@ -1653,7 +1653,7 @@ fn computeHash(f: *Fetch, pkg_path: Cache.Path, filter: Filter) RunError!Compute
16531653
1654fn dumpHashInfo(all_files: []const *const HashedFile) !void {1654fn dumpHashInfo(all_files: []const *const HashedFile) !void {
1655 var stdout_buffer: [1024]u8 = undefined;1655 var stdout_buffer: [1024]u8 = undefined;
1656 var stdout_writer: fs.File.Writer = .initStreaming(.stdout(), &stdout_buffer);1656 var stdout_writer: Io.File.Writer = .initStreaming(.stdout(), &stdout_buffer);
1657 const w = &stdout_writer.interface;1657 const w = &stdout_writer.interface;
1658 for (all_files) |hashed_file| {1658 for (all_files) |hashed_file| {
1659 try w.print("{t}: {x}: {s}\n", .{ hashed_file.kind, &hashed_file.hash, hashed_file.normalized_path });1659 try w.print("{t}: {x}: {s}\n", .{ hashed_file.kind, &hashed_file.hash, hashed_file.normalized_path });
...@@ -1712,11 +1712,11 @@ fn deleteFileFallible(dir: Io.Dir, deleted_file: *DeletedFile) DeletedFile.Error...@@ -1712,11 +1712,11 @@ fn deleteFileFallible(dir: Io.Dir, deleted_file: *DeletedFile) DeletedFile.Error
1712 try dir.deleteFile(deleted_file.fs_path);1712 try dir.deleteFile(deleted_file.fs_path);
1713}1713}
17141714
1715fn setExecutable(file: fs.File) !void {1715fn setExecutable(file: Io.File) !void {
1716 if (!std.fs.has_executable_bit) return;1716 if (!std.fs.has_executable_bit) return;
17171717
1718 const S = std.posix.S;1718 const S = std.posix.S;
1719 const mode = fs.File.default_mode | S.IXUSR | S.IXGRP | S.IXOTH;1719 const mode = Io.File.default_mode | S.IXUSR | S.IXGRP | S.IXOTH;
1720 try file.chmod(mode);1720 try file.chmod(mode);
1721}1721}
17221722
...@@ -1738,10 +1738,10 @@ const HashedFile = struct {...@@ -1738,10 +1738,10 @@ const HashedFile = struct {
1738 size: u64,1738 size: u64,
17391739
1740 const Error =1740 const Error =
1741 fs.File.OpenError ||1741 Io.File.OpenError ||
1742 fs.File.ReadError ||1742 Io.File.ReadError ||
1743 fs.File.StatError ||1743 Io.File.StatError ||
1744 fs.File.ChmodError ||1744 Io.File.ChmodError ||
1745 Io.Dir.ReadLinkError;1745 Io.Dir.ReadLinkError;
17461746
1747 const Kind = enum { file, link };1747 const Kind = enum { file, link };
src/Package/Fetch/git.zig+11-11
...@@ -198,8 +198,8 @@ pub const Repository = struct {...@@ -198,8 +198,8 @@ pub const Repository = struct {
198 repo: *Repository,198 repo: *Repository,
199 allocator: Allocator,199 allocator: Allocator,
200 format: Oid.Format,200 format: Oid.Format,
201 pack_file: *std.fs.File.Reader,201 pack_file: *Io.File.Reader,
202 index_file: *std.fs.File.Reader,202 index_file: *Io.File.Reader,
203 ) !void {203 ) !void {
204 repo.* = .{ .odb = undefined };204 repo.* = .{ .odb = undefined };
205 try repo.odb.init(allocator, format, pack_file, index_file);205 try repo.odb.init(allocator, format, pack_file, index_file);
...@@ -372,9 +372,9 @@ pub const Repository = struct {...@@ -372,9 +372,9 @@ pub const Repository = struct {
372/// [pack-format](https://git-scm.com/docs/pack-format).372/// [pack-format](https://git-scm.com/docs/pack-format).
373const Odb = struct {373const Odb = struct {
374 format: Oid.Format,374 format: Oid.Format,
375 pack_file: *std.fs.File.Reader,375 pack_file: *Io.File.Reader,
376 index_header: IndexHeader,376 index_header: IndexHeader,
377 index_file: *std.fs.File.Reader,377 index_file: *Io.File.Reader,
378 cache: ObjectCache = .{},378 cache: ObjectCache = .{},
379 allocator: Allocator,379 allocator: Allocator,
380380
...@@ -383,8 +383,8 @@ const Odb = struct {...@@ -383,8 +383,8 @@ const Odb = struct {
383 odb: *Odb,383 odb: *Odb,
384 allocator: Allocator,384 allocator: Allocator,
385 format: Oid.Format,385 format: Oid.Format,
386 pack_file: *std.fs.File.Reader,386 pack_file: *Io.File.Reader,
387 index_file: *std.fs.File.Reader,387 index_file: *Io.File.Reader,
388 ) !void {388 ) !void {
389 try pack_file.seekTo(0);389 try pack_file.seekTo(0);
390 try index_file.seekTo(0);390 try index_file.seekTo(0);
...@@ -1272,8 +1272,8 @@ const IndexEntry = struct {...@@ -1272,8 +1272,8 @@ const IndexEntry = struct {
1272pub fn indexPack(1272pub fn indexPack(
1273 allocator: Allocator,1273 allocator: Allocator,
1274 format: Oid.Format,1274 format: Oid.Format,
1275 pack: *std.fs.File.Reader,1275 pack: *Io.File.Reader,
1276 index_writer: *std.fs.File.Writer,1276 index_writer: *Io.File.Writer,
1277) !void {1277) !void {
1278 try pack.seekTo(0);1278 try pack.seekTo(0);
12791279
...@@ -1372,7 +1372,7 @@ pub fn indexPack(...@@ -1372,7 +1372,7 @@ pub fn indexPack(
1372fn indexPackFirstPass(1372fn indexPackFirstPass(
1373 allocator: Allocator,1373 allocator: Allocator,
1374 format: Oid.Format,1374 format: Oid.Format,
1375 pack: *std.fs.File.Reader,1375 pack: *Io.File.Reader,
1376 index_entries: *std.AutoHashMapUnmanaged(Oid, IndexEntry),1376 index_entries: *std.AutoHashMapUnmanaged(Oid, IndexEntry),
1377 pending_deltas: *std.ArrayList(IndexEntry),1377 pending_deltas: *std.ArrayList(IndexEntry),
1378) !Oid {1378) !Oid {
...@@ -1425,7 +1425,7 @@ fn indexPackFirstPass(...@@ -1425,7 +1425,7 @@ fn indexPackFirstPass(
1425fn indexPackHashDelta(1425fn indexPackHashDelta(
1426 allocator: Allocator,1426 allocator: Allocator,
1427 format: Oid.Format,1427 format: Oid.Format,
1428 pack: *std.fs.File.Reader,1428 pack: *Io.File.Reader,
1429 delta: IndexEntry,1429 delta: IndexEntry,
1430 index_entries: std.AutoHashMapUnmanaged(Oid, IndexEntry),1430 index_entries: std.AutoHashMapUnmanaged(Oid, IndexEntry),
1431 cache: *ObjectCache,1431 cache: *ObjectCache,
...@@ -1477,7 +1477,7 @@ fn indexPackHashDelta(...@@ -1477,7 +1477,7 @@ fn indexPackHashDelta(
1477fn resolveDeltaChain(1477fn resolveDeltaChain(
1478 allocator: Allocator,1478 allocator: Allocator,
1479 format: Oid.Format,1479 format: Oid.Format,
1480 pack: *std.fs.File.Reader,1480 pack: *Io.File.Reader,
1481 base_object: Object,1481 base_object: Object,
1482 delta_offsets: []const u64,1482 delta_offsets: []const u64,
1483 cache: *ObjectCache,1483 cache: *ObjectCache,
src/Zcu.zig+4-4
...@@ -1200,7 +1200,7 @@ pub const EmbedFile = struct {...@@ -1200,7 +1200,7 @@ pub const EmbedFile = struct {
1200 /// `.none` means the file was not loaded, so `stat` is undefined.1200 /// `.none` means the file was not loaded, so `stat` is undefined.
1201 val: InternPool.Index,1201 val: InternPool.Index,
1202 /// If this is `null` and `val` is `.none`, the file has never been loaded.1202 /// If this is `null` and `val` is `.none`, the file has never been loaded.
1203 err: ?(std.fs.File.OpenError || std.fs.File.StatError || std.fs.File.ReadError || error{UnexpectedEof}),1203 err: ?(Io.File.OpenError || Io.File.StatError || Io.File.ReadError || error{UnexpectedEof}),
1204 stat: Cache.File.Stat,1204 stat: Cache.File.Stat,
12051205
1206 pub const Index = enum(u32) {1206 pub const Index = enum(u32) {
...@@ -2927,7 +2927,7 @@ comptime {...@@ -2927,7 +2927,7 @@ comptime {
2927 }2927 }
2928}2928}
29292929
2930pub fn loadZirCache(gpa: Allocator, io: Io, cache_file: std.fs.File) !Zir {2930pub fn loadZirCache(gpa: Allocator, io: Io, cache_file: Io.File) !Zir {
2931 var buffer: [2000]u8 = undefined;2931 var buffer: [2000]u8 = undefined;
2932 var file_reader = cache_file.reader(io, &buffer);2932 var file_reader = cache_file.reader(io, &buffer);
2933 return result: {2933 return result: {
...@@ -2986,7 +2986,7 @@ pub fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_br: *Io.Reader...@@ -2986,7 +2986,7 @@ pub fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_br: *Io.Reader
2986 return zir;2986 return zir;
2987}2987}
29882988
2989pub fn saveZirCache(gpa: Allocator, cache_file: std.fs.File, stat: std.fs.File.Stat, zir: Zir) (std.fs.File.WriteError || Allocator.Error)!void {2989pub fn saveZirCache(gpa: Allocator, cache_file: Io.File, stat: Io.File.Stat, zir: Zir) (Io.File.WriteError || Allocator.Error)!void {
2990 const safety_buffer = if (data_has_safety_tag)2990 const safety_buffer = if (data_has_safety_tag)
2991 try gpa.alloc([8]u8, zir.instructions.len)2991 try gpa.alloc([8]u8, zir.instructions.len)
2992 else2992 else
...@@ -3026,7 +3026,7 @@ pub fn saveZirCache(gpa: Allocator, cache_file: std.fs.File, stat: std.fs.File.S...@@ -3026,7 +3026,7 @@ pub fn saveZirCache(gpa: Allocator, cache_file: std.fs.File, stat: std.fs.File.S
3026 };3026 };
3027}3027}
30283028
3029pub fn saveZoirCache(cache_file: std.fs.File, stat: std.fs.File.Stat, zoir: Zoir) std.fs.File.WriteError!void {3029pub fn saveZoirCache(cache_file: Io.File, stat: Io.File.Stat, zoir: Zoir) Io.File.WriteError!void {
3030 const header: Zoir.Header = .{3030 const header: Zoir.Header = .{
3031 .nodes_len = @intCast(zoir.nodes.len),3031 .nodes_len = @intCast(zoir.nodes.len),
3032 .extra_len = @intCast(zoir.extra.len),3032 .extra_len = @intCast(zoir.extra.len),
src/Zcu/PerThread.zig+3-3
...@@ -118,7 +118,7 @@ pub fn updateFile(...@@ -118,7 +118,7 @@ pub fn updateFile(
118 const zir_dir = cache_directory.handle;118 const zir_dir = cache_directory.handle;
119119
120 // Determine whether we need to reload the file from disk and redo parsing and AstGen.120 // Determine whether we need to reload the file from disk and redo parsing and AstGen.
121 var lock: std.fs.File.Lock = switch (file.status) {121 var lock: Io.File.Lock = switch (file.status) {
122 .never_loaded, .retryable_failure => lock: {122 .never_loaded, .retryable_failure => lock: {
123 // First, load the cached ZIR code, if any.123 // First, load the cached ZIR code, if any.
124 log.debug("AstGen checking cache: {f} (local={}, digest={s})", .{124 log.debug("AstGen checking cache: {f} (local={}, digest={s})", .{
...@@ -346,8 +346,8 @@ pub fn updateFile(...@@ -346,8 +346,8 @@ pub fn updateFile(
346346
347fn loadZirZoirCache(347fn loadZirZoirCache(
348 zcu: *Zcu,348 zcu: *Zcu,
349 cache_file: std.fs.File,349 cache_file: Io.File,
350 stat: std.fs.File.Stat,350 stat: Io.File.Stat,
351 file: *Zcu.File,351 file: *Zcu.File,
352 comptime mode: Ast.Mode,352 comptime mode: Ast.Mode,
353) !enum { success, invalid, truncated, stale } {353) !enum { success, invalid, truncated, stale } {
src/fmt.zig+8-8
...@@ -37,9 +37,9 @@ const Fmt = struct {...@@ -37,9 +37,9 @@ const Fmt = struct {
37 arena: Allocator,37 arena: Allocator,
38 io: Io,38 io: Io,
39 out_buffer: std.Io.Writer.Allocating,39 out_buffer: std.Io.Writer.Allocating,
40 stdout_writer: *fs.File.Writer,40 stdout_writer: *Io.File.Writer,
4141
42 const SeenMap = std.AutoHashMap(fs.File.INode, void);42 const SeenMap = std.AutoHashMap(Io.File.INode, void);
43};43};
4444
45pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !void {45pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !void {
...@@ -59,7 +59,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !...@@ -59,7 +59,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
59 const arg = args[i];59 const arg = args[i];
60 if (mem.startsWith(u8, arg, "-")) {60 if (mem.startsWith(u8, arg, "-")) {
61 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {61 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
62 try fs.File.stdout().writeAll(usage_fmt);62 try Io.File.stdout().writeAll(usage_fmt);
63 return process.cleanExit();63 return process.cleanExit();
64 } else if (mem.eql(u8, arg, "--color")) {64 } else if (mem.eql(u8, arg, "--color")) {
65 if (i + 1 >= args.len) {65 if (i + 1 >= args.len) {
...@@ -99,9 +99,9 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !...@@ -99,9 +99,9 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
99 fatal("cannot use --stdin with positional arguments", .{});99 fatal("cannot use --stdin with positional arguments", .{});
100 }100 }
101101
102 const stdin: fs.File = .stdin();102 const stdin: Io.File = .stdin();
103 var stdio_buffer: [1024]u8 = undefined;103 var stdio_buffer: [1024]u8 = undefined;
104 var file_reader: fs.File.Reader = stdin.reader(io, &stdio_buffer);104 var file_reader: Io.File.Reader = stdin.reader(io, &stdio_buffer);
105 const source_code = std.zig.readSourceFileToEndAlloc(gpa, &file_reader) catch |err| {105 const source_code = std.zig.readSourceFileToEndAlloc(gpa, &file_reader) catch |err| {
106 fatal("unable to read stdin: {}", .{err});106 fatal("unable to read stdin: {}", .{err});
107 };107 };
...@@ -154,7 +154,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !...@@ -154,7 +154,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
154 process.exit(code);154 process.exit(code);
155 }155 }
156156
157 return fs.File.stdout().writeAll(formatted);157 return Io.File.stdout().writeAll(formatted);
158 }158 }
159159
160 if (input_files.items.len == 0) {160 if (input_files.items.len == 0) {
...@@ -162,7 +162,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !...@@ -162,7 +162,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
162 }162 }
163163
164 var stdout_buffer: [4096]u8 = undefined;164 var stdout_buffer: [4096]u8 = undefined;
165 var stdout_writer = fs.File.stdout().writer(&stdout_buffer);165 var stdout_writer = Io.File.stdout().writer(&stdout_buffer);
166166
167 var fmt: Fmt = .{167 var fmt: Fmt = .{
168 .gpa = gpa,168 .gpa = gpa,
...@@ -272,7 +272,7 @@ fn fmtPathFile(...@@ -272,7 +272,7 @@ fn fmtPathFile(
272 return error.IsDir;272 return error.IsDir;
273273
274 var read_buffer: [1024]u8 = undefined;274 var read_buffer: [1024]u8 = undefined;
275 var file_reader: fs.File.Reader = source_file.reader(io, &read_buffer);275 var file_reader: Io.File.Reader = source_file.reader(io, &read_buffer);
276 file_reader.size = stat.size;276 file_reader.size = stat.size;
277277
278 const gpa = fmt.gpa;278 const gpa = fmt.gpa;
src/link.zig+10-10
...@@ -393,7 +393,7 @@ pub const File = struct {...@@ -393,7 +393,7 @@ pub const File = struct {
393 comp: *Compilation,393 comp: *Compilation,
394 emit: Path,394 emit: Path,
395395
396 file: ?fs.File,396 file: ?Io.File,
397 /// When using the LLVM backend, the emitted object is written to a file with this name. This397 /// When using the LLVM backend, the emitted object is written to a file with this name. This
398 /// object file then becomes a normal link input to LLD or a self-hosted linker.398 /// object file then becomes a normal link input to LLD or a self-hosted linker.
399 ///399 ///
...@@ -1110,7 +1110,7 @@ pub const File = struct {...@@ -1110,7 +1110,7 @@ pub const File = struct {
1110 };1110 };
1111 }1111 }
11121112
1113 fn loadGnuLdScript(base: *File, path: Path, parent_query: UnresolvedInput.Query, file: fs.File) anyerror!void {1113 fn loadGnuLdScript(base: *File, path: Path, parent_query: UnresolvedInput.Query, file: Io.File) anyerror!void {
1114 const comp = base.comp;1114 const comp = base.comp;
1115 const diags = &comp.link_diags;1115 const diags = &comp.link_diags;
1116 const gpa = comp.gpa;1116 const gpa = comp.gpa;
...@@ -1238,7 +1238,7 @@ pub const File = struct {...@@ -1238,7 +1238,7 @@ pub const File = struct {
1238 pub fn determineMode(1238 pub fn determineMode(
1239 output_mode: std.builtin.OutputMode,1239 output_mode: std.builtin.OutputMode,
1240 link_mode: std.builtin.LinkMode,1240 link_mode: std.builtin.LinkMode,
1241 ) fs.File.Mode {1241 ) Io.File.Mode {
1242 // On common systems with a 0o022 umask, 0o777 will still result in a file created1242 // On common systems with a 0o022 umask, 0o777 will still result in a file created
1243 // with 0o755 permissions, but it works appropriately if the system is configured1243 // with 0o755 permissions, but it works appropriately if the system is configured
1244 // more leniently. As another data point, C's fopen seems to open files with the1244 // more leniently. As another data point, C's fopen seems to open files with the
...@@ -1247,10 +1247,10 @@ pub const File = struct {...@@ -1247,10 +1247,10 @@ pub const File = struct {
1247 switch (output_mode) {1247 switch (output_mode) {
1248 .Lib => return switch (link_mode) {1248 .Lib => return switch (link_mode) {
1249 .dynamic => executable_mode,1249 .dynamic => executable_mode,
1250 .static => fs.File.default_mode,1250 .static => Io.File.default_mode,
1251 },1251 },
1252 .Exe => return executable_mode,1252 .Exe => return executable_mode,
1253 .Obj => return fs.File.default_mode,1253 .Obj => return Io.File.default_mode,
1254 }1254 }
1255 }1255 }
12561256
...@@ -1660,19 +1660,19 @@ pub const Input = union(enum) {...@@ -1660,19 +1660,19 @@ pub const Input = union(enum) {
16601660
1661 pub const Object = struct {1661 pub const Object = struct {
1662 path: Path,1662 path: Path,
1663 file: fs.File,1663 file: Io.File,
1664 must_link: bool,1664 must_link: bool,
1665 hidden: bool,1665 hidden: bool,
1666 };1666 };
16671667
1668 pub const Res = struct {1668 pub const Res = struct {
1669 path: Path,1669 path: Path,
1670 file: fs.File,1670 file: Io.File,
1671 };1671 };
16721672
1673 pub const Dso = struct {1673 pub const Dso = struct {
1674 path: Path,1674 path: Path,
1675 file: fs.File,1675 file: Io.File,
1676 needed: bool,1676 needed: bool,
1677 weak: bool,1677 weak: bool,
1678 reexport: bool,1678 reexport: bool,
...@@ -1694,7 +1694,7 @@ pub const Input = union(enum) {...@@ -1694,7 +1694,7 @@ pub const Input = union(enum) {
1694 }1694 }
16951695
1696 /// Returns `null` in the case of `dso_exact`.1696 /// Returns `null` in the case of `dso_exact`.
1697 pub fn pathAndFile(input: Input) ?struct { Path, fs.File } {1697 pub fn pathAndFile(input: Input) ?struct { Path, Io.File } {
1698 return switch (input) {1698 return switch (input) {
1699 .object, .archive => |obj| .{ obj.path, obj.file },1699 .object, .archive => |obj| .{ obj.path, obj.file },
1700 inline .res, .dso => |x| .{ x.path, x.file },1700 inline .res, .dso => |x| .{ x.path, x.file },
...@@ -2075,7 +2075,7 @@ fn resolveLibInput(...@@ -2075,7 +2075,7 @@ fn resolveLibInput(
2075fn finishResolveLibInput(2075fn finishResolveLibInput(
2076 resolved_inputs: *std.ArrayList(Input),2076 resolved_inputs: *std.ArrayList(Input),
2077 path: Path,2077 path: Path,
2078 file: std.fs.File,2078 file: Io.File,
2079 link_mode: std.builtin.LinkMode,2079 link_mode: std.builtin.LinkMode,
2080 query: UnresolvedInput.Query,2080 query: UnresolvedInput.Query,
2081) ResolveLibInputResult {2081) ResolveLibInputResult {
src/link/Dwarf.zig+28-25
...@@ -1,3 +1,24 @@...@@ -1,3 +1,24 @@
1const Dwarf = @This();
2
3const std = @import("std");
4const Io = std.Io;
5const Allocator = std.mem.Allocator;
6const DW = std.dwarf;
7const Zir = std.zig.Zir;
8const assert = std.debug.assert;
9const log = std.log.scoped(.dwarf);
10const Writer = std.Io.Writer;
11
12const InternPool = @import("../InternPool.zig");
13const Module = @import("../Package.zig").Module;
14const Type = @import("../Type.zig");
15const Value = @import("../Value.zig");
16const Zcu = @import("../Zcu.zig");
17const codegen = @import("../codegen.zig");
18const dev = @import("../dev.zig");
19const link = @import("../link.zig");
20const target_info = @import("../target.zig");
21
1gpa: Allocator,22gpa: Allocator,
2bin_file: *link.File,23bin_file: *link.File,
3format: DW.Format,24format: DW.Format,
...@@ -29,16 +50,16 @@ pub const UpdateError = error{...@@ -29,16 +50,16 @@ pub const UpdateError = error{
29 UnexpectedEndOfFile,50 UnexpectedEndOfFile,
30} ||51} ||
31 codegen.GenerateSymbolError ||52 codegen.GenerateSymbolError ||
32 std.fs.File.OpenError ||53 Io.File.OpenError ||
33 std.fs.File.SetEndPosError ||54 Io.File.SetEndPosError ||
34 std.fs.File.CopyRangeError ||55 Io.File.CopyRangeError ||
35 std.fs.File.PReadError ||56 Io.File.PReadError ||
36 std.fs.File.PWriteError;57 Io.File.PWriteError;
3758
38pub const FlushError = UpdateError;59pub const FlushError = UpdateError;
3960
40pub const RelocError =61pub const RelocError =
41 std.fs.File.PWriteError;62 Io.File.PWriteError;
4263
43pub const AddressSize = enum(u8) {64pub const AddressSize = enum(u8) {
44 @"32" = 4,65 @"32" = 4,
...@@ -6350,7 +6371,7 @@ const AbbrevCode = enum {...@@ -6350,7 +6371,7 @@ const AbbrevCode = enum {
6350 });6371 });
6351};6372};
63526373
6353fn getFile(dwarf: *Dwarf) ?std.fs.File {6374fn getFile(dwarf: *Dwarf) ?Io.File {
6354 if (dwarf.bin_file.cast(.macho)) |macho_file| if (macho_file.d_sym) |*d_sym| return d_sym.file;6375 if (dwarf.bin_file.cast(.macho)) |macho_file| if (macho_file.d_sym) |*d_sym| return d_sym.file;
6355 return dwarf.bin_file.file;6376 return dwarf.bin_file.file;
6356}6377}
...@@ -6429,21 +6450,3 @@ const force_incremental = false;...@@ -6429,21 +6450,3 @@ const force_incremental = false;
6429inline fn incremental(dwarf: Dwarf) bool {6450inline fn incremental(dwarf: Dwarf) bool {
6430 return force_incremental or dwarf.bin_file.comp.config.incremental;6451 return force_incremental or dwarf.bin_file.comp.config.incremental;
6431}6452}
6432
6433const Allocator = std.mem.Allocator;
6434const DW = std.dwarf;
6435const Dwarf = @This();
6436const InternPool = @import("../InternPool.zig");
6437const Module = @import("../Package.zig").Module;
6438const Type = @import("../Type.zig");
6439const Value = @import("../Value.zig");
6440const Zcu = @import("../Zcu.zig");
6441const Zir = std.zig.Zir;
6442const assert = std.debug.assert;
6443const codegen = @import("../codegen.zig");
6444const dev = @import("../dev.zig");
6445const link = @import("../link.zig");
6446const log = std.log.scoped(.dwarf);
6447const std = @import("std");
6448const target_info = @import("../target.zig");
6449const Writer = std.Io.Writer;
src/link/Elf.zig+3-2
...@@ -3651,7 +3651,7 @@ fn fileLookup(files: std.MultiArrayList(File.Entry), index: File.Index, zig_obje...@@ -3651,7 +3651,7 @@ fn fileLookup(files: std.MultiArrayList(File.Entry), index: File.Index, zig_obje
3651pub fn addFileHandle(3651pub fn addFileHandle(
3652 gpa: Allocator,3652 gpa: Allocator,
3653 file_handles: *std.ArrayList(File.Handle),3653 file_handles: *std.ArrayList(File.Handle),
3654 handle: fs.File,3654 handle: Io.File,
3655) Allocator.Error!File.HandleIndex {3655) Allocator.Error!File.HandleIndex {
3656 try file_handles.append(gpa, handle);3656 try file_handles.append(gpa, handle);
3657 return @intCast(file_handles.items.len - 1);3657 return @intCast(file_handles.items.len - 1);
...@@ -4068,7 +4068,7 @@ fn fmtDumpState(self: *Elf, writer: *std.Io.Writer) std.Io.Writer.Error!void {...@@ -4068,7 +4068,7 @@ fn fmtDumpState(self: *Elf, writer: *std.Io.Writer) std.Io.Writer.Error!void {
4068}4068}
40694069
4070/// Caller owns the memory.4070/// Caller owns the memory.
4071pub fn preadAllAlloc(allocator: Allocator, handle: fs.File, offset: u64, size: u64) ![]u8 {4071pub fn preadAllAlloc(allocator: Allocator, handle: Io.File, offset: u64, size: u64) ![]u8 {
4072 const buffer = try allocator.alloc(u8, math.cast(usize, size) orelse return error.Overflow);4072 const buffer = try allocator.alloc(u8, math.cast(usize, size) orelse return error.Overflow);
4073 errdefer allocator.free(buffer);4073 errdefer allocator.free(buffer);
4074 const amt = try handle.preadAll(buffer, offset);4074 const amt = try handle.preadAll(buffer, offset);
...@@ -4460,6 +4460,7 @@ pub fn cast(elf_file: *Elf, comptime T: type, x: anytype) error{LinkFailure}!T {...@@ -4460,6 +4460,7 @@ pub fn cast(elf_file: *Elf, comptime T: type, x: anytype) error{LinkFailure}!T {
4460}4460}
44614461
4462const std = @import("std");4462const std = @import("std");
4463const Io = std.Io;
4463const build_options = @import("build_options");4464const build_options = @import("build_options");
4464const builtin = @import("builtin");4465const builtin = @import("builtin");
4465const assert = std.debug.assert;4466const assert = std.debug.assert;
src/link/Elf/Object.zig+33-32
...@@ -1,3 +1,30 @@...@@ -1,3 +1,30 @@
1const Object = @This();
2
3const std = @import("std");
4const Io = std.Io;
5const assert = std.debug.assert;
6const eh_frame = @import("eh_frame.zig");
7const elf = std.elf;
8const fs = std.fs;
9const log = std.log.scoped(.link);
10const math = std.math;
11const mem = std.mem;
12const Path = std.Build.Cache.Path;
13const Allocator = std.mem.Allocator;
14
15const Diags = @import("../../link.zig").Diags;
16const Archive = @import("Archive.zig");
17const Atom = @import("Atom.zig");
18const AtomList = @import("AtomList.zig");
19const Cie = eh_frame.Cie;
20const Elf = @import("../Elf.zig");
21const Fde = eh_frame.Fde;
22const File = @import("file.zig").File;
23const Merge = @import("Merge.zig");
24const Symbol = @import("Symbol.zig");
25const Alignment = Atom.Alignment;
26const riscv = @import("../riscv.zig");
27
1archive: ?InArchive = null,28archive: ?InArchive = null,
2/// Archive files cannot contain subdirectories, so only the basename is needed29/// Archive files cannot contain subdirectories, so only the basename is needed
3/// for output. However, the full path is kept for error reporting.30/// for output. However, the full path is kept for error reporting.
...@@ -68,7 +95,7 @@ pub fn parse(...@@ -68,7 +95,7 @@ pub fn parse(
68 diags: *Diags,95 diags: *Diags,
69 /// For error reporting purposes only.96 /// For error reporting purposes only.
70 path: Path,97 path: Path,
71 handle: fs.File,98 handle: Io.File,
72 target: *const std.Target,99 target: *const std.Target,
73 debug_fmt_strip: bool,100 debug_fmt_strip: bool,
74 default_sym_version: elf.Versym,101 default_sym_version: elf.Versym,
...@@ -97,7 +124,7 @@ pub fn parseCommon(...@@ -97,7 +124,7 @@ pub fn parseCommon(
97 gpa: Allocator,124 gpa: Allocator,
98 diags: *Diags,125 diags: *Diags,
99 path: Path,126 path: Path,
100 handle: fs.File,127 handle: Io.File,
101 target: *const std.Target,128 target: *const std.Target,
102) !void {129) !void {
103 const offset = if (self.archive) |ar| ar.offset else 0;130 const offset = if (self.archive) |ar| ar.offset else 0;
...@@ -264,7 +291,7 @@ fn initAtoms(...@@ -264,7 +291,7 @@ fn initAtoms(
264 gpa: Allocator,291 gpa: Allocator,
265 diags: *Diags,292 diags: *Diags,
266 path: Path,293 path: Path,
267 handle: fs.File,294 handle: Io.File,
268 debug_fmt_strip: bool,295 debug_fmt_strip: bool,
269 target: *const std.Target,296 target: *const std.Target,
270) !void {297) !void {
...@@ -421,7 +448,7 @@ fn initSymbols(...@@ -421,7 +448,7 @@ fn initSymbols(
421fn parseEhFrame(448fn parseEhFrame(
422 self: *Object,449 self: *Object,
423 gpa: Allocator,450 gpa: Allocator,
424 handle: fs.File,451 handle: Io.File,
425 shndx: u32,452 shndx: u32,
426 target: *const std.Target,453 target: *const std.Target,
427) !void {454) !void {
...@@ -1310,7 +1337,7 @@ fn addString(self: *Object, gpa: Allocator, str: []const u8) !u32 {...@@ -1310,7 +1337,7 @@ fn addString(self: *Object, gpa: Allocator, str: []const u8) !u32 {
1310}1337}
13111338
1312/// Caller owns the memory.1339/// Caller owns the memory.
1313fn preadShdrContentsAlloc(self: Object, gpa: Allocator, handle: fs.File, index: u32) ![]u8 {1340fn preadShdrContentsAlloc(self: Object, gpa: Allocator, handle: Io.File, index: u32) ![]u8 {
1314 assert(index < self.shdrs.items.len);1341 assert(index < self.shdrs.items.len);
1315 const offset = if (self.archive) |ar| ar.offset else 0;1342 const offset = if (self.archive) |ar| ar.offset else 0;
1316 const shdr = self.shdrs.items[index];1343 const shdr = self.shdrs.items[index];
...@@ -1320,7 +1347,7 @@ fn preadShdrContentsAlloc(self: Object, gpa: Allocator, handle: fs.File, index:...@@ -1320,7 +1347,7 @@ fn preadShdrContentsAlloc(self: Object, gpa: Allocator, handle: fs.File, index:
1320}1347}
13211348
1322/// Caller owns the memory.1349/// Caller owns the memory.
1323fn preadRelocsAlloc(self: Object, gpa: Allocator, handle: fs.File, shndx: u32) ![]align(1) const elf.Elf64_Rela {1350fn preadRelocsAlloc(self: Object, gpa: Allocator, handle: Io.File, shndx: u32) ![]align(1) const elf.Elf64_Rela {
1324 const raw = try self.preadShdrContentsAlloc(gpa, handle, shndx);1351 const raw = try self.preadShdrContentsAlloc(gpa, handle, shndx);
1325 const num = @divExact(raw.len, @sizeOf(elf.Elf64_Rela));1352 const num = @divExact(raw.len, @sizeOf(elf.Elf64_Rela));
1326 return @as([*]align(1) const elf.Elf64_Rela, @ptrCast(raw.ptr))[0..num];1353 return @as([*]align(1) const elf.Elf64_Rela, @ptrCast(raw.ptr))[0..num];
...@@ -1552,29 +1579,3 @@ const InArchive = struct {...@@ -1552,29 +1579,3 @@ const InArchive = struct {
1552 offset: u64,1579 offset: u64,
1553 size: u32,1580 size: u32,
1554};1581};
1555
1556const Object = @This();
1557
1558const std = @import("std");
1559const assert = std.debug.assert;
1560const eh_frame = @import("eh_frame.zig");
1561const elf = std.elf;
1562const fs = std.fs;
1563const log = std.log.scoped(.link);
1564const math = std.math;
1565const mem = std.mem;
1566const Path = std.Build.Cache.Path;
1567const Allocator = std.mem.Allocator;
1568
1569const Diags = @import("../../link.zig").Diags;
1570const Archive = @import("Archive.zig");
1571const Atom = @import("Atom.zig");
1572const AtomList = @import("AtomList.zig");
1573const Cie = eh_frame.Cie;
1574const Elf = @import("../Elf.zig");
1575const Fde = eh_frame.Fde;
1576const File = @import("file.zig").File;
1577const Merge = @import("Merge.zig");
1578const Symbol = @import("Symbol.zig");
1579const Alignment = Atom.Alignment;
1580const riscv = @import("../riscv.zig");
src/link/Elf/SharedObject.zig+19-18
...@@ -1,3 +1,20 @@...@@ -1,3 +1,20 @@
1const SharedObject = @This();
2
3const std = @import("std");
4const Io = std.Io;
5const assert = std.debug.assert;
6const elf = std.elf;
7const log = std.log.scoped(.elf);
8const mem = std.mem;
9const Path = std.Build.Cache.Path;
10const Stat = std.Build.Cache.File.Stat;
11const Allocator = mem.Allocator;
12
13const Elf = @import("../Elf.zig");
14const File = @import("file.zig").File;
15const Symbol = @import("Symbol.zig");
16const Diags = @import("../../link.zig").Diags;
17
1path: Path,18path: Path,
2index: File.Index,19index: File.Index,
320
...@@ -94,7 +111,7 @@ pub fn parseHeader(...@@ -94,7 +111,7 @@ pub fn parseHeader(
94 gpa: Allocator,111 gpa: Allocator,
95 diags: *Diags,112 diags: *Diags,
96 file_path: Path,113 file_path: Path,
97 fs_file: std.fs.File,114 fs_file: Io.File,
98 stat: Stat,115 stat: Stat,
99 target: *const std.Target,116 target: *const std.Target,
100) !Header {117) !Header {
...@@ -192,7 +209,7 @@ pub fn parse(...@@ -192,7 +209,7 @@ pub fn parse(
192 gpa: Allocator,209 gpa: Allocator,
193 /// Moves resources from header. Caller may unconditionally deinit.210 /// Moves resources from header. Caller may unconditionally deinit.
194 header: *Header,211 header: *Header,
195 fs_file: std.fs.File,212 fs_file: Io.File,
196) !Parsed {213) !Parsed {
197 const symtab = if (header.dynsym_sect_index) |index| st: {214 const symtab = if (header.dynsym_sect_index) |index| st: {
198 const shdr = header.sections[index];215 const shdr = header.sections[index];
...@@ -534,19 +551,3 @@ const Format = struct {...@@ -534,19 +551,3 @@ const Format = struct {
534 }551 }
535 }552 }
536};553};
537
538const SharedObject = @This();
539
540const std = @import("std");
541const assert = std.debug.assert;
542const elf = std.elf;
543const log = std.log.scoped(.elf);
544const mem = std.mem;
545const Path = std.Build.Cache.Path;
546const Stat = std.Build.Cache.File.Stat;
547const Allocator = mem.Allocator;
548
549const Elf = @import("../Elf.zig");
550const File = @import("file.zig").File;
551const Symbol = @import("Symbol.zig");
552const Diags = @import("../../link.zig").Diags;
src/link/Elf/file.zig+18-17
...@@ -1,3 +1,20 @@...@@ -1,3 +1,20 @@
1const std = @import("std");
2const Io = std.Io;
3const elf = std.elf;
4const log = std.log.scoped(.link);
5const Path = std.Build.Cache.Path;
6const Allocator = std.mem.Allocator;
7
8const Archive = @import("Archive.zig");
9const Atom = @import("Atom.zig");
10const Cie = @import("eh_frame.zig").Cie;
11const Elf = @import("../Elf.zig");
12const LinkerDefined = @import("LinkerDefined.zig");
13const Object = @import("Object.zig");
14const SharedObject = @import("SharedObject.zig");
15const Symbol = @import("Symbol.zig");
16const ZigObject = @import("ZigObject.zig");
17
1pub const File = union(enum) {18pub const File = union(enum) {
2 zig_object: *ZigObject,19 zig_object: *ZigObject,
3 linker_defined: *LinkerDefined,20 linker_defined: *LinkerDefined,
...@@ -279,22 +296,6 @@ pub const File = union(enum) {...@@ -279,22 +296,6 @@ pub const File = union(enum) {
279 shared_object: SharedObject,296 shared_object: SharedObject,
280 };297 };
281298
282 pub const Handle = std.fs.File;299 pub const Handle = Io.File;
283 pub const HandleIndex = Index;300 pub const HandleIndex = Index;
284};301};
285
286const std = @import("std");
287const elf = std.elf;
288const log = std.log.scoped(.link);
289const Path = std.Build.Cache.Path;
290const Allocator = std.mem.Allocator;
291
292const Archive = @import("Archive.zig");
293const Atom = @import("Atom.zig");
294const Cie = @import("eh_frame.zig").Cie;
295const Elf = @import("../Elf.zig");
296const LinkerDefined = @import("LinkerDefined.zig");
297const Object = @import("Object.zig");
298const SharedObject = @import("SharedObject.zig");
299const Symbol = @import("Symbol.zig");
300const ZigObject = @import("ZigObject.zig");
src/link/Elf2.zig+25-21
...@@ -1,3 +1,23 @@...@@ -1,3 +1,23 @@
1const Elf = @This();
2
3const builtin = @import("builtin");
4const native_endian = builtin.cpu.arch.endian();
5
6const std = @import("std");
7const Io = std.Io;
8const assert = std.debug.assert;
9const log = std.log.scoped(.link);
10
11const codegen = @import("../codegen.zig");
12const Compilation = @import("../Compilation.zig");
13const InternPool = @import("../InternPool.zig");
14const link = @import("../link.zig");
15const MappedFile = @import("MappedFile.zig");
16const target_util = @import("../target.zig");
17const Type = @import("../Type.zig");
18const Value = @import("../Value.zig");
19const Zcu = @import("../Zcu.zig");
20
1base: link.File,21base: link.File,
2options: link.File.OpenOptions,22options: link.File.OpenOptions,
3mf: MappedFile,23mf: MappedFile,
...@@ -1973,8 +1993,8 @@ pub fn lazySymbol(elf: *Elf, lazy: link.File.LazySymbol) !Symbol.Index {...@@ -1973,8 +1993,8 @@ pub fn lazySymbol(elf: *Elf, lazy: link.File.LazySymbol) !Symbol.Index {
1973 return lazy_gop.value_ptr.*;1993 return lazy_gop.value_ptr.*;
1974}1994}
19751995
1976pub fn loadInput(elf: *Elf, input: link.Input) (std.fs.File.Reader.SizeError ||1996pub fn loadInput(elf: *Elf, input: link.Input) (Io.File.Reader.SizeError ||
1977 std.Io.File.Reader.Error || MappedFile.Error || error{ EndOfStream, BadMagic, LinkFailure })!void {1997 Io.File.Reader.Error || MappedFile.Error || error{ EndOfStream, BadMagic, LinkFailure })!void {
1978 const io = elf.base.comp.io;1998 const io = elf.base.comp.io;
1979 var buf: [4096]u8 = undefined;1999 var buf: [4096]u8 = undefined;
1980 switch (input) {2000 switch (input) {
...@@ -2007,7 +2027,7 @@ pub fn loadInput(elf: *Elf, input: link.Input) (std.fs.File.Reader.SizeError ||...@@ -2007,7 +2027,7 @@ pub fn loadInput(elf: *Elf, input: link.Input) (std.fs.File.Reader.SizeError ||
2007 .dso_exact => |dso_exact| try elf.loadDsoExact(dso_exact.name),2027 .dso_exact => |dso_exact| try elf.loadDsoExact(dso_exact.name),
2008 }2028 }
2009}2029}
2010fn loadArchive(elf: *Elf, path: std.Build.Cache.Path, fr: *std.Io.File.Reader) !void {2030fn loadArchive(elf: *Elf, path: std.Build.Cache.Path, fr: *Io.File.Reader) !void {
2011 const comp = elf.base.comp;2031 const comp = elf.base.comp;
2012 const gpa = comp.gpa;2032 const gpa = comp.gpa;
2013 const diags = &comp.link_diags;2033 const diags = &comp.link_diags;
...@@ -2067,7 +2087,7 @@ fn loadObject(...@@ -2067,7 +2087,7 @@ fn loadObject(
2067 elf: *Elf,2087 elf: *Elf,
2068 path: std.Build.Cache.Path,2088 path: std.Build.Cache.Path,
2069 member: ?[]const u8,2089 member: ?[]const u8,
2070 fr: *std.Io.File.Reader,2090 fr: *Io.File.Reader,
2071 fl: MappedFile.Node.FileLocation,2091 fl: MappedFile.Node.FileLocation,
2072) !void {2092) !void {
2073 const comp = elf.base.comp;2093 const comp = elf.base.comp;
...@@ -2310,7 +2330,7 @@ fn loadObject(...@@ -2310,7 +2330,7 @@ fn loadObject(
2310 },2330 },
2311 }2331 }
2312}2332}
2313fn loadDso(elf: *Elf, path: std.Build.Cache.Path, fr: *std.Io.File.Reader) !void {2333fn loadDso(elf: *Elf, path: std.Build.Cache.Path, fr: *Io.File.Reader) !void {
2314 const comp = elf.base.comp;2334 const comp = elf.base.comp;
2315 const diags = &comp.link_diags;2335 const diags = &comp.link_diags;
2316 const r = &fr.interface;2336 const r = &fr.interface;
...@@ -3822,19 +3842,3 @@ pub fn printNode(...@@ -3822,19 +3842,3 @@ pub fn printNode(
3822 try w.writeByte('\n');3842 try w.writeByte('\n');
3823 }3843 }
3824}3844}
3825
3826const assert = std.debug.assert;
3827const builtin = @import("builtin");
3828const codegen = @import("../codegen.zig");
3829const Compilation = @import("../Compilation.zig");
3830const Elf = @This();
3831const InternPool = @import("../InternPool.zig");
3832const link = @import("../link.zig");
3833const log = std.log.scoped(.link);
3834const MappedFile = @import("MappedFile.zig");
3835const native_endian = builtin.cpu.arch.endian();
3836const std = @import("std");
3837const target_util = @import("../target.zig");
3838const Type = @import("../Type.zig");
3839const Value = @import("../Value.zig");
3840const Zcu = @import("../Zcu.zig");
src/link/MachO.zig+12-11
...@@ -890,7 +890,7 @@ pub fn classifyInputFile(self: *MachO, input: link.Input) !void {...@@ -890,7 +890,7 @@ pub fn classifyInputFile(self: *MachO, input: link.Input) !void {
890 _ = try self.addTbd(.fromLinkInput(input), true, fh);890 _ = try self.addTbd(.fromLinkInput(input), true, fh);
891}891}
892892
893fn parseFatFile(self: *MachO, file: std.fs.File, path: Path) !?fat.Arch {893fn parseFatFile(self: *MachO, file: Io.File, path: Path) !?fat.Arch {
894 const diags = &self.base.comp.link_diags;894 const diags = &self.base.comp.link_diags;
895 const fat_h = fat.readFatHeader(file) catch return null;895 const fat_h = fat.readFatHeader(file) catch return null;
896 if (fat_h.magic != macho.FAT_MAGIC and fat_h.magic != macho.FAT_MAGIC_64) return null;896 if (fat_h.magic != macho.FAT_MAGIC and fat_h.magic != macho.FAT_MAGIC_64) return null;
...@@ -903,7 +903,7 @@ fn parseFatFile(self: *MachO, file: std.fs.File, path: Path) !?fat.Arch {...@@ -903,7 +903,7 @@ fn parseFatFile(self: *MachO, file: std.fs.File, path: Path) !?fat.Arch {
903 return diags.failParse(path, "missing arch in universal file: expected {s}", .{@tagName(cpu_arch)});903 return diags.failParse(path, "missing arch in universal file: expected {s}", .{@tagName(cpu_arch)});
904}904}
905905
906pub fn readMachHeader(file: std.fs.File, offset: usize) !macho.mach_header_64 {906pub fn readMachHeader(file: Io.File, offset: usize) !macho.mach_header_64 {
907 var buffer: [@sizeOf(macho.mach_header_64)]u8 = undefined;907 var buffer: [@sizeOf(macho.mach_header_64)]u8 = undefined;
908 const nread = try file.preadAll(&buffer, offset);908 const nread = try file.preadAll(&buffer, offset);
909 if (nread != buffer.len) return error.InputOutput;909 if (nread != buffer.len) return error.InputOutput;
...@@ -911,7 +911,7 @@ pub fn readMachHeader(file: std.fs.File, offset: usize) !macho.mach_header_64 {...@@ -911,7 +911,7 @@ pub fn readMachHeader(file: std.fs.File, offset: usize) !macho.mach_header_64 {
911 return hdr;911 return hdr;
912}912}
913913
914pub fn readArMagic(file: std.fs.File, offset: usize, buffer: *[Archive.SARMAG]u8) ![]const u8 {914pub fn readArMagic(file: Io.File, offset: usize, buffer: *[Archive.SARMAG]u8) ![]const u8 {
915 const nread = try file.preadAll(buffer, offset);915 const nread = try file.preadAll(buffer, offset);
916 if (nread != buffer.len) return error.InputOutput;916 if (nread != buffer.len) return error.InputOutput;
917 return buffer[0..Archive.SARMAG];917 return buffer[0..Archive.SARMAG];
...@@ -3768,7 +3768,7 @@ pub fn getInternalObject(self: *MachO) ?*InternalObject {...@@ -3768,7 +3768,7 @@ pub fn getInternalObject(self: *MachO) ?*InternalObject {
3768 return self.getFile(index).?.internal;3768 return self.getFile(index).?.internal;
3769}3769}
37703770
3771pub fn addFileHandle(self: *MachO, file: fs.File) !File.HandleIndex {3771pub fn addFileHandle(self: *MachO, file: Io.File) !File.HandleIndex {
3772 const gpa = self.base.comp.gpa;3772 const gpa = self.base.comp.gpa;
3773 const index: File.HandleIndex = @intCast(self.file_handles.items.len);3773 const index: File.HandleIndex = @intCast(self.file_handles.items.len);
3774 const fh = try self.file_handles.addOne(gpa);3774 const fh = try self.file_handles.addOne(gpa);
...@@ -5373,10 +5373,11 @@ const max_distance = (1 << (jump_bits - 1));...@@ -5373,10 +5373,11 @@ const max_distance = (1 << (jump_bits - 1));
5373const max_allowed_distance = max_distance - 0x500_000;5373const max_allowed_distance = max_distance - 0x500_000;
53745374
5375const MachO = @This();5375const MachO = @This();
5376
5377const std = @import("std");
5378const build_options = @import("build_options");5376const build_options = @import("build_options");
5379const builtin = @import("builtin");5377const builtin = @import("builtin");
5378
5379const std = @import("std");
5380const Io = std.Io;
5380const assert = std.debug.assert;5381const assert = std.debug.assert;
5381const fs = std.fs;5382const fs = std.fs;
5382const log = std.log.scoped(.link);5383const log = std.log.scoped(.link);
...@@ -5386,6 +5387,11 @@ const math = std.math;...@@ -5386,6 +5387,11 @@ const math = std.math;
5386const mem = std.mem;5387const mem = std.mem;
5387const meta = std.meta;5388const meta = std.meta;
5388const Writer = std.Io.Writer;5389const Writer = std.Io.Writer;
5390const AtomicBool = std.atomic.Value(bool);
5391const Cache = std.Build.Cache;
5392const Hash = std.hash.Wyhash;
5393const Md5 = std.crypto.hash.Md5;
5394const Allocator = std.mem.Allocator;
53895395
5390const aarch64 = codegen.aarch64.encoding;5396const aarch64 = codegen.aarch64.encoding;
5391const bind = @import("MachO/dyld_info/bind.zig");5397const bind = @import("MachO/dyld_info/bind.zig");
...@@ -5403,11 +5409,8 @@ const trace = @import("../tracy.zig").trace;...@@ -5403,11 +5409,8 @@ const trace = @import("../tracy.zig").trace;
5403const synthetic = @import("MachO/synthetic.zig");5409const synthetic = @import("MachO/synthetic.zig");
54045410
5405const Alignment = Atom.Alignment;5411const Alignment = Atom.Alignment;
5406const Allocator = mem.Allocator;
5407const Archive = @import("MachO/Archive.zig");5412const Archive = @import("MachO/Archive.zig");
5408const AtomicBool = std.atomic.Value(bool);
5409const Bind = bind.Bind;5413const Bind = bind.Bind;
5410const Cache = std.Build.Cache;
5411const CodeSignature = @import("MachO/CodeSignature.zig");5414const CodeSignature = @import("MachO/CodeSignature.zig");
5412const Compilation = @import("../Compilation.zig");5415const Compilation = @import("../Compilation.zig");
5413const DataInCode = synthetic.DataInCode;5416const DataInCode = synthetic.DataInCode;
...@@ -5417,14 +5420,12 @@ const ExportTrie = @import("MachO/dyld_info/Trie.zig");...@@ -5417,14 +5420,12 @@ const ExportTrie = @import("MachO/dyld_info/Trie.zig");
5417const Path = Cache.Path;5420const Path = Cache.Path;
5418const File = @import("MachO/file.zig").File;5421const File = @import("MachO/file.zig").File;
5419const GotSection = synthetic.GotSection;5422const GotSection = synthetic.GotSection;
5420const Hash = std.hash.Wyhash;
5421const Indsymtab = synthetic.Indsymtab;5423const Indsymtab = synthetic.Indsymtab;
5422const InternalObject = @import("MachO/InternalObject.zig");5424const InternalObject = @import("MachO/InternalObject.zig");
5423const ObjcStubsSection = synthetic.ObjcStubsSection;5425const ObjcStubsSection = synthetic.ObjcStubsSection;
5424const Object = @import("MachO/Object.zig");5426const Object = @import("MachO/Object.zig");
5425const LazyBind = bind.LazyBind;5427const LazyBind = bind.LazyBind;
5426const LaSymbolPtrSection = synthetic.LaSymbolPtrSection;5428const LaSymbolPtrSection = synthetic.LaSymbolPtrSection;
5427const Md5 = std.crypto.hash.Md5;
5428const Zcu = @import("../Zcu.zig");5429const Zcu = @import("../Zcu.zig");
5429const InternPool = @import("../InternPool.zig");5430const InternPool = @import("../InternPool.zig");
5430const Rebase = @import("MachO/dyld_info/Rebase.zig");5431const Rebase = @import("MachO/dyld_info/Rebase.zig");
src/link/MachO/CodeSignature.zig+5-3
...@@ -1,17 +1,19 @@...@@ -1,17 +1,19 @@
1const CodeSignature = @This();1const CodeSignature = @This();
22
3const std = @import("std");3const std = @import("std");
4const Io = std.Io;
4const assert = std.debug.assert;5const assert = std.debug.assert;
5const fs = std.fs;6const fs = std.fs;
6const log = std.log.scoped(.link);7const log = std.log.scoped(.link);
7const macho = std.macho;8const macho = std.macho;
8const mem = std.mem;9const mem = std.mem;
9const testing = std.testing;10const testing = std.testing;
11const Sha256 = std.crypto.hash.sha2.Sha256;
12const Allocator = std.mem.Allocator;
13
10const trace = @import("../../tracy.zig").trace;14const trace = @import("../../tracy.zig").trace;
11const Allocator = mem.Allocator;
12const Hasher = @import("hasher.zig").ParallelHasher;15const Hasher = @import("hasher.zig").ParallelHasher;
13const MachO = @import("../MachO.zig");16const MachO = @import("../MachO.zig");
14const Sha256 = std.crypto.hash.sha2.Sha256;
1517
16const hash_size = Sha256.digest_length;18const hash_size = Sha256.digest_length;
1719
...@@ -250,7 +252,7 @@ pub fn addEntitlements(self: *CodeSignature, allocator: Allocator, path: []const...@@ -250,7 +252,7 @@ pub fn addEntitlements(self: *CodeSignature, allocator: Allocator, path: []const
250}252}
251253
252pub const WriteOpts = struct {254pub const WriteOpts = struct {
253 file: fs.File,255 file: Io.File,
254 exec_seg_base: u64,256 exec_seg_base: u64,
255 exec_seg_limit: u64,257 exec_seg_limit: u64,
256 file_size: u32,258 file_size: u32,
src/link/MachO/fat.zig+7-5
...@@ -1,18 +1,20 @@...@@ -1,18 +1,20 @@
1const builtin = @import("builtin");
2const native_endian = builtin.target.cpu.arch.endian();
3
1const std = @import("std");4const std = @import("std");
5const Io = std.Io;
2const assert = std.debug.assert;6const assert = std.debug.assert;
3const builtin = @import("builtin");
4const log = std.log.scoped(.macho);7const log = std.log.scoped(.macho);
5const macho = std.macho;8const macho = std.macho;
6const mem = std.mem;9const mem = std.mem;
7const native_endian = builtin.target.cpu.arch.endian();
810
9const MachO = @import("../MachO.zig");11const MachO = @import("../MachO.zig");
1012
11pub fn readFatHeader(file: std.fs.File) !macho.fat_header {13pub fn readFatHeader(file: Io.File) !macho.fat_header {
12 return readFatHeaderGeneric(macho.fat_header, file, 0);14 return readFatHeaderGeneric(macho.fat_header, file, 0);
13}15}
1416
15fn readFatHeaderGeneric(comptime Hdr: type, file: std.fs.File, offset: usize) !Hdr {17fn readFatHeaderGeneric(comptime Hdr: type, file: Io.File, offset: usize) !Hdr {
16 var buffer: [@sizeOf(Hdr)]u8 = undefined;18 var buffer: [@sizeOf(Hdr)]u8 = undefined;
17 const nread = try file.preadAll(&buffer, offset);19 const nread = try file.preadAll(&buffer, offset);
18 if (nread != buffer.len) return error.InputOutput;20 if (nread != buffer.len) return error.InputOutput;
...@@ -27,7 +29,7 @@ pub const Arch = struct {...@@ -27,7 +29,7 @@ pub const Arch = struct {
27 size: u32,29 size: u32,
28};30};
2931
30pub fn parseArchs(file: std.fs.File, fat_header: macho.fat_header, out: *[2]Arch) ![]const Arch {32pub fn parseArchs(file: Io.File, fat_header: macho.fat_header, out: *[2]Arch) ![]const Arch {
31 var count: usize = 0;33 var count: usize = 0;
32 var fat_arch_index: u32 = 0;34 var fat_arch_index: u32 = 0;
33 while (fat_arch_index < fat_header.nfat_arch and count < out.len) : (fat_arch_index += 1) {35 while (fat_arch_index < fat_header.nfat_arch and count < out.len) : (fat_arch_index += 1) {
src/link/MachO/file.zig+2-1
...@@ -355,11 +355,12 @@ pub const File = union(enum) {...@@ -355,11 +355,12 @@ pub const File = union(enum) {
355 dylib: Dylib,355 dylib: Dylib,
356 };356 };
357357
358 pub const Handle = std.fs.File;358 pub const Handle = Io.File;
359 pub const HandleIndex = Index;359 pub const HandleIndex = Index;
360};360};
361361
362const std = @import("std");362const std = @import("std");
363const Io = std.Io;
363const assert = std.debug.assert;364const assert = std.debug.assert;
364const log = std.log.scoped(.link);365const log = std.log.scoped(.link);
365const macho = std.macho;366const macho = std.macho;
src/link/MachO/hasher.zig+10-12
...@@ -1,3 +1,9 @@...@@ -1,3 +1,9 @@
1const std = @import("std");
2const Io = std.Io;
3const Allocator = std.mem.Allocator;
4
5const trace = @import("../../tracy.zig").trace;
6
1pub fn ParallelHasher(comptime Hasher: type) type {7pub fn ParallelHasher(comptime Hasher: type) type {
2 const hash_size = Hasher.digest_length;8 const hash_size = Hasher.digest_length;
39
...@@ -5,7 +11,7 @@ pub fn ParallelHasher(comptime Hasher: type) type {...@@ -5,7 +11,7 @@ pub fn ParallelHasher(comptime Hasher: type) type {
5 allocator: Allocator,11 allocator: Allocator,
6 io: std.Io,12 io: std.Io,
713
8 pub fn hash(self: Self, file: fs.File, out: [][hash_size]u8, opts: struct {14 pub fn hash(self: Self, file: Io.File, out: [][hash_size]u8, opts: struct {
9 chunk_size: u64 = 0x4000,15 chunk_size: u64 = 0x4000,
10 max_file_size: ?u64 = null,16 max_file_size: ?u64 = null,
11 }) !void {17 }) !void {
...@@ -23,7 +29,7 @@ pub fn ParallelHasher(comptime Hasher: type) type {...@@ -23,7 +29,7 @@ pub fn ParallelHasher(comptime Hasher: type) type {
23 const buffer = try self.allocator.alloc(u8, chunk_size * out.len);29 const buffer = try self.allocator.alloc(u8, chunk_size * out.len);
24 defer self.allocator.free(buffer);30 defer self.allocator.free(buffer);
2531
26 const results = try self.allocator.alloc(fs.File.PReadError!usize, out.len);32 const results = try self.allocator.alloc(Io.File.PReadError!usize, out.len);
27 defer self.allocator.free(results);33 defer self.allocator.free(results);
2834
29 {35 {
...@@ -51,11 +57,11 @@ pub fn ParallelHasher(comptime Hasher: type) type {...@@ -51,11 +57,11 @@ pub fn ParallelHasher(comptime Hasher: type) type {
51 }57 }
5258
53 fn worker(59 fn worker(
54 file: fs.File,60 file: Io.File,
55 fstart: usize,61 fstart: usize,
56 buffer: []u8,62 buffer: []u8,
57 out: *[hash_size]u8,63 out: *[hash_size]u8,
58 err: *fs.File.PReadError!usize,64 err: *Io.File.PReadError!usize,
59 ) void {65 ) void {
60 const tracy = trace(@src());66 const tracy = trace(@src());
61 defer tracy.end();67 defer tracy.end();
...@@ -66,11 +72,3 @@ pub fn ParallelHasher(comptime Hasher: type) type {...@@ -66,11 +72,3 @@ pub fn ParallelHasher(comptime Hasher: type) type {
66 const Self = @This();72 const Self = @This();
67 };73 };
68}74}
69
70const assert = std.debug.assert;
71const fs = std.fs;
72const mem = std.mem;
73const std = @import("std");
74const trace = @import("../../tracy.zig").trace;
75
76const Allocator = mem.Allocator;
src/link/MachO/uuid.zig+9-10
...@@ -1,10 +1,18 @@...@@ -1,10 +1,18 @@
1const std = @import("std");
2const Io = std.Io;
3const Md5 = std.crypto.hash.Md5;
4
5const trace = @import("../../tracy.zig").trace;
6const Compilation = @import("../../Compilation.zig");
7const Hasher = @import("hasher.zig").ParallelHasher;
8
1/// Calculates Md5 hash of each chunk in parallel and then hashes all Md5 hashes to produce9/// Calculates Md5 hash of each chunk in parallel and then hashes all Md5 hashes to produce
2/// the final digest.10/// the final digest.
3/// While this is NOT a correct MD5 hash of the contents, this methodology is used by LLVM/LLD11/// While this is NOT a correct MD5 hash of the contents, this methodology is used by LLVM/LLD
4/// and we will use it too as it seems accepted by Apple OSes.12/// and we will use it too as it seems accepted by Apple OSes.
5/// TODO LLD also hashes the output filename to disambiguate between same builds with different13/// TODO LLD also hashes the output filename to disambiguate between same builds with different
6/// output files. Should we also do that?14/// output files. Should we also do that?
7pub fn calcUuid(comp: *const Compilation, file: fs.File, file_size: u64, out: *[Md5.digest_length]u8) !void {15pub fn calcUuid(comp: *const Compilation, file: Io.File, file_size: u64, out: *[Md5.digest_length]u8) !void {
8 const tracy = trace(@src());16 const tracy = trace(@src());
9 defer tracy.end();17 defer tracy.end();
1018
...@@ -37,12 +45,3 @@ inline fn conform(out: *[Md5.digest_length]u8) void {...@@ -37,12 +45,3 @@ inline fn conform(out: *[Md5.digest_length]u8) void {
37 out[6] = (out[6] & 0x0F) | (3 << 4);45 out[6] = (out[6] & 0x0F) | (3 << 4);
38 out[8] = (out[8] & 0x3F) | 0x80;46 out[8] = (out[8] & 0x3F) | 0x80;
39}47}
40
41const fs = std.fs;
42const mem = std.mem;
43const std = @import("std");
44const trace = @import("../../tracy.zig").trace;
45
46const Compilation = @import("../../Compilation.zig");
47const Md5 = std.crypto.hash.Md5;
48const Hasher = @import("hasher.zig").ParallelHasher;
src/link/MappedFile.zig+14-11
...@@ -1,3 +1,15 @@...@@ -1,3 +1,15 @@
1const MappedFile = @This();
2
3const builtin = @import("builtin");
4const is_linux = builtin.os.tag == .linux;
5const is_windows = builtin.os.tag == .windows;
6
7const std = @import("std");
8const Io = std.Io;
9const assert = std.debug.assert;
10const linux = std.os.linux;
11const windows = std.os.windows;
12
1file: std.Io.File,13file: std.Io.File,
2flags: packed struct {14flags: packed struct {
3 block_size: std.mem.Alignment,15 block_size: std.mem.Alignment,
...@@ -16,7 +28,7 @@ writers: std.SinglyLinkedList,...@@ -16,7 +28,7 @@ writers: std.SinglyLinkedList,
1628
17pub const growth_factor = 4;29pub const growth_factor = 4;
1830
19pub const Error = std.posix.MMapError || std.posix.MRemapError || std.fs.File.SetEndPosError || error{31pub const Error = std.posix.MMapError || std.posix.MRemapError || Io.File.SetEndPosError || error{
20 NotFile,32 NotFile,
21 SystemResources,33 SystemResources,
22 IsDir,34 IsDir,
...@@ -618,7 +630,7 @@ fn resizeNode(mf: *MappedFile, gpa: std.mem.Allocator, ni: Node.Index, requested...@@ -618,7 +630,7 @@ fn resizeNode(mf: *MappedFile, gpa: std.mem.Allocator, ni: Node.Index, requested
618 // Resize the entire file630 // Resize the entire file
619 if (ni == Node.Index.root) {631 if (ni == Node.Index.root) {
620 try mf.ensureCapacityForSetLocation(gpa);632 try mf.ensureCapacityForSetLocation(gpa);
621 try std.fs.File.adaptFromNewApi(mf.file).setEndPos(new_size);633 try Io.File.adaptFromNewApi(mf.file).setEndPos(new_size);
622 try mf.ensureTotalCapacity(@intCast(new_size));634 try mf.ensureTotalCapacity(@intCast(new_size));
623 ni.setLocationAssumeCapacity(mf, old_offset, new_size);635 ni.setLocationAssumeCapacity(mf, old_offset, new_size);
624 return;636 return;
...@@ -1059,12 +1071,3 @@ fn verifyNode(mf: *MappedFile, parent_ni: Node.Index) void {...@@ -1059,12 +1071,3 @@ fn verifyNode(mf: *MappedFile, parent_ni: Node.Index) void {
1059 ni = node.next;1071 ni = node.next;
1060 }1072 }
1061}1073}
1062
1063const assert = std.debug.assert;
1064const builtin = @import("builtin");
1065const is_linux = builtin.os.tag == .linux;
1066const is_windows = builtin.os.tag == .windows;
1067const linux = std.os.linux;
1068const MappedFile = @This();
1069const std = @import("std");
1070const windows = std.os.windows;
src/link/Wasm.zig+3-2
...@@ -20,6 +20,7 @@ const native_endian = builtin.cpu.arch.endian();...@@ -20,6 +20,7 @@ const native_endian = builtin.cpu.arch.endian();
20const build_options = @import("build_options");20const build_options = @import("build_options");
2121
22const std = @import("std");22const std = @import("std");
23const Io = std.Io;
23const Allocator = std.mem.Allocator;24const Allocator = std.mem.Allocator;
24const Cache = std.Build.Cache;25const Cache = std.Build.Cache;
25const Path = Cache.Path;26const Path = Cache.Path;
...@@ -3001,9 +3002,9 @@ pub fn createEmpty(...@@ -3001,9 +3002,9 @@ pub fn createEmpty(
3001 .read = true,3002 .read = true,
3002 .mode = if (fs.has_executable_bit)3003 .mode = if (fs.has_executable_bit)
3003 if (target.os.tag == .wasi and output_mode == .Exe)3004 if (target.os.tag == .wasi and output_mode == .Exe)
3004 fs.File.default_mode | 0b001_000_0003005 Io.File.default_mode | 0b001_000_000
3005 else3006 else
3006 fs.File.default_mode3007 Io.File.default_mode
3007 else3008 else
3008 0,3009 0,
3009 });3010 });
src/link/tapi.zig+5-5
...@@ -1,10 +1,10 @@...@@ -1,10 +1,10 @@
1const std = @import("std");1const std = @import("std");
2const fs = std.fs;2const Io = std.Io;
3const mem = std.mem;3const mem = std.mem;
4const log = std.log.scoped(.tapi);4const log = std.log.scoped(.tapi);
5const yaml = @import("tapi/yaml.zig");5const Allocator = std.mem.Allocator;
66
7const Allocator = mem.Allocator;7const yaml = @import("tapi/yaml.zig");
8const Yaml = yaml.Yaml;8const Yaml = yaml.Yaml;
99
10const VersionField = union(enum) {10const VersionField = union(enum) {
...@@ -130,7 +130,7 @@ pub const Tbd = union(enum) {...@@ -130,7 +130,7 @@ pub const Tbd = union(enum) {
130pub const TapiError = error{130pub const TapiError = error{
131 NotLibStub,131 NotLibStub,
132 InputOutput,132 InputOutput,
133} || yaml.YamlError || std.fs.File.PReadError;133} || yaml.YamlError || Io.File.PReadError;
134134
135pub const LibStub = struct {135pub const LibStub = struct {
136 /// Underlying memory for stub's contents.136 /// Underlying memory for stub's contents.
...@@ -139,7 +139,7 @@ pub const LibStub = struct {...@@ -139,7 +139,7 @@ pub const LibStub = struct {
139 /// Typed contents of the tbd file.139 /// Typed contents of the tbd file.
140 inner: []Tbd,140 inner: []Tbd,
141141
142 pub fn loadFromFile(allocator: Allocator, file: fs.File) TapiError!LibStub {142 pub fn loadFromFile(allocator: Allocator, file: Io.File) TapiError!LibStub {
143 const filesize = blk: {143 const filesize = blk: {
144 const stat = file.stat() catch break :blk std.math.maxInt(u32);144 const stat = file.stat() catch break :blk std.math.maxInt(u32);
145 break :blk @min(stat.size, std.math.maxInt(u32));145 break :blk @min(stat.size, std.math.maxInt(u32));