Skip to content

Commit f2df8a2

Browse files
committed
remove usage of deprecated standard library APIs
1 parent 33a18cf commit f2df8a2

27 files changed

Lines changed: 97 additions & 92 deletions

src/DiagnosticsCollection.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,11 @@ fn collectUrisFromErrorBundle(
253253
}
254254

255255
fn pathToUri(allocator: std.mem.Allocator, base_path: ?[]const u8, src_path: []const u8) error{OutOfMemory}!?Uri {
256-
if (std.fs.path.isAbsolute(src_path)) {
256+
if (std.Io.Dir.path.isAbsolute(src_path)) {
257257
return try .fromPath(allocator, src_path);
258258
}
259259
const base = base_path orelse return null;
260-
const absolute_src_path = try std.fs.path.join(allocator, &.{ base, src_path });
260+
const absolute_src_path = try std.Io.Dir.path.join(allocator, &.{ base, src_path });
261261
defer allocator.free(absolute_src_path);
262262

263263
return try .fromPath(allocator, absolute_src_path);

src/DocumentStore.zig

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ pub const Handle = struct {
414414
const tracy_zone = tracy.traceNamed(@src(), "Handle.refresh");
415415
defer tracy_zone.end();
416416

417-
const mode: Ast.Mode = if (std.mem.eql(u8, std.fs.path.extension(handle.uri.raw), ".zon")) .zon else .zig;
417+
const mode: Ast.Mode = if (std.mem.eql(u8, std.Io.Dir.path.extension(handle.uri.raw), ".zon")) .zon else .zig;
418418
var new_tree = try parseTree(allocator, text, mode);
419419
errdefer new_tree.deinit(allocator);
420420

@@ -847,7 +847,7 @@ pub fn openLspSyncedDocument(self: *DocumentStore, uri: Uri, text: []const u8) e
847847
}
848848
}
849849

850-
const duped_text = try self.allocator.dupeZ(u8, text);
850+
const duped_text = try self.allocator.dupeSentinel(u8, text, 0);
851851
_ = self.createAndStoreDocument(
852852
uri,
853853
.{ .text = duped_text },
@@ -1013,11 +1013,11 @@ pub fn loadDirectoryRecursive(store: *DocumentStore, directory_uri: Uri) LoadDir
10131013
}
10141014
continue;
10151015
}
1016-
if (!std.mem.eql(u8, std.fs.path.extension(entry.basename), ".zig")) continue;
1016+
if (!std.mem.eql(u8, std.Io.Dir.path.extension(entry.basename), ".zig")) continue;
10171017

10181018
file_count += 1;
10191019

1020-
const path = try std.fs.path.join(store.allocator, &.{ workspace_path, entry.path });
1020+
const path = try std.Io.Dir.path.join(store.allocator, &.{ workspace_path, entry.path });
10211021
defer store.allocator.free(path);
10221022

10231023
const uri: Uri = try .fromPath(store.allocator, path);
@@ -1046,7 +1046,7 @@ pub fn loadTrigramStores(
10461046
while (it.next()) |handle| {
10471047
const uri = handle.uri.toStdUri();
10481048

1049-
var component_it = std.fs.path.componentIterator(uri.path.percent_encoded);
1049+
var component_it = std.Io.Dir.path.componentIterator(uri.path.percent_encoded);
10501050
const skip = while (component_it.next()) |component| {
10511051
// Keep in sync with `loadDirectoryRecursive`
10521052
if (std.mem.startsWith(u8, component.name, ".")) break true;
@@ -1305,7 +1305,7 @@ fn loadBuildAssociatedConfiguration(io: std.Io, allocator: std.mem.Allocator, bu
13051305

13061306
const build_file_path = try build_file.uri.toFsPath(allocator);
13071307
defer allocator.free(build_file_path);
1308-
const config_file_path = try std.fs.path.resolve(allocator, &.{ build_file_path, "..", "zls.build.json" });
1308+
const config_file_path = try std.Io.Dir.path.resolve(allocator, &.{ build_file_path, "..", "zls.build.json" });
13091309
defer allocator.free(config_file_path);
13101310

13111311
const file_buf = try std.Io.Dir.cwd().readFileAlloc(
@@ -1373,7 +1373,7 @@ fn loadBuildConfiguration(self: *DocumentStore, build_file_uri: Uri, build_file_
13731373
const build_file_path = try build_file_uri.toFsPath(self.allocator);
13741374
defer self.allocator.free(build_file_path);
13751375

1376-
const cwd = std.fs.path.dirname(build_file_path).?;
1376+
const cwd = std.Io.Dir.path.dirname(build_file_path).?;
13771377

13781378
const args = try self.prepareBuildRunnerArgs(build_file_uri);
13791379
defer {
@@ -1489,16 +1489,16 @@ fn collectPotentialBuildFiles(self: *DocumentStore, uri: Uri) error{ Canceled, O
14891489
// https://github.com/ziglang/zig/issues/15607
14901490
const root_end_index: usize = root_end_index: {
14911491
if (builtin.target.os.tag != .windows) break :root_end_index 0;
1492-
const component_iterator = std.fs.path.componentIterator(path);
1492+
const component_iterator = std.Io.Dir.path.componentIterator(path);
14931493
break :root_end_index component_iterator.root_end_index;
14941494
};
14951495

14961496
var current_path: []const u8 = path;
1497-
while (std.fs.path.dirname(current_path)) |potential_root_path| : (current_path = potential_root_path) {
1497+
while (std.Io.Dir.path.dirname(current_path)) |potential_root_path| : (current_path = potential_root_path) {
14981498
if (potential_root_path.len < root_end_index) break;
14991499
if (!try buildDotZigExists(self.io, potential_root_path)) continue;
15001500

1501-
const build_path = try std.fs.path.join(self.allocator, &.{ potential_root_path, "build.zig" });
1501+
const build_path = try std.Io.Dir.path.join(self.allocator, &.{ potential_root_path, "build.zig" });
15021502
defer self.allocator.free(build_path);
15031503

15041504
try potential_build_files.ensureUnusedCapacity(self.allocator, 1);
@@ -1534,7 +1534,7 @@ fn createBuildFile(self: *DocumentStore, uri: Uri) error{ Canceled, OutOfMemory
15341534

15351535
if (cfg.value.relative_builtin_path) |relative_builtin_path| blk: {
15361536
const build_file_path = build_file.uri.toFsPath(self.allocator) catch break :blk;
1537-
const absolute_builtin_path = try std.fs.path.resolve(self.allocator, &.{ build_file_path, "..", relative_builtin_path });
1537+
const absolute_builtin_path = try std.Io.Dir.path.resolve(self.allocator, &.{ build_file_path, "..", relative_builtin_path });
15381538
defer self.allocator.free(absolute_builtin_path);
15391539
build_file.builtin_uri = try .fromPath(self.allocator, absolute_builtin_path);
15401540
}
@@ -1731,15 +1731,15 @@ pub fn collectIncludeDirs(
17311731

17321732
try include_dirs.ensureUnusedCapacity(allocator, module.include_dirs.len);
17331733
for (module.include_dirs) |include_path| {
1734-
const absolute_path = if (std.fs.path.isAbsolute(include_path))
1734+
const absolute_path = if (std.Io.Dir.path.isAbsolute(include_path))
17351735
try allocator.dupe(u8, include_path)
17361736
else blk: {
17371737
const build_file_path = resolved.build_file.uri.toFsPath(allocator) catch |err| switch (err) {
17381738
error.OutOfMemory => return error.OutOfMemory,
17391739
error.UnsupportedScheme => continue,
17401740
};
1741-
const build_file_dirname = std.fs.path.dirname(build_file_path) orelse continue;
1742-
break :blk try std.fs.path.join(allocator, &.{ build_file_dirname, include_path });
1741+
const build_file_dirname = std.Io.Dir.path.dirname(build_file_path) orelse continue;
1742+
break :blk try std.Io.Dir.path.join(allocator, &.{ build_file_dirname, include_path });
17431743
};
17441744

17451745
include_dirs.appendAssumeCapacity(absolute_path);

src/Server.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -739,14 +739,14 @@ fn handleConfiguration(server: *Server, json: std.json.Value) error{ Canceled, O
739739
const field: *?[]const u8 = &@field(new_config, file_config.name);
740740
if (field.*) |maybe_relative| resolve: {
741741
if (maybe_relative.len == 0) break :resolve;
742-
if (std.fs.path.isAbsolute(maybe_relative)) break :resolve;
742+
if (std.Io.Dir.path.isAbsolute(maybe_relative)) break :resolve;
743743

744744
const root_dir = maybe_root_dir orelse {
745745
log.err("relative path only supported for {s} with exactly one workspace", .{runtime_known_config_name});
746746
break;
747747
};
748748

749-
const absolute = try std.fs.path.resolve(arena, &.{
749+
const absolute = try std.Io.Dir.path.resolve(arena, &.{
750750
root_dir, maybe_relative,
751751
});
752752

@@ -902,7 +902,7 @@ fn didChangeWatchedFilesHandler(server: *Server, arena: std.mem.Allocator, notif
902902
error.OutOfMemory => return error.OutOfMemory,
903903
else => return error.InvalidParams,
904904
};
905-
const file_extension = std.fs.path.extension(uri.raw);
905+
const file_extension = std.Io.Dir.path.extension(uri.raw);
906906
if (!std.mem.eql(u8, file_extension, ".zig") and !std.mem.eql(u8, file_extension, ".zon")) continue;
907907

908908
switch (change.type) {

src/Uri.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ fn fromPathWithOs(
198198
buf.appendSliceAssumeCapacity("file:");
199199
if (is_windows and
200200
path.len >= 2 and
201-
std.fs.path.PathType.isSep(.windows, u8, path[0]) and
202-
std.fs.path.PathType.isSep(.windows, u8, path[1]))
201+
std.Io.Dir.path.PathType.isSep(.windows, u8, path[0]) and
202+
std.Io.Dir.path.PathType.isSep(.windows, u8, path[1]))
203203
{
204204
// UNC path
205205
} else if (!std.mem.startsWith(u8, path, "/")) {
@@ -449,7 +449,7 @@ pub fn resolveImport(
449449
std.Uri.Component.percentEncode(&aw.writer, sub_path, isPathChar) catch unreachable;
450450

451451
const percent_encoded_path = parsed_uri.path.percent_encoded;
452-
const joined_path = try std.fs.path.resolvePosix(allocator, &.{ percent_encoded_path, "..", aw.written() });
452+
const joined_path = try std.Io.Dir.path.resolvePosix(allocator, &.{ percent_encoded_path, "..", aw.written() });
453453
defer allocator.free(joined_path);
454454

455455
var buffer = aw.toArrayList();

src/analyser/InternPool.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ pub const Key = union(enum) {
426426
=> |a_data, t| {
427427
const b_data = @field(b, @tagName(t));
428428

429-
const Int = std.meta.Int(.unsigned, @bitSizeOf(@TypeOf(a_data)));
429+
const Int = @Int(.unsigned, @bitSizeOf(@TypeOf(a_data)));
430430
return @as(Int, @bitCast(a_data)) == @as(Int, @bitCast(b_data));
431431
},
432432

src/analyser/string_pool.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub fn StringPool(comptime config: Config) type {
127127
defer pool.mutex.unlock(io);
128128
const string_bytes: [*:0]u8 = @ptrCast(pool.bytes.items.ptr);
129129
const start = @intFromEnum(index);
130-
return try allocator.dupeZ(u8, std.mem.sliceTo(string_bytes + start, 0));
130+
return try allocator.dupeSentinel(u8, std.mem.sliceTo(string_bytes + start, 0), 0);
131131
}
132132

133133
/// storage a slice that points into the internal storage of the `StringPool`.

src/analysis.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,7 +1729,7 @@ fn resolveCallsiteReferences(analyser: *Analyser, decl_handle: DeclWithHandle) E
17291729
};
17301730

17311731
const tree = &decl_handle.handle.tree;
1732-
const is_cimport = std.mem.eql(u8, std.fs.path.basename(decl_handle.handle.uri.raw), "cimport.zig");
1732+
const is_cimport = std.mem.eql(u8, std.Io.Dir.path.basename(decl_handle.handle.uri.raw), "cimport.zig");
17331733

17341734
if (is_cimport or !analyser.collect_callsite_references) return null;
17351735

@@ -4632,7 +4632,7 @@ pub const Type = struct {
46324632
error.OutOfMemory => return error.OutOfMemory,
46334633
error.UnsupportedScheme => handle.uri.raw,
46344634
};
4635-
const str = std.fs.path.stem(path);
4635+
const str = std.Io.Dir.path.stem(path);
46364636
try writer.writeAll(str);
46374637
if (referenced) |r| try r.put(analyser.arena, .of(str, handle, tree.firstToken(node)), {});
46384638
},
@@ -4954,7 +4954,7 @@ pub fn getFieldAccessType(
49544954
source_index: usize,
49554955
loc: offsets.Loc,
49564956
) Error!?Type {
4957-
const held_range = try analyser.arena.dupeZ(u8, offsets.locToSlice(handle.tree.source, loc));
4957+
const held_range = try analyser.arena.dupeSentinel(u8, offsets.locToSlice(handle.tree.source, loc), 0);
49584958
var tokenizer: std.zig.Tokenizer = .init(held_range);
49594959
var current_type: ?Type = null;
49604960

src/build_runner/build_runner.zig

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub fn main(init: process.Init.Minimal) !void {
148148
const option_contents = arg[2..];
149149
if (option_contents.len == 0)
150150
fatalWithHint("expected option name after '-D'", .{});
151-
if (mem.indexOfScalar(u8, option_contents, '=')) |name_end| {
151+
if (mem.findScalar(u8, option_contents, '=')) |name_end| {
152152
const option_name = option_contents[0..name_end];
153153
const option_value = option_contents[name_end + 1 ..];
154154
if (try builder.addUserInputOption(option_name, option_value))
@@ -369,7 +369,7 @@ pub fn main(init: process.Init.Minimal) !void {
369369
try buffer.appendSlice(arena, k);
370370
try buffer.append(arena, '\n');
371371
}
372-
const s = std.fs.path.sep_str;
372+
const s = std.Io.Dir.path.sep_str;
373373
const tmp_sub_path = "tmp" ++ s ++ (output_tmp_nonce orelse fatal("missing -Z arg", .{}));
374374
local_cache_directory.handle.writeFile(io, .{
375375
.sub_path = tmp_sub_path,
@@ -572,7 +572,7 @@ fn resolveStepNames(
572572
step_names: []const []const u8,
573573
check_step_only: bool,
574574
) !std.AutoArrayHashMapUnmanaged(*Step, void) {
575-
var starting_steps: std.AutoArrayHashMapUnmanaged(*Step, void) = .{};
575+
var starting_steps: std.AutoArrayHashMapUnmanaged(*Step, void) = .empty;
576576
errdefer starting_steps.deinit(gpa);
577577

578578
if (step_names.len == 0) {
@@ -1064,7 +1064,7 @@ fn extractBuildInformation(
10641064
if (other.generated_h) |header| {
10651065
try include_dirs.put(
10661066
allocator,
1067-
std.fs.path.dirname(header.getPath()).?,
1067+
std.Io.Dir.path.dirname(header.getPath()).?,
10681068
{},
10691069
);
10701070
}
@@ -1091,7 +1091,7 @@ fn extractBuildInformation(
10911091

10921092
const cwd = module.owner.graph.cache.cwd;
10931093

1094-
const root_source_file_path = try std.fs.path.resolve(allocator, &.{ cwd, root_source_file.getPath2(module.owner, null) });
1094+
const root_source_file_path = try std.Io.Dir.path.resolve(allocator, &.{ cwd, root_source_file.getPath2(module.owner, null) });
10951095

10961096
// All modules with the same root source file are merged. This limitation may be lifted in the future.
10971097
const gop = try modules.getOrPutValue(allocator, root_source_file_path, .{
@@ -1105,7 +1105,7 @@ fn extractBuildInformation(
11051105
const gop_import = try gop.value_ptr.import_table.map.getOrPut(allocator, name);
11061106
// This does not account for the possibility of collisions (i.e. modules with same root source file import different modules under the same name).
11071107
if (!gop_import.found_existing) {
1108-
gop_import.value_ptr.* = try std.fs.path.resolve(allocator, &.{ cwd, import_root_source_file.getPath2(import.owner, null) });
1108+
gop_import.value_ptr.* = try std.Io.Dir.path.resolve(allocator, &.{ cwd, import_root_source_file.getPath2(import.owner, null) });
11091109
}
11101110
}
11111111
gop.value_ptr.c_macros = try std.mem.concat(allocator, []const u8, &.{ gop.value_ptr.c_macros, c_macros.keys() });
@@ -1221,7 +1221,7 @@ fn extractBuildInformation(
12211221
for (all_steps.keys()) |step| {
12221222
const compile = step.cast(Step.Compile) orelse continue;
12231223
const root_source_file = compile.root_module.root_source_file orelse continue;
1224-
const root_source_file_path = try std.fs.path.resolve(arena, &.{ b.graph.cache.cwd, root_source_file.getPath2(compile.root_module.owner, null) });
1224+
const root_source_file_path = try std.Io.Dir.path.resolve(arena, &.{ b.graph.cache.cwd, root_source_file.getPath2(compile.root_module.owner, null) });
12251225
try compilations.append(arena, .{
12261226
.root_module = root_source_file_path,
12271227
});
@@ -1252,7 +1252,7 @@ fn extractBuildInformation(
12521252
try root_dependencies.put(
12531253
arena,
12541254
root_dep[0],
1255-
try std.fs.path.join(arena, &.{ package_info.build_root, "build.zig" }),
1255+
try std.Io.Dir.path.join(arena, &.{ package_info.build_root, "build.zig" }),
12561256
);
12571257
}
12581258
}
@@ -1353,7 +1353,7 @@ const copied_from_zig = struct {
13531353

13541354
// Now try appending ".0".
13551355
for (pkgs) |pkg| {
1356-
if (std.ascii.indexOfIgnoreCase(pkg.name, lib_name)) |pos| {
1356+
if (std.ascii.findIgnoreCase(pkg.name, lib_name)) |pos| {
13571357
if (pos != 0) continue;
13581358
if (mem.eql(u8, pkg.name[lib_name.len..], ".0")) {
13591359
break :match pkg.name;

src/build_runner/shared.zig

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ pub const BuildOnSaveSupport = union(enum) {
131131

132132
/// Parses a Linux Kernel Version. The result will ignore pre-release and build metadata.
133133
fn parseUnameKernelVersion(kernel_version: []const u8) !std.SemanticVersion {
134-
const extra_index = std.mem.indexOfAny(u8, kernel_version, "-+");
134+
const extra_index = for (kernel_version, 0..) |c, i| {
135+
switch (c) {
136+
'-', '+' => break i,
137+
else => continue,
138+
}
139+
} else null;
135140
const required = kernel_version[0..(extra_index orelse kernel_version.len)];
136141
var it = std.mem.splitScalar(u8, required, '.');
137142
return .{

0 commit comments

Comments
 (0)