Skip to content

Commit

Permalink
std: Convert deprecated aliases to compile errors and fix usages
Browse files Browse the repository at this point in the history
  • Loading branch information
squeek502 committed May 3, 2024
1 parent e8dd79c commit d29bdec
Show file tree
Hide file tree
Showing 63 changed files with 173 additions and 190 deletions.
4 changes: 2 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const stack_size = 32 * 1024 * 1024;
pub fn build(b: *std.Build) !void {
const only_c = b.option(bool, "only-c", "Translate the Zig compiler to C code, with only the C backend enabled") orelse false;
const target = t: {
var default_target: std.zig.CrossTarget = .{};
var default_target: std.Target.Query = .{};
default_target.ofmt = b.option(std.Target.ObjectFormat, "ofmt", "Object format to target") orelse if (only_c) .c else null;
break :t b.standardTargetOptions(.{ .default_target = default_target });
};
Expand Down Expand Up @@ -554,7 +554,7 @@ pub fn build(b: *std.Build) !void {
fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
const semver = try std.SemanticVersion.parse(version);

var target_query: std.zig.CrossTarget = .{
var target_query: std.Target.Query = .{
.cpu_arch = .wasm32,
.os_tag = .wasi,
};
Expand Down
4 changes: 2 additions & 2 deletions lib/compiler/aro/aro/Driver.zig
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ pub fn invokeLinker(d: *Driver, tc: *Toolchain, comptime fast_exit: bool) !void
var argv = std.ArrayList([]const u8).init(d.comp.gpa);
defer argv.deinit();

var linker_path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
var linker_path_buf: [std.fs.max_path_bytes]u8 = undefined;
const linker_path = try tc.getLinkerPath(&linker_path_buf);
try argv.append(linker_path);

Expand All @@ -803,7 +803,7 @@ pub fn invokeLinker(d: *Driver, tc: *Toolchain, comptime fast_exit: bool) !void
return d.fatal("unable to dump linker args: {s}", .{errorDescription(er)});
};
}
var child = std.ChildProcess.init(argv.items, d.comp.gpa);
var child = std.process.Child.init(argv.items, d.comp.gpa);
// TODO handle better
child.stdin_behavior = .Inherit;
child.stdout_behavior = .Inherit;
Expand Down
4 changes: 2 additions & 2 deletions lib/compiler/aro/aro/Driver/Filesystem.zig
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn canExecuteFake(entries: []const Filesystem.Entry, path: []const u8) bool {

fn existsFake(entries: []const Filesystem.Entry, path: []const u8) bool {
@setCold(true);
var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
var buf: [std.fs.max_path_bytes]u8 = undefined;
var fib = std.heap.FixedBufferAllocator.init(&buf);
const resolved = std.fs.path.resolvePosix(fib.allocator(), &.{path}) catch return false;
for (entries) |entry| {
Expand Down Expand Up @@ -181,7 +181,7 @@ pub const Filesystem = union(enum) {
}

pub fn joinedExists(fs: Filesystem, parts: []const []const u8) bool {
var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
var buf: [std.fs.max_path_bytes]u8 = undefined;
var fib = std.heap.FixedBufferAllocator.init(&buf);
const joined = std.fs.path.join(fib.allocator(), parts) catch return false;
return fs.exists(joined);
Expand Down
4 changes: 2 additions & 2 deletions lib/compiler/aro/aro/Driver/GCCDetector.zig
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ fn collectLibDirsAndTriples(
}

pub fn discover(self: *GCCDetector, tc: *Toolchain) !void {
var path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
var path_buf: [std.fs.max_path_bytes]u8 = undefined;
var fib = std.heap.FixedBufferAllocator.init(&path_buf);

const target = tc.getTarget();
Expand Down Expand Up @@ -589,7 +589,7 @@ fn scanLibDirForGCCTriple(
gcc_dir_exists: bool,
gcc_cross_dir_exists: bool,
) !void {
var path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
var path_buf: [std.fs.max_path_bytes]u8 = undefined;
var fib = std.heap.FixedBufferAllocator.init(&path_buf);
for (0..2) |i| {
if (i == 0 and !gcc_dir_exists) continue;
Expand Down
6 changes: 3 additions & 3 deletions lib/compiler/aro/aro/Toolchain.zig
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pub fn addFilePathLibArgs(tc: *const Toolchain, argv: *std.ArrayList([]const u8)
/// If not found there, just use `name`
/// Writes the result to `buf` and returns a slice of it
fn getProgramPath(tc: *const Toolchain, name: []const u8, buf: []u8) []const u8 {
var path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
var path_buf: [std.fs.max_path_bytes]u8 = undefined;
var fib = std.heap.FixedBufferAllocator.init(&path_buf);

var tool_specific_buf: [64]u8 = undefined;
Expand Down Expand Up @@ -251,7 +251,7 @@ pub fn getSysroot(tc: *const Toolchain) []const u8 {
/// Search for `name` in a variety of places
/// TODO: cache results based on `name` so we're not repeatedly allocating the same strings?
pub fn getFilePath(tc: *const Toolchain, name: []const u8) ![]const u8 {
var path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
var path_buf: [std.fs.max_path_bytes]u8 = undefined;
var fib = std.heap.FixedBufferAllocator.init(&path_buf);
const allocator = fib.allocator();

Expand Down Expand Up @@ -304,7 +304,7 @@ const PathKind = enum {
/// Join `components` into a path. If the path exists, dupe it into the toolchain arena and
/// add it to the specified path list.
pub fn addPathIfExists(tc: *Toolchain, components: []const []const u8, dest_kind: PathKind) !void {
var path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
var path_buf: [std.fs.max_path_bytes]u8 = undefined;
var fib = std.heap.FixedBufferAllocator.init(&path_buf);

const candidate = try std.fs.path.join(fib.allocator(), components);
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler/aro/aro/Value.zig
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ pub fn printString(bytes: []const u8, ty: Type, comp: *const Compilation, w: any
switch (size) {
inline .@"1", .@"2" => |sz| {
const data_slice: []const sz.Type() = @alignCast(std.mem.bytesAsSlice(sz.Type(), without_null));
const formatter = if (sz == .@"1") std.zig.fmtEscapes(data_slice) else std.unicode.fmtUtf16le(data_slice);
const formatter = if (sz == .@"1") std.zig.fmtEscapes(data_slice) else std.unicode.fmtUtf16Le(data_slice);
try w.print("\"{}\"", .{formatter});
},
.@"4" => {
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler/aro/aro/toolchains/Linux.zig
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ test Linux {
var argv = std.ArrayList([]const u8).init(driver.comp.gpa);
defer argv.deinit();

var linker_path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
var linker_path_buf: [std.fs.max_path_bytes]u8 = undefined;
const linker_path = try toolchain.getLinkerPath(&linker_path_buf);
try argv.append(linker_path);

Expand Down
2 changes: 1 addition & 1 deletion lib/compiler/resinator/cli.zig
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn
arg_i += 1;
break :next_arg;
};
var tokenizer = std.mem.tokenize(u8, value.slice, "=");
var tokenizer = std.mem.tokenizeScalar(u8, value.slice, '=');
// guaranteed to exist since an empty value.slice would invoke
// the 'missing symbol to define' branch above
const symbol = tokenizer.next().?;
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler/resinator/compile.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3405,7 +3405,7 @@ test "StringTable" {
}
break :ids buf;
};
var prng = std.rand.DefaultPrng.init(0);
var prng = std.Random.DefaultPrng.init(0);
var random = prng.random();
random.shuffle(u16, &ids);

Expand Down
2 changes: 1 addition & 1 deletion lib/compiler/resinator/source_mapping.zig
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ pub fn handleLineEnd(allocator: Allocator, post_processed_line_number: usize, ma
// TODO: Might want to provide diagnostics on invalid line commands instead of just returning
pub fn handleLineCommand(allocator: Allocator, line_command: []const u8, current_mapping: *CurrentMapping) error{OutOfMemory}!void {
// TODO: Are there other whitespace characters that should be included?
var tokenizer = std.mem.tokenize(u8, line_command, " \t");
var tokenizer = std.mem.tokenizeAny(u8, line_command, " \t");
const line_directive = tokenizer.next() orelse return; // #line
if (!std.mem.eql(u8, line_directive, "#line")) return;
const linenum_str = tokenizer.next() orelse return;
Expand Down
4 changes: 2 additions & 2 deletions lib/compiler/std-docs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ fn buildWasmBinary(
"--listen=-",
});

var child = std.ChildProcess.init(argv.items, gpa);
var child = std.process.Child.init(argv.items, gpa);
child.stdin_behavior = .Pipe;
child.stdout_behavior = .Pipe;
child.stderr_behavior = .Pipe;
Expand Down Expand Up @@ -435,7 +435,7 @@ fn openBrowserTabThread(gpa: Allocator, url: []const u8) !void {
.windows => "explorer",
else => "xdg-open",
};
var child = std.ChildProcess.init(&.{ main_exe, url }, gpa);
var child = std.process.Child.init(&.{ main_exe, url }, gpa);
child.stdin_behavior = .Ignore;
child.stdout_behavior = .Ignore;
child.stderr_behavior = .Ignore;
Expand Down
2 changes: 1 addition & 1 deletion lib/docs/wasm/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ fn unindent(s: []const u8, indent: usize) []const u8 {
}

fn appendUnindented(out: *std.ArrayListUnmanaged(u8), s: []const u8, indent: usize) !void {
var it = std.mem.split(u8, s, "\n");
var it = std.mem.splitScalar(u8, s, '\n');
var is_first_line = true;
while (it.next()) |line| {
if (is_first_line) {
Expand Down
2 changes: 1 addition & 1 deletion lib/docs/wasm/markdown.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ fn testRender(input: []const u8, expected: []const u8) !void {
var parser = try Parser.init(testing.allocator);
defer parser.deinit();

var lines = std.mem.split(u8, input, "\n");
var lines = std.mem.splitScalar(u8, input, '\n');
while (lines.next()) |line| {
try parser.feedLine(line);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/std/Build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ pub const RunError = error{
ExitCodeFailure,
ProcessTerminated,
ExecNotSupported,
} || std.ChildProcess.SpawnError;
} || std.process.Child.SpawnError;

pub const PkgConfigError = error{
PkgConfigCrashed,
Expand Down Expand Up @@ -1717,15 +1717,15 @@ pub fn runAllowFail(
self: *Build,
argv: []const []const u8,
out_code: *u8,
stderr_behavior: std.ChildProcess.StdIo,
stderr_behavior: std.process.Child.StdIo,
) RunError![]u8 {
assert(argv.len != 0);

if (!process.can_spawn)
return error.ExecNotSupported;

const max_output_size = 400 * 1024;
var child = std.ChildProcess.init(argv, self.allocator);
var child = std.process.Child.init(argv, self.allocator);
child.stdin_behavior = .Ignore;
child.stdout_behavior = .Pipe;
child.stderr_behavior = stderr_behavior;
Expand Down
12 changes: 6 additions & 6 deletions lib/std/Build/Cache/Path.zig
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn openFile(
sub_path: []const u8,
flags: fs.File.OpenFlags,
) !fs.File {
var buf: [fs.MAX_PATH_BYTES]u8 = undefined;
var buf: [fs.max_path_bytes]u8 = undefined;
const joined_path = if (p.sub_path.len == 0) sub_path else p: {
break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{
p.sub_path, sub_path,
Expand All @@ -59,7 +59,7 @@ pub fn openFile(
}

pub fn makeOpenPath(p: Path, sub_path: []const u8, opts: fs.OpenDirOptions) !fs.Dir {
var buf: [fs.MAX_PATH_BYTES]u8 = undefined;
var buf: [fs.max_path_bytes]u8 = undefined;
const joined_path = if (p.sub_path.len == 0) sub_path else p: {
break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{
p.sub_path, sub_path,
Expand All @@ -69,7 +69,7 @@ pub fn makeOpenPath(p: Path, sub_path: []const u8, opts: fs.OpenDirOptions) !fs.
}

pub fn statFile(p: Path, sub_path: []const u8) !fs.Dir.Stat {
var buf: [fs.MAX_PATH_BYTES]u8 = undefined;
var buf: [fs.max_path_bytes]u8 = undefined;
const joined_path = if (p.sub_path.len == 0) sub_path else p: {
break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{
p.sub_path, sub_path,
Expand All @@ -82,7 +82,7 @@ pub fn atomicFile(
p: Path,
sub_path: []const u8,
options: fs.Dir.AtomicFileOptions,
buf: *[fs.MAX_PATH_BYTES]u8,
buf: *[fs.max_path_bytes]u8,
) !fs.AtomicFile {
const joined_path = if (p.sub_path.len == 0) sub_path else p: {
break :p std.fmt.bufPrint(buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{
Expand All @@ -93,7 +93,7 @@ pub fn atomicFile(
}

pub fn access(p: Path, sub_path: []const u8, flags: fs.File.OpenFlags) !void {
var buf: [fs.MAX_PATH_BYTES]u8 = undefined;
var buf: [fs.max_path_bytes]u8 = undefined;
const joined_path = if (p.sub_path.len == 0) sub_path else p: {
break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{
p.sub_path, sub_path,
Expand All @@ -103,7 +103,7 @@ pub fn access(p: Path, sub_path: []const u8, flags: fs.File.OpenFlags) !void {
}

pub fn makePath(p: Path, sub_path: []const u8) !void {
var buf: [fs.MAX_PATH_BYTES]u8 = undefined;
var buf: [fs.max_path_bytes]u8 = undefined;
const joined_path = if (p.sub_path.len == 0) sub_path else p: {
break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{
p.sub_path, sub_path,
Expand Down
6 changes: 3 additions & 3 deletions lib/std/Build/Step.zig
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ pub fn evalChildProcess(s: *Step, argv: []const []const u8) !void {
try handleChildProcUnsupported(s, null, argv);
try handleVerbose(s.owner, null, argv);

const result = std.ChildProcess.run(.{
const result = std.process.Child.run(.{
.allocator = arena,
.argv = argv,
}) catch |err| return s.fail("unable to spawn {s}: {s}", .{ argv[0], @errorName(err) });
Expand Down Expand Up @@ -313,7 +313,7 @@ pub fn evalZigProcess(
try handleChildProcUnsupported(s, null, argv);
try handleVerbose(s.owner, null, argv);

var child = std.ChildProcess.init(argv, arena);
var child = std.process.Child.init(argv, arena);
child.env_map = &b.graph.env_map;
child.stdin_behavior = .Pipe;
child.stdout_behavior = .Pipe;
Expand Down Expand Up @@ -480,7 +480,7 @@ pub inline fn handleChildProcUnsupported(

pub fn handleChildProcessTerm(
s: *Step,
term: std.ChildProcess.Term,
term: std.process.Child.Term,
opt_cwd: ?[]const u8,
argv: []const []const u8,
) error{ MakeFailed, OutOfMemory }!void {
Expand Down
2 changes: 1 addition & 1 deletion lib/std/Random.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const math = std.math;
const mem = std.mem;
const assert = std.debug.assert;
const maxInt = std.math.maxInt;
pub const Random = @This(); // Remove pub when `std.rand` namespace is removed.
const Random = @This();

/// Fast unbiased random numbers.
pub const DefaultPrng = Xoshiro256;
Expand Down
2 changes: 1 addition & 1 deletion lib/std/debug.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,7 @@ pub fn readElfDebugInfo(
if (readElfDebugInfo(allocator, path, null, separate_debug_crc, &sections, mapped_mem)) |debug_info| return debug_info else |_| {}
}

var cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;
var cwd_buf: [fs.max_path_bytes]u8 = undefined;
const cwd_path = posix.realpath(".", &cwd_buf) catch break :blk;

// <global debug directory>/<absolute folder of current binary>/<gnu_debuglink>
Expand Down

0 comments on commit d29bdec

Please sign in to comment.