authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-11-30 00:13:07-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-11-30 00:13:07-07:00
log902df103c6151c257c90de9ba5f29f7f4b9dbea2
tree16a522f3c8bbe34b56038d4810bf2487e32e2d85
parent173d56213b60fc570b6ba3922ee1d40bbf0d0e36

std lib API deprecations for the upcoming 0.9.0 release

See #3811

101 files changed, 1225 insertions(+), 1561 deletions(-)

CMakeLists.txt+1-1
...@@ -534,7 +534,7 @@ set(ZIG_STAGE2_SOURCES...@@ -534,7 +534,7 @@ set(ZIG_STAGE2_SOURCES
534 "${CMAKE_SOURCE_DIR}/lib/std/unicode.zig"534 "${CMAKE_SOURCE_DIR}/lib/std/unicode.zig"
535 "${CMAKE_SOURCE_DIR}/lib/std/zig.zig"535 "${CMAKE_SOURCE_DIR}/lib/std/zig.zig"
536 "${CMAKE_SOURCE_DIR}/lib/std/zig/Ast.zig"536 "${CMAKE_SOURCE_DIR}/lib/std/zig/Ast.zig"
537 "${CMAKE_SOURCE_DIR}/lib/std/zig/cross_target.zig"537 "${CMAKE_SOURCE_DIR}/lib/std/zig/CrossTarget.zig"
538 "${CMAKE_SOURCE_DIR}/lib/std/zig/parse.zig"538 "${CMAKE_SOURCE_DIR}/lib/std/zig/parse.zig"
539 "${CMAKE_SOURCE_DIR}/lib/std/zig/render.zig"539 "${CMAKE_SOURCE_DIR}/lib/std/zig/render.zig"
540 "${CMAKE_SOURCE_DIR}/lib/std/zig/string_literal.zig"540 "${CMAKE_SOURCE_DIR}/lib/std/zig/string_literal.zig"
build.zig+3-4
...@@ -3,7 +3,6 @@ const builtin = std.builtin;...@@ -3,7 +3,6 @@ const builtin = std.builtin;
3const Builder = std.build.Builder;3const Builder = std.build.Builder;
4const tests = @import("test/tests.zig");4const tests = @import("test/tests.zig");
5const BufMap = std.BufMap;5const BufMap = std.BufMap;
6const warn = std.debug.warn;
7const mem = std.mem;6const mem = std.mem;
8const ArrayList = std.ArrayList;7const ArrayList = std.ArrayList;
9const io = std.io;8const io = std.io;
...@@ -558,9 +557,9 @@ fn addCxxKnownPath(...@@ -558,9 +557,9 @@ fn addCxxKnownPath(
558 const path_unpadded = mem.tokenize(u8, path_padded, "\r\n").next().?;557 const path_unpadded = mem.tokenize(u8, path_padded, "\r\n").next().?;
559 if (mem.eql(u8, path_unpadded, objname)) {558 if (mem.eql(u8, path_unpadded, objname)) {
560 if (errtxt) |msg| {559 if (errtxt) |msg| {
561 warn("{s}", .{msg});560 std.debug.print("{s}", .{msg});
562 } else {561 } else {
563 warn("Unable to determine path to {s}\n", .{objname});562 std.debug.print("Unable to determine path to {s}\n", .{objname});
564 }563 }
565 return error.RequiredLibraryNotFound;564 return error.RequiredLibraryNotFound;
566 }565 }
...@@ -687,7 +686,7 @@ fn findAndParseConfigH(b: *Builder, config_h_path_option: ?[]const u8) ?CMakeCon...@@ -687,7 +686,7 @@ fn findAndParseConfigH(b: *Builder, config_h_path_option: ?[]const u8) ?CMakeCon
687}686}
688687
689fn toNativePathSep(b: *Builder, s: []const u8) []u8 {688fn toNativePathSep(b: *Builder, s: []const u8) []u8 {
690 const duplicated = mem.dupe(b.allocator, u8, s) catch unreachable;689 const duplicated = b.allocator.dupe(u8, s) catch unreachable;
691 for (duplicated) |*byte| switch (byte.*) {690 for (duplicated) |*byte| switch (byte.*) {
692 '/' => byte.* = fs.path.sep,691 '/' => byte.* = fs.path.sep,
693 else => {},692 else => {},
doc/langref.html.in+5-5
...@@ -5708,7 +5708,7 @@ const mem = std.mem;...@@ -5708,7 +5708,7 @@ const mem = std.mem;
5708test "cast *[1][*]const u8 to [*]const ?[*]const u8" {5708test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
5709 const window_name = [1][*]const u8{"window name"};5709 const window_name = [1][*]const u8{"window name"};
5710 const x: [*]const ?[*]const u8 = &window_name;5710 const x: [*]const ?[*]const u8 = &window_name;
5711 try expect(mem.eql(u8, std.mem.spanZ(@ptrCast([*:0]const u8, x[0].?)), "window name"));5711 try expect(mem.eql(u8, std.mem.sliceTo(@ptrCast([*:0]const u8, x[0].?), 0), "window name"));
5712}5712}
5713 {#code_end#}5713 {#code_end#}
5714 {#header_close#}5714 {#header_close#}
...@@ -7364,7 +7364,7 @@ fn amain() !void {...@@ -7364,7 +7364,7 @@ fn amain() !void {
7364var global_download_frame: anyframe = undefined;7364var global_download_frame: anyframe = undefined;
7365fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 {7365fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 {
7366 _ = url; // this is just an example, we don't actually do it!7366 _ = url; // this is just an example, we don't actually do it!
7367 const result = try std.mem.dupe(allocator, u8, "this is the downloaded url contents");7367 const result = try allocator.dupe(u8, "this is the downloaded url contents");
7368 errdefer allocator.free(result);7368 errdefer allocator.free(result);
7369 suspend {7369 suspend {
7370 global_download_frame = @frame();7370 global_download_frame = @frame();
...@@ -7376,7 +7376,7 @@ fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 {...@@ -7376,7 +7376,7 @@ fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 {
7376var global_file_frame: anyframe = undefined;7376var global_file_frame: anyframe = undefined;
7377fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 {7377fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 {
7378 _ = filename; // this is just an example, we don't actually do it!7378 _ = filename; // this is just an example, we don't actually do it!
7379 const result = try std.mem.dupe(allocator, u8, "this is the file contents");7379 const result = try allocator.dupe(u8, "this is the file contents");
7380 errdefer allocator.free(result);7380 errdefer allocator.free(result);
7381 suspend {7381 suspend {
7382 global_file_frame = @frame();7382 global_file_frame = @frame();
...@@ -7435,7 +7435,7 @@ fn amain() !void {...@@ -7435,7 +7435,7 @@ fn amain() !void {
74357435
7436fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 {7436fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 {
7437 _ = url; // this is just an example, we don't actually do it!7437 _ = url; // this is just an example, we don't actually do it!
7438 const result = try std.mem.dupe(allocator, u8, "this is the downloaded url contents");7438 const result = try allocator.dupe(u8, "this is the downloaded url contents");
7439 errdefer allocator.free(result);7439 errdefer allocator.free(result);
7440 std.debug.print("fetchUrl returning\n", .{});7440 std.debug.print("fetchUrl returning\n", .{});
7441 return result;7441 return result;
...@@ -7443,7 +7443,7 @@ fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 {...@@ -7443,7 +7443,7 @@ fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 {
74437443
7444fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 {7444fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 {
7445 _ = filename; // this is just an example, we don't actually do it!7445 _ = filename; // this is just an example, we don't actually do it!
7446 const result = try std.mem.dupe(allocator, u8, "this is the file contents");7446 const result = try allocator.dupe(u8, "this is the file contents");
7447 errdefer allocator.free(result);7447 errdefer allocator.free(result);
7448 std.debug.print("readFile returning\n", .{});7448 std.debug.print("readFile returning\n", .{});
7449 return result;7449 return result;
lib/std/Thread.zig+1-3
...@@ -17,8 +17,6 @@ pub const Mutex = @import("Thread/Mutex.zig");...@@ -17,8 +17,6 @@ pub const Mutex = @import("Thread/Mutex.zig");
17pub const Semaphore = @import("Thread/Semaphore.zig");17pub const Semaphore = @import("Thread/Semaphore.zig");
18pub const Condition = @import("Thread/Condition.zig");18pub const Condition = @import("Thread/Condition.zig");
1919
20pub const spinLoopHint = @compileError("deprecated: use std.atomic.spinLoopHint");
21
22pub const use_pthreads = target.os.tag != .windows and target.os.tag != .wasi and builtin.link_libc;20pub const use_pthreads = target.os.tag != .windows and target.os.tag != .wasi and builtin.link_libc;
23const is_gnu = target.abi.isGnu();21const is_gnu = target.abi.isGnu();
2422
...@@ -361,7 +359,7 @@ fn callFn(comptime f: anytype, args: anytype) switch (Impl) {...@@ -361,7 +359,7 @@ fn callFn(comptime f: anytype, args: anytype) switch (Impl) {
361 }359 }
362360
363 @call(.{}, f, args) catch |err| {361 @call(.{}, f, args) catch |err| {
364 std.debug.warn("error: {s}\n", .{@errorName(err)});362 std.debug.print("error: {s}\n", .{@errorName(err)});
365 if (@errorReturnTrace()) |trace| {363 if (@errorReturnTrace()) |trace| {
366 std.debug.dumpStackTrace(trace.*);364 std.debug.dumpStackTrace(trace.*);
367 }365 }
lib/std/array_hash_map.zig+2-15
...@@ -201,8 +201,7 @@ pub fn ArrayHashMap(...@@ -201,8 +201,7 @@ pub fn ArrayHashMap(
201 return self.unmanaged.getOrPutValueContext(self.allocator, key, value, self.ctx);201 return self.unmanaged.getOrPutValueContext(self.allocator, key, value, self.ctx);
202 }202 }
203203
204 /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.204 pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`");
205 pub const ensureCapacity = ensureTotalCapacity;
206205
207 /// Increases capacity, guaranteeing that insertions up until the206 /// Increases capacity, guaranteeing that insertions up until the
208 /// `expected_count` will not cause an allocation, and therefore cannot fail.207 /// `expected_count` will not cause an allocation, and therefore cannot fail.
...@@ -746,8 +745,7 @@ pub fn ArrayHashMapUnmanaged(...@@ -746,8 +745,7 @@ pub fn ArrayHashMapUnmanaged(
746 return res;745 return res;
747 }746 }
748747
749 /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.748 pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`");
750 pub const ensureCapacity = ensureTotalCapacity;
751749
752 /// Increases capacity, guaranteeing that insertions up until the750 /// Increases capacity, guaranteeing that insertions up until the
753 /// `expected_count` will not cause an allocation, and therefore cannot fail.751 /// `expected_count` will not cause an allocation, and therefore cannot fail.
...@@ -2217,17 +2215,6 @@ test "auto store_hash" {...@@ -2217,17 +2215,6 @@ test "auto store_hash" {
2217 try testing.expect(meta.fieldInfo(HasExpensiveEqlUn.Data, .hash).field_type != void);2215 try testing.expect(meta.fieldInfo(HasExpensiveEqlUn.Data, .hash).field_type != void);
2218}2216}
22192217
2220test "compile everything" {
2221 std.testing.refAllDecls(AutoArrayHashMap(i32, i32));
2222 std.testing.refAllDecls(StringArrayHashMap([]const u8));
2223 std.testing.refAllDecls(AutoArrayHashMap(i32, void));
2224 std.testing.refAllDecls(StringArrayHashMap(u0));
2225 std.testing.refAllDecls(AutoArrayHashMapUnmanaged(i32, i32));
2226 std.testing.refAllDecls(StringArrayHashMapUnmanaged([]const u8));
2227 std.testing.refAllDecls(AutoArrayHashMapUnmanaged(i32, void));
2228 std.testing.refAllDecls(StringArrayHashMapUnmanaged(u0));
2229}
2230
2231pub fn getHashPtrAddrFn(comptime K: type, comptime Context: type) (fn (Context, K) u32) {2218pub fn getHashPtrAddrFn(comptime K: type, comptime Context: type) (fn (Context, K) u32) {
2232 return struct {2219 return struct {
2233 fn hash(ctx: Context, key: K) u32 {2220 fn hash(ctx: Context, key: K) u32 {
lib/std/array_list.zig+6-22
...@@ -71,15 +71,6 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -71,15 +71,6 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
71 }71 }
72 }72 }
7373
74 pub const span = @compileError("deprecated: use `items` field directly");
75 pub const toSlice = @compileError("deprecated: use `items` field directly");
76 pub const toSliceConst = @compileError("deprecated: use `items` field directly");
77 pub const at = @compileError("deprecated: use `list.items[i]`");
78 pub const ptrAt = @compileError("deprecated: use `&list.items[i]`");
79 pub const setOrError = @compileError("deprecated: use `if (i >= list.items.len) return error.OutOfBounds else list.items[i] = item`");
80 pub const set = @compileError("deprecated: use `list.items[i] = item`");
81 pub const swapRemoveOrError = @compileError("deprecated: use `if (i >= list.items.len) return error.OutOfBounds else list.swapRemove(i)`");
82
83 /// ArrayList takes ownership of the passed in slice. The slice must have been74 /// ArrayList takes ownership of the passed in slice. The slice must have been
84 /// allocated with `allocator`.75 /// allocated with `allocator`.
85 /// Deinitialize with `deinit` or use `toOwnedSlice`.76 /// Deinitialize with `deinit` or use `toOwnedSlice`.
...@@ -91,12 +82,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -91,12 +82,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
91 };82 };
92 }83 }
9384
94 /// Initializes an ArrayListUnmanaged with the `items` and `capacity` fields85 pub const toUnmanaged = @compileError("deprecated; use `moveToUnmanaged` which has different semantics.");
95 /// of this ArrayList. This ArrayList retains ownership of underlying memory.
96 /// Deprecated: use `moveToUnmanaged` which has different semantics.
97 pub fn toUnmanaged(self: Self) ArrayListAlignedUnmanaged(T, alignment) {
98 return .{ .items = self.items, .capacity = self.capacity };
99 }
10086
101 /// Initializes an ArrayListUnmanaged with the `items` and `capacity` fields87 /// Initializes an ArrayListUnmanaged with the `items` and `capacity` fields
102 /// of this ArrayList. Empties this ArrayList.88 /// of this ArrayList. Empties this ArrayList.
...@@ -307,8 +293,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -307,8 +293,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
307 self.capacity = 0;293 self.capacity = 0;
308 }294 }
309295
310 /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.296 pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`");
311 pub const ensureCapacity = ensureTotalCapacity;
312297
313 /// Modify the array so that it can hold at least `new_capacity` items.298 /// Modify the array so that it can hold at least `new_capacity` items.
314 /// Invalidates pointers if additional memory is needed.299 /// Invalidates pointers if additional memory is needed.
...@@ -533,7 +518,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -533,7 +518,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
533 pub fn replaceRange(self: *Self, allocator: *Allocator, start: usize, len: usize, new_items: []const T) !void {518 pub fn replaceRange(self: *Self, allocator: *Allocator, start: usize, len: usize, new_items: []const T) !void {
534 var managed = self.toManaged(allocator);519 var managed = self.toManaged(allocator);
535 try managed.replaceRange(start, len, new_items);520 try managed.replaceRange(start, len, new_items);
536 self.* = managed.toUnmanaged();521 self.* = managed.moveToUnmanaged();
537 }522 }
538523
539 /// Extend the list by 1 element. Allocates more memory as necessary.524 /// Extend the list by 1 element. Allocates more memory as necessary.
...@@ -674,8 +659,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -674,8 +659,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
674 self.capacity = 0;659 self.capacity = 0;
675 }660 }
676661
677 /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.662 pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`");
678 pub const ensureCapacity = ensureTotalCapacity;
679663
680 /// Modify the array so that it can hold at least `new_capacity` items.664 /// Modify the array so that it can hold at least `new_capacity` items.
681 /// Invalidates pointers if additional memory is needed.665 /// Invalidates pointers if additional memory is needed.
...@@ -1337,7 +1321,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {...@@ -1337,7 +1321,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {
13371321
1338 const result = try list.toOwnedSliceSentinel(0);1322 const result = try list.toOwnedSliceSentinel(0);
1339 defer a.free(result);1323 defer a.free(result);
1340 try testing.expectEqualStrings(result, mem.spanZ(result.ptr));1324 try testing.expectEqualStrings(result, mem.sliceTo(result.ptr, 0));
1341 }1325 }
1342 {1326 {
1343 var list = ArrayListUnmanaged(u8){};1327 var list = ArrayListUnmanaged(u8){};
...@@ -1347,7 +1331,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {...@@ -1347,7 +1331,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {
13471331
1348 const result = try list.toOwnedSliceSentinel(a, 0);1332 const result = try list.toOwnedSliceSentinel(a, 0);
1349 defer a.free(result);1333 defer a.free(result);
1350 try testing.expectEqualStrings(result, mem.spanZ(result.ptr));1334 try testing.expectEqualStrings(result, mem.sliceTo(result.ptr, 0));
1351 }1335 }
1352}1336}
13531337
lib/std/base64.zig+3-8
...@@ -64,14 +64,9 @@ pub const url_safe_no_pad = Codecs{...@@ -64,14 +64,9 @@ pub const url_safe_no_pad = Codecs{
64 .Decoder = Base64Decoder.init(url_safe_alphabet_chars, null),64 .Decoder = Base64Decoder.init(url_safe_alphabet_chars, null),
65};65};
6666
67// Backwards compatibility67pub const standard_pad_char = @compileError("deprecated; use standard.pad_char");
6868pub const standard_encoder = @compileError("deprecated; use standard.Encoder");
69/// Deprecated - Use `standard.pad_char`69pub const standard_decoder = @compileError("deprecated; use standard.Decoder");
70pub const standard_pad_char = standard.pad_char;
71/// Deprecated - Use `standard.Encoder`
72pub const standard_encoder = standard.Encoder;
73/// Deprecated - Use `standard.Decoder`
74pub const standard_decoder = standard.Decoder;
7570
76pub const Base64Encoder = struct {71pub const Base64Encoder = struct {
77 alphabet_chars: [64]u8,72 alphabet_chars: [64]u8,
lib/std/build.zig+7-19
...@@ -6,7 +6,7 @@ const mem = std.mem;...@@ -6,7 +6,7 @@ const mem = std.mem;
6const debug = std.debug;6const debug = std.debug;
7const panic = std.debug.panic;7const panic = std.debug.panic;
8const assert = debug.assert;8const assert = debug.assert;
9const warn = std.debug.warn;9const warn = std.debug.print; // TODO use the log system instead of this
10const ArrayList = std.ArrayList;10const ArrayList = std.ArrayList;
11const StringHashMap = std.StringHashMap;11const StringHashMap = std.StringHashMap;
12const Allocator = mem.Allocator;12const Allocator = mem.Allocator;
...@@ -1295,11 +1295,12 @@ test "builder.findProgram compiles" {...@@ -1295,11 +1295,12 @@ test "builder.findProgram compiles" {
1295 _ = builder.findProgram(&[_][]const u8{}, &[_][]const u8{}) catch null;1295 _ = builder.findProgram(&[_][]const u8{}, &[_][]const u8{}) catch null;
1296}1296}
12971297
1298/// Deprecated. Use `std.builtin.Version`.1298/// TODO: propose some kind of `@deprecate` builtin so that we can deprecate
1299pub const Version = std.builtin.Version;1299/// this while still having somewhat non-lazy decls. In this file we wanted to do
13001300/// refAllDecls for example which makes it trigger `@compileError` if you try
1301/// Deprecated. Use `std.zig.CrossTarget`.1301/// to use that strategy.
1302pub const Target = std.zig.CrossTarget;1302pub const Version = @compileError("deprecated; Use `std.builtin.Version`");
1303pub const Target = @compileError("deprecated; Use `std.zig.CrossTarget`");
13031304
1304pub const Pkg = struct {1305pub const Pkg = struct {
1305 name: []const u8,1306 name: []const u8,
...@@ -3277,16 +3278,3 @@ test "LibExeObjStep.addPackage" {...@@ -3277,16 +3278,3 @@ test "LibExeObjStep.addPackage" {
3277 const dupe = exe.packages.items[0];3278 const dupe = exe.packages.items[0];
3278 try std.testing.expectEqualStrings(pkg_top.name, dupe.name);3279 try std.testing.expectEqualStrings(pkg_top.name, dupe.name);
3279}3280}
3280
3281test {
3282 // The only purpose of this test is to get all these untested functions
3283 // to be referenced to avoid regression so it is okay to skip some targets.
3284 if (comptime builtin.cpu.arch.ptrBitWidth() == 64) {
3285 std.testing.refAllDecls(@This());
3286 std.testing.refAllDecls(Builder);
3287
3288 inline for (std.meta.declarations(@This())) |decl|
3289 if (comptime mem.endsWith(u8, decl.name, "Step"))
3290 std.testing.refAllDecls(decl.data.Type);
3291 }
3292}
lib/std/build/CheckFileStep.zig+1-2
...@@ -4,7 +4,6 @@ const Step = build.Step;...@@ -4,7 +4,6 @@ const Step = build.Step;
4const Builder = build.Builder;4const Builder = build.Builder;
5const fs = std.fs;5const fs = std.fs;
6const mem = std.mem;6const mem = std.mem;
7const warn = std.debug.warn;
87
9const CheckFileStep = @This();8const CheckFileStep = @This();
109
...@@ -40,7 +39,7 @@ fn make(step: *Step) !void {...@@ -40,7 +39,7 @@ fn make(step: *Step) !void {
4039
41 for (self.expected_matches) |expected_match| {40 for (self.expected_matches) |expected_match| {
42 if (mem.indexOf(u8, contents, expected_match) == null) {41 if (mem.indexOf(u8, contents, expected_match) == null) {
43 warn(42 std.debug.print(
44 \\43 \\
45 \\========= Expected to find: ===================44 \\========= Expected to find: ===================
46 \\{s}45 \\{s}
lib/std/build/InstallRawStep.zig+1-2
...@@ -12,7 +12,6 @@ const elf = std.elf;...@@ -12,7 +12,6 @@ const elf = std.elf;
12const fs = std.fs;12const fs = std.fs;
13const io = std.io;13const io = std.io;
14const sort = std.sort;14const sort = std.sort;
15const warn = std.debug.warn;
1615
17const BinaryElfSection = struct {16const BinaryElfSection = struct {
18 elfOffset: u64,17 elfOffset: u64,
...@@ -387,7 +386,7 @@ fn make(step: *Step) !void {...@@ -387,7 +386,7 @@ fn make(step: *Step) !void {
387 const builder = self.builder;386 const builder = self.builder;
388387
389 if (self.artifact.target.getObjectFormat() != .elf) {388 if (self.artifact.target.getObjectFormat() != .elf) {
390 warn("InstallRawStep only works with ELF format.\n", .{});389 std.debug.print("InstallRawStep only works with ELF format.\n", .{});
391 return error.InvalidObjectFormat;390 return error.InvalidObjectFormat;
392 }391 }
393392
lib/std/build/RunStep.zig+12-13
...@@ -10,7 +10,6 @@ const mem = std.mem;...@@ -10,7 +10,6 @@ const mem = std.mem;
10const process = std.process;10const process = std.process;
11const ArrayList = std.ArrayList;11const ArrayList = std.ArrayList;
12const BufMap = std.BufMap;12const BufMap = std.BufMap;
13const warn = std.debug.warn;
1413
15const max_stdout_size = 1 * 1024 * 1024; // 1 MiB14const max_stdout_size = 1 * 1024 * 1024; // 1 MiB
1615
...@@ -189,7 +188,7 @@ fn make(step: *Step) !void {...@@ -189,7 +188,7 @@ fn make(step: *Step) !void {
189 printCmd(cwd, argv);188 printCmd(cwd, argv);
190189
191 child.spawn() catch |err| {190 child.spawn() catch |err| {
192 warn("Unable to spawn {s}: {s}\n", .{ argv[0], @errorName(err) });191 std.debug.print("Unable to spawn {s}: {s}\n", .{ argv[0], @errorName(err) });
193 return err;192 return err;
194 };193 };
195194
...@@ -216,7 +215,7 @@ fn make(step: *Step) !void {...@@ -216,7 +215,7 @@ fn make(step: *Step) !void {
216 }215 }
217216
218 const term = child.wait() catch |err| {217 const term = child.wait() catch |err| {
219 warn("Unable to spawn {s}: {s}\n", .{ argv[0], @errorName(err) });218 std.debug.print("Unable to spawn {s}: {s}\n", .{ argv[0], @errorName(err) });
220 return err;219 return err;
221 };220 };
222221
...@@ -224,12 +223,12 @@ fn make(step: *Step) !void {...@@ -224,12 +223,12 @@ fn make(step: *Step) !void {
224 .Exited => |code| {223 .Exited => |code| {
225 if (code != self.expected_exit_code) {224 if (code != self.expected_exit_code) {
226 if (self.builder.prominent_compile_errors) {225 if (self.builder.prominent_compile_errors) {
227 warn("Run step exited with error code {} (expected {})\n", .{226 std.debug.print("Run step exited with error code {} (expected {})\n", .{
228 code,227 code,
229 self.expected_exit_code,228 self.expected_exit_code,
230 });229 });
231 } else {230 } else {
232 warn("The following command exited with error code {} (expected {}):\n", .{231 std.debug.print("The following command exited with error code {} (expected {}):\n", .{
233 code,232 code,
234 self.expected_exit_code,233 self.expected_exit_code,
235 });234 });
...@@ -240,7 +239,7 @@ fn make(step: *Step) !void {...@@ -240,7 +239,7 @@ fn make(step: *Step) !void {
240 }239 }
241 },240 },
242 else => {241 else => {
243 warn("The following command terminated unexpectedly:\n", .{});242 std.debug.print("The following command terminated unexpectedly:\n", .{});
244 printCmd(cwd, argv);243 printCmd(cwd, argv);
245 return error.UncleanExit;244 return error.UncleanExit;
246 },245 },
...@@ -250,7 +249,7 @@ fn make(step: *Step) !void {...@@ -250,7 +249,7 @@ fn make(step: *Step) !void {
250 .inherit, .ignore => {},249 .inherit, .ignore => {},
251 .expect_exact => |expected_bytes| {250 .expect_exact => |expected_bytes| {
252 if (!mem.eql(u8, expected_bytes, stderr.?)) {251 if (!mem.eql(u8, expected_bytes, stderr.?)) {
253 warn(252 std.debug.print(
254 \\253 \\
255 \\========= Expected this stderr: =========254 \\========= Expected this stderr: =========
256 \\{s}255 \\{s}
...@@ -264,7 +263,7 @@ fn make(step: *Step) !void {...@@ -264,7 +263,7 @@ fn make(step: *Step) !void {
264 },263 },
265 .expect_matches => |matches| for (matches) |match| {264 .expect_matches => |matches| for (matches) |match| {
266 if (mem.indexOf(u8, stderr.?, match) == null) {265 if (mem.indexOf(u8, stderr.?, match) == null) {
267 warn(266 std.debug.print(
268 \\267 \\
269 \\========= Expected to find in stderr: =========268 \\========= Expected to find in stderr: =========
270 \\{s}269 \\{s}
...@@ -282,7 +281,7 @@ fn make(step: *Step) !void {...@@ -282,7 +281,7 @@ fn make(step: *Step) !void {
282 .inherit, .ignore => {},281 .inherit, .ignore => {},
283 .expect_exact => |expected_bytes| {282 .expect_exact => |expected_bytes| {
284 if (!mem.eql(u8, expected_bytes, stdout.?)) {283 if (!mem.eql(u8, expected_bytes, stdout.?)) {
285 warn(284 std.debug.print(
286 \\285 \\
287 \\========= Expected this stdout: =========286 \\========= Expected this stdout: =========
288 \\{s}287 \\{s}
...@@ -296,7 +295,7 @@ fn make(step: *Step) !void {...@@ -296,7 +295,7 @@ fn make(step: *Step) !void {
296 },295 },
297 .expect_matches => |matches| for (matches) |match| {296 .expect_matches => |matches| for (matches) |match| {
298 if (mem.indexOf(u8, stdout.?, match) == null) {297 if (mem.indexOf(u8, stdout.?, match) == null) {
299 warn(298 std.debug.print(
300 \\299 \\
301 \\========= Expected to find in stdout: =========300 \\========= Expected to find in stdout: =========
302 \\{s}301 \\{s}
...@@ -312,11 +311,11 @@ fn make(step: *Step) !void {...@@ -312,11 +311,11 @@ fn make(step: *Step) !void {
312}311}
313312
314fn printCmd(cwd: ?[]const u8, argv: []const []const u8) void {313fn printCmd(cwd: ?[]const u8, argv: []const []const u8) void {
315 if (cwd) |yes_cwd| warn("cd {s} && ", .{yes_cwd});314 if (cwd) |yes_cwd| std.debug.print("cd {s} && ", .{yes_cwd});
316 for (argv) |arg| {315 for (argv) |arg| {
317 warn("{s} ", .{arg});316 std.debug.print("{s} ", .{arg});
318 }317 }
319 warn("\n", .{});318 std.debug.print("\n", .{});
320}319}
321320
322fn addPathForDynLibs(self: *RunStep, artifact: *LibExeObjStep) void {321fn addPathForDynLibs(self: *RunStep, artifact: *LibExeObjStep) void {
lib/std/build/WriteFileStep.zig+2-3
...@@ -3,7 +3,6 @@ const build = @import("../build.zig");...@@ -3,7 +3,6 @@ const build = @import("../build.zig");
3const Step = build.Step;3const Step = build.Step;
4const Builder = build.Builder;4const Builder = build.Builder;
5const fs = std.fs;5const fs = std.fs;
6const warn = std.debug.warn;
7const ArrayList = std.ArrayList;6const ArrayList = std.ArrayList;
87
9const WriteFileStep = @This();8const WriteFileStep = @This();
...@@ -91,7 +90,7 @@ fn make(step: *Step) !void {...@@ -91,7 +90,7 @@ fn make(step: *Step) !void {
91 });90 });
92 // TODO replace with something like fs.makePathAndOpenDir91 // TODO replace with something like fs.makePathAndOpenDir
93 fs.cwd().makePath(self.output_dir) catch |err| {92 fs.cwd().makePath(self.output_dir) catch |err| {
94 warn("unable to make path {s}: {s}\n", .{ self.output_dir, @errorName(err) });93 std.debug.print("unable to make path {s}: {s}\n", .{ self.output_dir, @errorName(err) });
95 return err;94 return err;
96 };95 };
97 var dir = try fs.cwd().openDir(self.output_dir, .{});96 var dir = try fs.cwd().openDir(self.output_dir, .{});
...@@ -100,7 +99,7 @@ fn make(step: *Step) !void {...@@ -100,7 +99,7 @@ fn make(step: *Step) !void {
100 var it = self.files.first;99 var it = self.files.first;
101 while (it) |node| : (it = node.next) {100 while (it) |node| : (it = node.next) {
102 dir.writeFile(node.data.basename, node.data.bytes) catch |err| {101 dir.writeFile(node.data.basename, node.data.bytes) catch |err| {
103 warn("unable to write {s} into {s}: {s}\n", .{102 std.debug.print("unable to write {s} into {s}: {s}\n", .{
104 node.data.basename,103 node.data.basename,
105 self.output_dir,104 self.output_dir,
106 @errorName(err),105 @errorName(err),
lib/std/builtin.zig+1-1
...@@ -707,7 +707,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn...@@ -707,7 +707,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn
707 }707 }
708 },708 },
709 .wasi => {709 .wasi => {
710 std.debug.warn("{s}", .{msg});710 std.debug.print("{s}", .{msg});
711 std.os.abort();711 std.os.abort();
712 },712 },
713 .uefi => {713 .uefi => {
lib/std/c/tokenizer.zig+2-2
...@@ -126,7 +126,7 @@ pub const Token = struct {...@@ -126,7 +126,7 @@ pub const Token = struct {
126 Keyword_error,126 Keyword_error,
127 Keyword_pragma,127 Keyword_pragma,
128128
129 pub fn symbol(id: std.meta.TagType(Id)) []const u8 {129 pub fn symbol(id: std.meta.Tag(Id)) []const u8 {
130 return switch (id) {130 return switch (id) {
131 .Invalid => "Invalid",131 .Invalid => "Invalid",
132 .Eof => "Eof",132 .Eof => "Eof",
...@@ -342,7 +342,7 @@ pub const Token = struct {...@@ -342,7 +342,7 @@ pub const Token = struct {
342pub const Tokenizer = struct {342pub const Tokenizer = struct {
343 buffer: []const u8,343 buffer: []const u8,
344 index: usize = 0,344 index: usize = 0,
345 prev_tok_id: std.meta.TagType(Token.Id) = .Invalid,345 prev_tok_id: std.meta.Tag(Token.Id) = .Invalid,
346 pp_directive: bool = false,346 pp_directive: bool = false,
347347
348 pub fn next(self: *Tokenizer) Token {348 pub fn next(self: *Tokenizer) Token {
lib/std/child_process.zig-2
...@@ -181,8 +181,6 @@ pub const ChildProcess = struct {...@@ -181,8 +181,6 @@ pub const ChildProcess = struct {
181 stderr: []u8,181 stderr: []u8,
182 };182 };
183183
184 pub const exec2 = @compileError("deprecated: exec2 is renamed to exec");
185
186 fn collectOutputPosix(184 fn collectOutputPosix(
187 child: *const ChildProcess,185 child: *const ChildProcess,
188 stdout: *std.ArrayList(u8),186 stdout: *std.ArrayList(u8),
lib/std/crypto/benchmark.zig+1-1
...@@ -343,7 +343,7 @@ fn benchmarkPwhash(...@@ -343,7 +343,7 @@ fn benchmarkPwhash(
343}343}
344344
345fn usage() void {345fn usage() void {
346 std.debug.warn(346 std.debug.print(
347 \\throughput_test [options]347 \\throughput_test [options]
348 \\348 \\
349 \\Options:349 \\Options:
lib/std/debug.zig+6-8
...@@ -55,9 +55,7 @@ const PdbOrDwarf = union(enum) {...@@ -55,9 +55,7 @@ const PdbOrDwarf = union(enum) {
5555
56var stderr_mutex = std.Thread.Mutex{};56var stderr_mutex = std.Thread.Mutex{};
5757
58/// Deprecated. Use `std.log` functions for logging or `std.debug.print` for58pub const warn = @compileError("deprecated; use `std.log` functions for logging or `std.debug.print` for 'printf debugging'");
59/// "printf debugging".
60pub const warn = print;
6159
62/// Print to stderr, unbuffered, and silently returning on failure. Intended60/// Print to stderr, unbuffered, and silently returning on failure. Intended
63/// for use in "printf debugging." Use `std.log` functions for proper logging.61/// for use in "printf debugging." Use `std.log` functions for proper logging.
...@@ -1052,7 +1050,7 @@ pub const DebugInfo = struct {...@@ -1052,7 +1050,7 @@ pub const DebugInfo = struct {
1052 const obj_di = try self.allocator.create(ModuleDebugInfo);1050 const obj_di = try self.allocator.create(ModuleDebugInfo);
1053 errdefer self.allocator.destroy(obj_di);1051 errdefer self.allocator.destroy(obj_di);
10541052
1055 const macho_path = mem.spanZ(std.c._dyld_get_image_name(i));1053 const macho_path = mem.sliceTo(std.c._dyld_get_image_name(i), 0);
1056 const macho_file = fs.cwd().openFile(macho_path, .{ .intended_io_mode = .blocking }) catch |err| switch (err) {1054 const macho_file = fs.cwd().openFile(macho_path, .{ .intended_io_mode = .blocking }) catch |err| switch (err) {
1057 error.FileNotFound => return error.MissingDebugInfo,1055 error.FileNotFound => return error.MissingDebugInfo,
1058 else => return err,1056 else => return err,
...@@ -1178,7 +1176,7 @@ pub const DebugInfo = struct {...@@ -1178,7 +1176,7 @@ pub const DebugInfo = struct {
1178 if (context.address >= seg_start and context.address < seg_end) {1176 if (context.address >= seg_start and context.address < seg_end) {
1179 // Android libc uses NULL instead of an empty string to mark the1177 // Android libc uses NULL instead of an empty string to mark the
1180 // main program1178 // main program
1181 context.name = mem.spanZ(info.dlpi_name) orelse "";1179 context.name = mem.sliceTo(info.dlpi_name, 0) orelse "";
1182 context.base_address = info.dlpi_addr;1180 context.base_address = info.dlpi_addr;
1183 // Stop the iteration1181 // Stop the iteration
1184 return error.Found;1182 return error.Found;
...@@ -1341,12 +1339,12 @@ pub const ModuleDebugInfo = switch (native_os) {...@@ -1341,12 +1339,12 @@ pub const ModuleDebugInfo = switch (native_os) {
13411339
1342 // Take the symbol name from the N_FUN STAB entry, we're going to1340 // Take the symbol name from the N_FUN STAB entry, we're going to
1343 // use it if we fail to find the DWARF infos1341 // use it if we fail to find the DWARF infos
1344 const stab_symbol = mem.spanZ(self.strings[symbol.nlist.n_strx..]);1342 const stab_symbol = mem.sliceTo(self.strings[symbol.nlist.n_strx..], 0);
13451343
1346 if (symbol.ofile == null)1344 if (symbol.ofile == null)
1347 return SymbolInfo{ .symbol_name = stab_symbol };1345 return SymbolInfo{ .symbol_name = stab_symbol };
13481346
1349 const o_file_path = mem.spanZ(self.strings[symbol.ofile.?.n_strx..]);1347 const o_file_path = mem.sliceTo(self.strings[symbol.ofile.?.n_strx..], 0);
13501348
1351 // Check if its debug infos are already in the cache1349 // Check if its debug infos are already in the cache
1352 var o_file_di = self.ofiles.get(o_file_path) orelse1350 var o_file_di = self.ofiles.get(o_file_path) orelse
...@@ -1668,5 +1666,5 @@ pub fn dumpStackPointerAddr(prefix: []const u8) void {...@@ -1668,5 +1666,5 @@ pub fn dumpStackPointerAddr(prefix: []const u8) void {
1668 const sp = asm (""1666 const sp = asm (""
1669 : [argc] "={rsp}" (-> usize),1667 : [argc] "={rsp}" (-> usize),
1670 );1668 );
1671 std.debug.warn("{} sp = 0x{x}\n", .{ prefix, sp });1669 std.debug.print("{} sp = 0x{x}\n", .{ prefix, sp });
1672}1670}
lib/std/dynamic_library.zig+3-9
...@@ -248,11 +248,9 @@ pub const ElfDynLib = struct {...@@ -248,11 +248,9 @@ pub const ElfDynLib = struct {
248 };248 };
249 }249 }
250250
251 pub const openC = @compileError("deprecated: renamed to openZ");
252
253 /// Trusts the file. Malicious file will be able to execute arbitrary code.251 /// Trusts the file. Malicious file will be able to execute arbitrary code.
254 pub fn openZ(path_c: [*:0]const u8) !ElfDynLib {252 pub fn openZ(path_c: [*:0]const u8) !ElfDynLib {
255 return open(mem.spanZ(path_c));253 return open(mem.sliceTo(path_c, 0));
256 }254 }
257255
258 /// Trusts the file256 /// Trusts the file
...@@ -281,7 +279,7 @@ pub const ElfDynLib = struct {...@@ -281,7 +279,7 @@ pub const ElfDynLib = struct {
281 if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info & 0xf) & OK_TYPES)) continue;279 if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info & 0xf) & OK_TYPES)) continue;
282 if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info >> 4) & OK_BINDS)) continue;280 if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info >> 4) & OK_BINDS)) continue;
283 if (0 == self.syms[i].st_shndx) continue;281 if (0 == self.syms[i].st_shndx) continue;
284 if (!mem.eql(u8, name, mem.spanZ(self.strings + self.syms[i].st_name))) continue;282 if (!mem.eql(u8, name, mem.sliceTo(self.strings + self.syms[i].st_name, 0))) continue;
285 if (maybe_versym) |versym| {283 if (maybe_versym) |versym| {
286 if (!checkver(self.verdef.?, versym[i], vername, self.strings))284 if (!checkver(self.verdef.?, versym[i], vername, self.strings))
287 continue;285 continue;
...@@ -312,7 +310,7 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [...@@ -312,7 +310,7 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [
312 def = @intToPtr(*elf.Verdef, @ptrToInt(def) + def.vd_next);310 def = @intToPtr(*elf.Verdef, @ptrToInt(def) + def.vd_next);
313 }311 }
314 const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux);312 const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux);
315 return mem.eql(u8, vername, mem.spanZ(strings + aux.vda_name));313 return mem.eql(u8, vername, mem.sliceTo(strings + aux.vda_name, 0));
316}314}
317315
318pub const WindowsDynLib = struct {316pub const WindowsDynLib = struct {
...@@ -325,8 +323,6 @@ pub const WindowsDynLib = struct {...@@ -325,8 +323,6 @@ pub const WindowsDynLib = struct {
325 return openW(path_w.span().ptr);323 return openW(path_w.span().ptr);
326 }324 }
327325
328 pub const openC = @compileError("deprecated: renamed to openZ");
329
330 pub fn openZ(path_c: [*:0]const u8) !WindowsDynLib {326 pub fn openZ(path_c: [*:0]const u8) !WindowsDynLib {
331 const path_w = try windows.cStrToPrefixedFileW(path_c);327 const path_w = try windows.cStrToPrefixedFileW(path_c);
332 return openW(path_w.span().ptr);328 return openW(path_w.span().ptr);
...@@ -368,8 +364,6 @@ pub const DlDynlib = struct {...@@ -368,8 +364,6 @@ pub const DlDynlib = struct {
368 return openZ(&path_c);364 return openZ(&path_c);
369 }365 }
370366
371 pub const openC = @compileError("deprecated: renamed to openZ");
372
373 pub fn openZ(path_c: [*:0]const u8) !DlDynlib {367 pub fn openZ(path_c: [*:0]const u8) !DlDynlib {
374 return DlDynlib{368 return DlDynlib{
375 .handle = system.dlopen(path_c, system.RTLD.LAZY) orelse {369 .handle = system.dlopen(path_c, system.RTLD.LAZY) orelse {
lib/std/fifo.zig+1-2
...@@ -119,8 +119,7 @@ pub fn LinearFifo(...@@ -119,8 +119,7 @@ pub fn LinearFifo(
119 }119 }
120 }120 }
121121
122 /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.122 pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`");
123 pub const ensureCapacity = ensureTotalCapacity;
124123
125 /// Ensure that the buffer can fit at least `size` items124 /// Ensure that the buffer can fit at least `size` items
126 pub fn ensureTotalCapacity(self: *Self, size: usize) !void {125 pub fn ensureTotalCapacity(self: *Self, size: usize) !void {
lib/std/fmt.zig+1-5
...@@ -1814,8 +1814,7 @@ pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: any...@@ -1814,8 +1814,7 @@ pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: any
1814 };1814 };
1815}1815}
18161816
1817/// Deprecated, use allocPrintZ1817pub const allocPrint0 = @compileError("deprecated; use allocPrintZ");
1818pub const allocPrint0 = allocPrintZ;
18191818
1820pub fn allocPrintZ(allocator: *mem.Allocator, comptime fmt: []const u8, args: anytype) AllocPrintError![:0]u8 {1819pub fn allocPrintZ(allocator: *mem.Allocator, comptime fmt: []const u8, args: anytype) AllocPrintError![:0]u8 {
1821 const result = try allocPrint(allocator, fmt ++ "\x00", args);1820 const result = try allocPrint(allocator, fmt ++ "\x00", args);
...@@ -2367,9 +2366,6 @@ test "bytes.hex" {...@@ -2367,9 +2366,6 @@ test "bytes.hex" {
2367 try expectFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", .{fmtSliceHexLower(bytes_with_zeros)});2366 try expectFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", .{fmtSliceHexLower(bytes_with_zeros)});
2368}2367}
23692368
2370pub const trim = @compileError("deprecated; use std.mem.trim with std.ascii.spaces instead");
2371pub const isWhiteSpace = @compileError("deprecated; use std.ascii.isSpace instead");
2372
2373/// Decodes the sequence of bytes represented by the specified string of2369/// Decodes the sequence of bytes represented by the specified string of
2374/// hexadecimal characters.2370/// hexadecimal characters.
2375/// Returns a slice of the output buffer containing the decoded bytes.2371/// Returns a slice of the output buffer containing the decoded bytes.
lib/std/fs.zig+7-42
...@@ -19,7 +19,6 @@ pub const wasi = @import("fs/wasi.zig");...@@ -19,7 +19,6 @@ pub const wasi = @import("fs/wasi.zig");
1919
20pub const realpath = os.realpath;20pub const realpath = os.realpath;
21pub const realpathZ = os.realpathZ;21pub const realpathZ = os.realpathZ;
22pub const realpathC = @compileError("deprecated: renamed to realpathZ");
23pub const realpathW = os.realpathW;22pub const realpathW = os.realpathW;
2423
25pub const getAppDataDir = @import("fs/get_app_data_dir.zig").getAppDataDir;24pub const getAppDataDir = @import("fs/get_app_data_dir.zig").getAppDataDir;
...@@ -227,10 +226,6 @@ pub fn makeDirAbsoluteW(absolute_path_w: [*:0]const u16) !void {...@@ -227,10 +226,6 @@ pub fn makeDirAbsoluteW(absolute_path_w: [*:0]const u16) !void {
227 return os.mkdirW(absolute_path_w, default_new_dir_mode);226 return os.mkdirW(absolute_path_w, default_new_dir_mode);
228}227}
229228
230pub const deleteDir = @compileError("deprecated; use dir.deleteDir or deleteDirAbsolute");
231pub const deleteDirC = @compileError("deprecated; use dir.deleteDirZ or deleteDirAbsoluteZ");
232pub const deleteDirW = @compileError("deprecated; use dir.deleteDirW or deleteDirAbsoluteW");
233
234/// Same as `Dir.deleteDir` except the path is absolute.229/// Same as `Dir.deleteDir` except the path is absolute.
235pub fn deleteDirAbsolute(dir_path: []const u8) !void {230pub fn deleteDirAbsolute(dir_path: []const u8) !void {
236 assert(path.isAbsolute(dir_path));231 assert(path.isAbsolute(dir_path));
...@@ -249,8 +244,6 @@ pub fn deleteDirAbsoluteW(dir_path: [*:0]const u16) !void {...@@ -249,8 +244,6 @@ pub fn deleteDirAbsoluteW(dir_path: [*:0]const u16) !void {
249 return os.rmdirW(dir_path);244 return os.rmdirW(dir_path);
250}245}
251246
252pub const renameC = @compileError("deprecated: use renameZ, dir.renameZ, or renameAbsoluteZ");
253
254/// Same as `Dir.rename` except the paths are absolute.247/// Same as `Dir.rename` except the paths are absolute.
255pub fn renameAbsolute(old_path: []const u8, new_path: []const u8) !void {248pub fn renameAbsolute(old_path: []const u8, new_path: []const u8) !void {
256 assert(path.isAbsolute(old_path));249 assert(path.isAbsolute(old_path));
...@@ -393,7 +386,7 @@ pub const Dir = struct {...@@ -393,7 +386,7 @@ pub const Dir = struct {
393 const next_index = self.index + entry.reclen();386 const next_index = self.index + entry.reclen();
394 self.index = next_index;387 self.index = next_index;
395388
396 const name = mem.spanZ(@ptrCast([*:0]u8, &entry.d_name));389 const name = mem.sliceTo(@ptrCast([*:0]u8, &entry.d_name), 0);
397 if (mem.eql(u8, name, ".") or mem.eql(u8, name, ".."))390 if (mem.eql(u8, name, ".") or mem.eql(u8, name, ".."))
398 continue :start_over;391 continue :start_over;
399392
...@@ -520,7 +513,7 @@ pub const Dir = struct {...@@ -520,7 +513,7 @@ pub const Dir = struct {
520 const haiku_entry = @ptrCast(*align(1) os.system.dirent, &self.buf[self.index]);513 const haiku_entry = @ptrCast(*align(1) os.system.dirent, &self.buf[self.index]);
521 const next_index = self.index + haiku_entry.reclen();514 const next_index = self.index + haiku_entry.reclen();
522 self.index = next_index;515 self.index = next_index;
523 const name = mem.spanZ(@ptrCast([*:0]u8, &haiku_entry.d_name));516 const name = mem.sliceTo(@ptrCast([*:0]u8, &haiku_entry.d_name), 0);
524517
525 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..") or (haiku_entry.d_ino == 0)) {518 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..") or (haiku_entry.d_ino == 0)) {
526 continue :start_over;519 continue :start_over;
...@@ -598,7 +591,7 @@ pub const Dir = struct {...@@ -598,7 +591,7 @@ pub const Dir = struct {
598 const next_index = self.index + linux_entry.reclen();591 const next_index = self.index + linux_entry.reclen();
599 self.index = next_index;592 self.index = next_index;
600593
601 const name = mem.spanZ(@ptrCast([*:0]u8, &linux_entry.d_name));594 const name = mem.sliceTo(@ptrCast([*:0]u8, &linux_entry.d_name), 0);
602595
603 // skip . and .. entries596 // skip . and .. entries
604 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) {597 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) {
...@@ -965,8 +958,6 @@ pub const Dir = struct {...@@ -965,8 +958,6 @@ pub const Dir = struct {
965 return File{ .handle = fd };958 return File{ .handle = fd };
966 }959 }
967960
968 pub const openFileC = @compileError("deprecated: renamed to openFileZ");
969
970 /// Same as `openFile` but the path parameter is null-terminated.961 /// Same as `openFile` but the path parameter is null-terminated.
971 pub fn openFileZ(self: Dir, sub_path: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File {962 pub fn openFileZ(self: Dir, sub_path: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File {
972 if (builtin.os.tag == .windows) {963 if (builtin.os.tag == .windows) {
...@@ -1100,8 +1091,6 @@ pub const Dir = struct {...@@ -1100,8 +1091,6 @@ pub const Dir = struct {
1100 return self.createFileZ(&path_c, flags);1091 return self.createFileZ(&path_c, flags);
1101 }1092 }
11021093
1103 pub const createFileC = @compileError("deprecated: renamed to createFileZ");
1104
1105 /// Same as `createFile` but WASI only.1094 /// Same as `createFile` but WASI only.
1106 pub fn createFileWasi(self: Dir, sub_path: []const u8, flags: File.CreateFlags) File.OpenError!File {1095 pub fn createFileWasi(self: Dir, sub_path: []const u8, flags: File.CreateFlags) File.OpenError!File {
1107 const w = os.wasi;1096 const w = os.wasi;
...@@ -1243,10 +1232,6 @@ pub const Dir = struct {...@@ -1243,10 +1232,6 @@ pub const Dir = struct {
1243 return file;1232 return file;
1244 }1233 }
12451234
1246 pub const openRead = @compileError("deprecated in favor of openFile");
1247 pub const openReadC = @compileError("deprecated in favor of openFileZ");
1248 pub const openReadW = @compileError("deprecated in favor of openFileW");
1249
1250 pub fn makeDir(self: Dir, sub_path: []const u8) !void {1235 pub fn makeDir(self: Dir, sub_path: []const u8) !void {
1251 try os.mkdirat(self.fd, sub_path, default_new_dir_mode);1236 try os.mkdirat(self.fd, sub_path, default_new_dir_mode);
1252 }1237 }
...@@ -1463,8 +1448,6 @@ pub const Dir = struct {...@@ -1463,8 +1448,6 @@ pub const Dir = struct {
1463 }1448 }
1464 }1449 }
14651450
1466 pub const openDirC = @compileError("deprecated: renamed to openDirZ");
1467
1468 /// Same as `openDir` except only WASI.1451 /// Same as `openDir` except only WASI.
1469 pub fn openDirWasi(self: Dir, sub_path: []const u8, args: OpenDirOptions) OpenError!Dir {1452 pub fn openDirWasi(self: Dir, sub_path: []const u8, args: OpenDirOptions) OpenError!Dir {
1470 const w = os.wasi;1453 const w = os.wasi;
...@@ -1554,7 +1537,7 @@ pub const Dir = struct {...@@ -1554,7 +1537,7 @@ pub const Dir = struct {
1554 .fd = undefined,1537 .fd = undefined,
1555 };1538 };
15561539
1557 const path_len_bytes = @intCast(u16, mem.lenZ(sub_path_w) * 2);1540 const path_len_bytes = @intCast(u16, mem.sliceTo(sub_path_w, 0).len * 2);
1558 var nt_name = w.UNICODE_STRING{1541 var nt_name = w.UNICODE_STRING{
1559 .Length = path_len_bytes,1542 .Length = path_len_bytes,
1560 .MaximumLength = path_len_bytes,1543 .MaximumLength = path_len_bytes,
...@@ -1613,8 +1596,6 @@ pub const Dir = struct {...@@ -1613,8 +1596,6 @@ pub const Dir = struct {
1613 }1596 }
1614 }1597 }
16151598
1616 pub const deleteFileC = @compileError("deprecated: renamed to deleteFileZ");
1617
1618 /// Same as `deleteFile` except the parameter is null-terminated.1599 /// Same as `deleteFile` except the parameter is null-terminated.
1619 pub fn deleteFileZ(self: Dir, sub_path_c: [*:0]const u8) DeleteFileError!void {1600 pub fn deleteFileZ(self: Dir, sub_path_c: [*:0]const u8) DeleteFileError!void {
1620 os.unlinkatZ(self.fd, sub_path_c, 0) catch |err| switch (err) {1601 os.unlinkatZ(self.fd, sub_path_c, 0) catch |err| switch (err) {
...@@ -1788,8 +1769,6 @@ pub const Dir = struct {...@@ -1788,8 +1769,6 @@ pub const Dir = struct {
1788 return self.readLinkZ(&sub_path_c, buffer);1769 return self.readLinkZ(&sub_path_c, buffer);
1789 }1770 }
17901771
1791 pub const readLinkC = @compileError("deprecated: renamed to readLinkZ");
1792
1793 /// WASI-only. Same as `readLink` except targeting WASI.1772 /// WASI-only. Same as `readLink` except targeting WASI.
1794 pub fn readLinkWasi(self: Dir, sub_path: []const u8, buffer: []u8) ![]u8 {1773 pub fn readLinkWasi(self: Dir, sub_path: []const u8, buffer: []u8) ![]u8 {
1795 return os.readlinkatWasi(self.fd, sub_path, buffer);1774 return os.readlinkatWasi(self.fd, sub_path, buffer);
...@@ -2275,8 +2254,6 @@ pub fn openFileAbsolute(absolute_path: []const u8, flags: File.OpenFlags) File.O...@@ -2275,8 +2254,6 @@ pub fn openFileAbsolute(absolute_path: []const u8, flags: File.OpenFlags) File.O
2275 return cwd().openFile(absolute_path, flags);2254 return cwd().openFile(absolute_path, flags);
2276}2255}
22772256
2278pub const openFileAbsoluteC = @compileError("deprecated: renamed to openFileAbsoluteZ");
2279
2280/// Same as `openFileAbsolute` but the path parameter is null-terminated.2257/// Same as `openFileAbsolute` but the path parameter is null-terminated.
2281pub fn openFileAbsoluteZ(absolute_path_c: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File {2258pub fn openFileAbsoluteZ(absolute_path_c: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File {
2282 assert(path.isAbsoluteZ(absolute_path_c));2259 assert(path.isAbsoluteZ(absolute_path_c));
...@@ -2330,8 +2307,6 @@ pub fn createFileAbsolute(absolute_path: []const u8, flags: File.CreateFlags) Fi...@@ -2330,8 +2307,6 @@ pub fn createFileAbsolute(absolute_path: []const u8, flags: File.CreateFlags) Fi
2330 return cwd().createFile(absolute_path, flags);2307 return cwd().createFile(absolute_path, flags);
2331}2308}
23322309
2333pub const createFileAbsoluteC = @compileError("deprecated: renamed to createFileAbsoluteZ");
2334
2335/// Same as `createFileAbsolute` but the path parameter is null-terminated.2310/// Same as `createFileAbsolute` but the path parameter is null-terminated.
2336pub fn createFileAbsoluteZ(absolute_path_c: [*:0]const u8, flags: File.CreateFlags) File.OpenError!File {2311pub fn createFileAbsoluteZ(absolute_path_c: [*:0]const u8, flags: File.CreateFlags) File.OpenError!File {
2337 assert(path.isAbsoluteZ(absolute_path_c));2312 assert(path.isAbsoluteZ(absolute_path_c));
...@@ -2353,8 +2328,6 @@ pub fn deleteFileAbsolute(absolute_path: []const u8) Dir.DeleteFileError!void {...@@ -2353,8 +2328,6 @@ pub fn deleteFileAbsolute(absolute_path: []const u8) Dir.DeleteFileError!void {
2353 return cwd().deleteFile(absolute_path);2328 return cwd().deleteFile(absolute_path);
2354}2329}
23552330
2356pub const deleteFileAbsoluteC = @compileError("deprecated: renamed to deleteFileAbsoluteZ");
2357
2358/// Same as `deleteFileAbsolute` except the parameter is null-terminated.2331/// Same as `deleteFileAbsolute` except the parameter is null-terminated.
2359pub fn deleteFileAbsoluteZ(absolute_path_c: [*:0]const u8) Dir.DeleteFileError!void {2332pub fn deleteFileAbsoluteZ(absolute_path_c: [*:0]const u8) Dir.DeleteFileError!void {
2360 assert(path.isAbsoluteZ(absolute_path_c));2333 assert(path.isAbsoluteZ(absolute_path_c));
...@@ -2405,9 +2378,6 @@ pub fn readLinkAbsoluteZ(pathname_c: [*:0]const u8, buffer: *[MAX_PATH_BYTES]u8)...@@ -2405,9 +2378,6 @@ pub fn readLinkAbsoluteZ(pathname_c: [*:0]const u8, buffer: *[MAX_PATH_BYTES]u8)
2405 return os.readlinkZ(pathname_c, buffer);2378 return os.readlinkZ(pathname_c, buffer);
2406}2379}
24072380
2408pub const readLink = @compileError("deprecated; use Dir.readLink or readLinkAbsolute");
2409pub const readLinkC = @compileError("deprecated; use Dir.readLinkZ or readLinkAbsoluteZ");
2410
2411/// Use with `Dir.symLink` and `symLinkAbsolute` to specify whether the symlink2381/// Use with `Dir.symLink` and `symLinkAbsolute` to specify whether the symlink
2412/// will point to a file or a directory. This value is ignored on all hosts2382/// will point to a file or a directory. This value is ignored on all hosts
2413/// except Windows where creating symlinks to different resource types, requires2383/// except Windows where creating symlinks to different resource types, requires
...@@ -2458,11 +2428,6 @@ pub fn symLinkAbsoluteZ(target_path_c: [*:0]const u8, sym_link_path_c: [*:0]cons...@@ -2458,11 +2428,6 @@ pub fn symLinkAbsoluteZ(target_path_c: [*:0]const u8, sym_link_path_c: [*:0]cons
2458 return os.symlinkZ(target_path_c, sym_link_path_c);2428 return os.symlinkZ(target_path_c, sym_link_path_c);
2459}2429}
24602430
2461pub const symLink = @compileError("deprecated: use Dir.symLink or symLinkAbsolute");
2462pub const symLinkC = @compileError("deprecated: use Dir.symLinkZ or symLinkAbsoluteZ");
2463
2464pub const walkPath = @compileError("deprecated: use Dir.walk");
2465
2466pub const OpenSelfExeError = error{2431pub const OpenSelfExeError = error{
2467 SharingViolation,2432 SharingViolation,
2468 PathAlreadyExists,2433 PathAlreadyExists,
...@@ -2544,14 +2509,14 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {...@@ -2544,14 +2509,14 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
2544 var out_len: usize = out_buffer.len;2509 var out_len: usize = out_buffer.len;
2545 try os.sysctl(&mib, out_buffer.ptr, &out_len, null, 0);2510 try os.sysctl(&mib, out_buffer.ptr, &out_len, null, 0);
2546 // TODO could this slice from 0 to out_len instead?2511 // TODO could this slice from 0 to out_len instead?
2547 return mem.spanZ(std.meta.assumeSentinel(out_buffer.ptr, 0));2512 return mem.sliceTo(std.meta.assumeSentinel(out_buffer.ptr, 0), 0);
2548 },2513 },
2549 .netbsd => {2514 .netbsd => {
2550 var mib = [4]c_int{ os.CTL.KERN, os.KERN.PROC_ARGS, -1, os.KERN.PROC_PATHNAME };2515 var mib = [4]c_int{ os.CTL.KERN, os.KERN.PROC_ARGS, -1, os.KERN.PROC_PATHNAME };
2551 var out_len: usize = out_buffer.len;2516 var out_len: usize = out_buffer.len;
2552 try os.sysctl(&mib, out_buffer.ptr, &out_len, null, 0);2517 try os.sysctl(&mib, out_buffer.ptr, &out_len, null, 0);
2553 // TODO could this slice from 0 to out_len instead?2518 // TODO could this slice from 0 to out_len instead?
2554 return mem.spanZ(std.meta.assumeSentinel(out_buffer.ptr, 0));2519 return mem.sliceTo(std.meta.assumeSentinel(out_buffer.ptr, 0), 0);
2555 },2520 },
2556 .openbsd, .haiku => {2521 .openbsd, .haiku => {
2557 // OpenBSD doesn't support getting the path of a running process, so try to guess it2522 // OpenBSD doesn't support getting the path of a running process, so try to guess it
...@@ -2603,7 +2568,7 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {...@@ -2603,7 +2568,7 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
2603/// The result is UTF16LE-encoded.2568/// The result is UTF16LE-encoded.
2604pub fn selfExePathW() [:0]const u16 {2569pub fn selfExePathW() [:0]const u16 {
2605 const image_path_name = &os.windows.peb().ProcessParameters.ImagePathName;2570 const image_path_name = &os.windows.peb().ProcessParameters.ImagePathName;
2606 return mem.spanZ(std.meta.assumeSentinel(image_path_name.Buffer, 0));2571 return mem.sliceTo(std.meta.assumeSentinel(image_path_name.Buffer, 0), 0);
2607}2572}
26082573
2609/// `selfExeDirPath` except allocates the result on the heap.2574/// `selfExeDirPath` except allocates the result on the heap.
lib/std/fs/get_app_data_dir.zig+2-2
...@@ -24,7 +24,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD...@@ -24,7 +24,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
24 )) {24 )) {
25 os.windows.S_OK => {25 os.windows.S_OK => {
26 defer os.windows.ole32.CoTaskMemFree(@ptrCast(*c_void, dir_path_ptr));26 defer os.windows.ole32.CoTaskMemFree(@ptrCast(*c_void, dir_path_ptr));
27 const global_dir = unicode.utf16leToUtf8Alloc(allocator, mem.spanZ(dir_path_ptr)) catch |err| switch (err) {27 const global_dir = unicode.utf16leToUtf8Alloc(allocator, mem.sliceTo(dir_path_ptr, 0)) catch |err| switch (err) {
28 error.UnexpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,28 error.UnexpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,
29 error.ExpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,29 error.ExpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,
30 error.DanglingSurrogateHalf => return error.AppDataDirUnavailable,30 error.DanglingSurrogateHalf => return error.AppDataDirUnavailable,
...@@ -56,7 +56,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD...@@ -56,7 +56,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
56 // TODO look into directory_which56 // TODO look into directory_which
57 const be_user_settings = 0xbbe;57 const be_user_settings = 0xbbe;
58 const rc = os.system.find_directory(be_user_settings, -1, true, dir_path_ptr, 1);58 const rc = os.system.find_directory(be_user_settings, -1, true, dir_path_ptr, 1);
59 const settings_dir = try allocator.dupeZ(u8, mem.spanZ(dir_path_ptr));59 const settings_dir = try allocator.dupeZ(u8, mem.sliceTo(dir_path_ptr, 0));
60 defer allocator.free(settings_dir);60 defer allocator.free(settings_dir);
61 switch (rc) {61 switch (rc) {
62 0 => return fs.path.join(allocator, &[_][]const u8{ settings_dir, appname }),62 0 => return fs.path.join(allocator, &[_][]const u8{ settings_dir, appname }),
lib/std/fs/path.zig+3-9
...@@ -187,8 +187,6 @@ test "join" {...@@ -187,8 +187,6 @@ test "join" {
187 }187 }
188}188}
189189
190pub const isAbsoluteC = @compileError("deprecated: renamed to isAbsoluteZ");
191
192pub fn isAbsoluteZ(path_c: [*:0]const u8) bool {190pub fn isAbsoluteZ(path_c: [*:0]const u8) bool {
193 if (native_os == .windows) {191 if (native_os == .windows) {
194 return isAbsoluteWindowsZ(path_c);192 return isAbsoluteWindowsZ(path_c);
...@@ -233,27 +231,23 @@ pub fn isAbsoluteWindows(path: []const u8) bool {...@@ -233,27 +231,23 @@ pub fn isAbsoluteWindows(path: []const u8) bool {
233}231}
234232
235pub fn isAbsoluteWindowsW(path_w: [*:0]const u16) bool {233pub fn isAbsoluteWindowsW(path_w: [*:0]const u16) bool {
236 return isAbsoluteWindowsImpl(u16, mem.spanZ(path_w));234 return isAbsoluteWindowsImpl(u16, mem.sliceTo(path_w, 0));
237}235}
238236
239pub fn isAbsoluteWindowsWTF16(path: []const u16) bool {237pub fn isAbsoluteWindowsWTF16(path: []const u16) bool {
240 return isAbsoluteWindowsImpl(u16, path);238 return isAbsoluteWindowsImpl(u16, path);
241}239}
242240
243pub const isAbsoluteWindowsC = @compileError("deprecated: renamed to isAbsoluteWindowsZ");
244
245pub fn isAbsoluteWindowsZ(path_c: [*:0]const u8) bool {241pub fn isAbsoluteWindowsZ(path_c: [*:0]const u8) bool {
246 return isAbsoluteWindowsImpl(u8, mem.spanZ(path_c));242 return isAbsoluteWindowsImpl(u8, mem.sliceTo(path_c, 0));
247}243}
248244
249pub fn isAbsolutePosix(path: []const u8) bool {245pub fn isAbsolutePosix(path: []const u8) bool {
250 return path.len > 0 and path[0] == sep_posix;246 return path.len > 0 and path[0] == sep_posix;
251}247}
252248
253pub const isAbsolutePosixC = @compileError("deprecated: renamed to isAbsolutePosixZ");
254
255pub fn isAbsolutePosixZ(path_c: [*:0]const u8) bool {249pub fn isAbsolutePosixZ(path_c: [*:0]const u8) bool {
256 return isAbsolutePosix(mem.spanZ(path_c));250 return isAbsolutePosix(mem.sliceTo(path_c, 0));
257}251}
258252
259test "isAbsoluteWindows" {253test "isAbsoluteWindows" {
lib/std/hash/benchmark.zig+1-1
...@@ -142,7 +142,7 @@ pub fn benchmarkHashSmallKeys(comptime H: anytype, key_size: usize, bytes: usize...@@ -142,7 +142,7 @@ pub fn benchmarkHashSmallKeys(comptime H: anytype, key_size: usize, bytes: usize
142}142}
143143
144fn usage() void {144fn usage() void {
145 std.debug.warn(145 std.debug.print(
146 \\throughput_test [options]146 \\throughput_test [options]
147 \\147 \\
148 \\Options:148 \\Options:
lib/std/hash_map.zig+5-20
...@@ -2,7 +2,6 @@ const std = @import("std.zig");...@@ -2,7 +2,6 @@ const std = @import("std.zig");
2const assert = debug.assert;2const assert = debug.assert;
3const autoHash = std.hash.autoHash;3const autoHash = std.hash.autoHash;
4const debug = std.debug;4const debug = std.debug;
5const warn = debug.warn;
6const math = std.math;5const math = std.math;
7const mem = std.mem;6const mem = std.mem;
8const meta = std.meta;7const meta = std.meta;
...@@ -101,7 +100,7 @@ pub const StringIndexContext = struct {...@@ -101,7 +100,7 @@ pub const StringIndexContext = struct {
101 }100 }
102101
103 pub fn hash(self: @This(), x: u32) u64 {102 pub fn hash(self: @This(), x: u32) u64 {
104 const x_slice = mem.spanZ(@ptrCast([*:0]const u8, self.bytes.items.ptr) + x);103 const x_slice = mem.sliceTo(@ptrCast([*:0]const u8, self.bytes.items.ptr) + x, 0);
105 return hashString(x_slice);104 return hashString(x_slice);
106 }105 }
107};106};
...@@ -110,7 +109,7 @@ pub const StringIndexAdapter = struct {...@@ -110,7 +109,7 @@ pub const StringIndexAdapter = struct {
110 bytes: *std.ArrayListUnmanaged(u8),109 bytes: *std.ArrayListUnmanaged(u8),
111110
112 pub fn eql(self: @This(), a_slice: []const u8, b: u32) bool {111 pub fn eql(self: @This(), a_slice: []const u8, b: u32) bool {
113 const b_slice = mem.spanZ(@ptrCast([*:0]const u8, self.bytes.items.ptr) + b);112 const b_slice = mem.sliceTo(@ptrCast([*:0]const u8, self.bytes.items.ptr) + b, 0);
114 return mem.eql(u8, a_slice, b_slice);113 return mem.eql(u8, a_slice, b_slice);
115 }114 }
116115
...@@ -120,8 +119,7 @@ pub const StringIndexAdapter = struct {...@@ -120,8 +119,7 @@ pub const StringIndexAdapter = struct {
120 }119 }
121};120};
122121
123/// Deprecated use `default_max_load_percentage`122pub const DefaultMaxLoadPercentage = @compileError("deprecated; use `default_max_load_percentage`");
124pub const DefaultMaxLoadPercentage = default_max_load_percentage;
125123
126pub const default_max_load_percentage = 80;124pub const default_max_load_percentage = 80;
127125
...@@ -506,8 +504,7 @@ pub fn HashMap(...@@ -506,8 +504,7 @@ pub fn HashMap(
506 return self.unmanaged.getOrPutValueContext(self.allocator, key, value, self.ctx);504 return self.unmanaged.getOrPutValueContext(self.allocator, key, value, self.ctx);
507 }505 }
508506
509 /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.507 pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`");
510 pub const ensureCapacity = ensureTotalCapacity;
511508
512 /// Increases capacity, guaranteeing that insertions up until the509 /// Increases capacity, guaranteeing that insertions up until the
513 /// `expected_count` will not cause an allocation, and therefore cannot fail.510 /// `expected_count` will not cause an allocation, and therefore cannot fail.
...@@ -873,8 +870,7 @@ pub fn HashMapUnmanaged(...@@ -873,8 +870,7 @@ pub fn HashMapUnmanaged(
873 return new_cap;870 return new_cap;
874 }871 }
875872
876 /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.873 pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`");
877 pub const ensureCapacity = ensureTotalCapacity;
878874
879 pub fn ensureTotalCapacity(self: *Self, allocator: *Allocator, new_size: Size) !void {875 pub fn ensureTotalCapacity(self: *Self, allocator: *Allocator, new_size: Size) !void {
880 if (@sizeOf(Context) != 0)876 if (@sizeOf(Context) != 0)
...@@ -2045,14 +2041,3 @@ test "std.hash_map ensureUnusedCapacity" {...@@ -2045,14 +2041,3 @@ test "std.hash_map ensureUnusedCapacity" {
2045 // should not change the capacity.2041 // should not change the capacity.
2046 try testing.expectEqual(capacity, map.capacity());2042 try testing.expectEqual(capacity, map.capacity());
2047}2043}
2048
2049test "compile everything" {
2050 std.testing.refAllDecls(AutoHashMap(i32, i32));
2051 std.testing.refAllDecls(StringHashMap([]const u8));
2052 std.testing.refAllDecls(AutoHashMap(i32, void));
2053 std.testing.refAllDecls(StringHashMap(u0));
2054 std.testing.refAllDecls(AutoHashMapUnmanaged(i32, i32));
2055 std.testing.refAllDecls(StringHashMapUnmanaged([]const u8));
2056 std.testing.refAllDecls(AutoHashMapUnmanaged(i32, void));
2057 std.testing.refAllDecls(StringHashMapUnmanaged(u0));
2058}
lib/std/io.zig+3-7
...@@ -142,10 +142,9 @@ pub const changeDetectionStream = @import("io/change_detection_stream.zig").chan...@@ -142,10 +142,9 @@ pub const changeDetectionStream = @import("io/change_detection_stream.zig").chan
142142
143pub const FindByteWriter = @import("io/find_byte_writer.zig").FindByteWriter;143pub const FindByteWriter = @import("io/find_byte_writer.zig").FindByteWriter;
144pub const findByteWriter = @import("io/find_byte_writer.zig").findByteWriter;144pub const findByteWriter = @import("io/find_byte_writer.zig").findByteWriter;
145/// Deprecated: use `FindByteWriter`.145
146pub const FindByteOutStream = FindByteWriter;146pub const FindByteOutStream = @compileError("deprecated; use `FindByteWriter`");
147/// Deprecated: use `findByteWriter`.147pub const findByteOutStream = @compileError("deprecated; use `findByteWriter`");
148pub const findByteOutStream = findByteWriter;
149148
150pub const BufferedAtomicFile = @import("io/buffered_atomic_file.zig").BufferedAtomicFile;149pub const BufferedAtomicFile = @import("io/buffered_atomic_file.zig").BufferedAtomicFile;
151150
...@@ -181,6 +180,3 @@ test {...@@ -181,6 +180,3 @@ test {
181 _ = @import("io/stream_source.zig");180 _ = @import("io/stream_source.zig");
182 _ = @import("io/test.zig");181 _ = @import("io/test.zig");
183}182}
184
185pub const writeFile = @compileError("deprecated: use std.fs.Dir.writeFile with math.maxInt(usize)");
186pub const readFileAlloc = @compileError("deprecated: use std.fs.Dir.readFileAlloc");
lib/std/io/reader.zig+4-4
...@@ -45,10 +45,10 @@ pub fn Reader(...@@ -45,10 +45,10 @@ pub fn Reader(
45 if (amt_read < buf.len) return error.EndOfStream;45 if (amt_read < buf.len) return error.EndOfStream;
46 }46 }
4747
48 pub const readAllBuffer = @compileError("deprecated; use readAllArrayList()");48 /// Appends to the `std.ArrayList` contents by reading from the stream
4949 /// until end of stream is found.
50 /// Appends to the `std.ArrayList` contents by reading from the stream until end of stream is found.50 /// If the number of bytes appended would exceed `max_append_size`,
51 /// If the number of bytes appended would exceed `max_append_size`, `error.StreamTooLong` is returned51 /// `error.StreamTooLong` is returned
52 /// and the `std.ArrayList` has exactly `max_append_size` bytes appended.52 /// and the `std.ArrayList` has exactly `max_append_size` bytes appended.
53 pub fn readAllArrayList(self: Self, array_list: *std.ArrayList(u8), max_append_size: usize) !void {53 pub fn readAllArrayList(self: Self, array_list: *std.ArrayList(u8), max_append_size: usize) !void {
54 return self.readAllArrayListAligned(null, array_list, max_append_size);54 return self.readAllArrayListAligned(null, array_list, max_append_size);
lib/std/json.zig+2-2
...@@ -3135,7 +3135,7 @@ fn teststringify(expected: []const u8, value: anytype, options: StringifyOptions...@@ -3135,7 +3135,7 @@ fn teststringify(expected: []const u8, value: anytype, options: StringifyOptions
31353135
3136 fn write(self: *Self, bytes: []const u8) Error!usize {3136 fn write(self: *Self, bytes: []const u8) Error!usize {
3137 if (self.expected_remaining.len < bytes.len) {3137 if (self.expected_remaining.len < bytes.len) {
3138 std.debug.warn(3138 std.debug.print(
3139 \\====== expected this output: =========3139 \\====== expected this output: =========
3140 \\{s}3140 \\{s}
3141 \\======== instead found this: =========3141 \\======== instead found this: =========
...@@ -3148,7 +3148,7 @@ fn teststringify(expected: []const u8, value: anytype, options: StringifyOptions...@@ -3148,7 +3148,7 @@ fn teststringify(expected: []const u8, value: anytype, options: StringifyOptions
3148 return error.TooMuchData;3148 return error.TooMuchData;
3149 }3149 }
3150 if (!mem.eql(u8, self.expected_remaining[0..bytes.len], bytes)) {3150 if (!mem.eql(u8, self.expected_remaining[0..bytes.len], bytes)) {
3151 std.debug.warn(3151 std.debug.print(
3152 \\====== expected this output: =========3152 \\====== expected this output: =========
3153 \\{s}3153 \\{s}
3154 \\======== instead found this: =========3154 \\======== instead found this: =========
lib/std/log.zig+8-20
...@@ -174,14 +174,9 @@ pub fn defaultLog(...@@ -174,14 +174,9 @@ pub fn defaultLog(
174/// provided here.174/// provided here.
175pub fn scoped(comptime scope: @Type(.EnumLiteral)) type {175pub fn scoped(comptime scope: @Type(.EnumLiteral)) type {
176 return struct {176 return struct {
177 /// Deprecated. TODO: replace with @compileError() after 0.9.0 is released177 pub const emerg = @compileError("deprecated; use err instead of emerg");
178 pub const emerg = @This().err;178 pub const alert = @compileError("deprecated; use err instead of alert");
179179 pub const crit = @compileError("deprecated; use err instead of crit");
180 /// Deprecated. TODO: replace with @compileError() after 0.9.0 is released
181 pub const alert = @This().err;
182
183 /// Deprecated. TODO: replace with @compileError() after 0.9.0 is released
184 pub const crit = @This().err;
185180
186 /// Log an error message. This log level is intended to be used181 /// Log an error message. This log level is intended to be used
187 /// when something has gone wrong. This might be recoverable or might182 /// when something has gone wrong. This might be recoverable or might
...@@ -204,8 +199,7 @@ pub fn scoped(comptime scope: @Type(.EnumLiteral)) type {...@@ -204,8 +199,7 @@ pub fn scoped(comptime scope: @Type(.EnumLiteral)) type {
204 log(.warn, scope, format, args);199 log(.warn, scope, format, args);
205 }200 }
206201
207 /// Deprecated. TODO: replace with @compileError() after 0.9.0 is released202 pub const notice = @compileError("deprecated; use info instead of notice");
208 pub const notice = @This().info;
209203
210 /// Log an info message. This log level is intended to be used for204 /// Log an info message. This log level is intended to be used for
211 /// general messages about the state of the program.205 /// general messages about the state of the program.
...@@ -230,14 +224,9 @@ pub fn scoped(comptime scope: @Type(.EnumLiteral)) type {...@@ -230,14 +224,9 @@ pub fn scoped(comptime scope: @Type(.EnumLiteral)) type {
230/// The default scoped logging namespace.224/// The default scoped logging namespace.
231pub const default = scoped(.default);225pub const default = scoped(.default);
232226
233/// Deprecated. TODO: replace with @compileError() after 0.9.0 is released227pub const emerg = @compileError("deprecated; use err instead of emerg");
234pub const emerg = default.err;228pub const alert = @compileError("deprecated; use err instead of alert");
235229pub const crit = @compileError("deprecated; use err instead of crit");
236/// Deprecated. TODO: replace with @compileError() after 0.9.0 is released
237pub const alert = default.err;
238
239/// Deprecated. TODO: replace with @compileError() after 0.9.0 is released
240pub const crit = default.err;
241230
242/// Log an error message using the default scope. This log level is intended to231/// Log an error message using the default scope. This log level is intended to
243/// be used when something has gone wrong. This might be recoverable or might232/// be used when something has gone wrong. This might be recoverable or might
...@@ -249,8 +238,7 @@ pub const err = default.err;...@@ -249,8 +238,7 @@ pub const err = default.err;
249/// the circumstances would be worth investigating.238/// the circumstances would be worth investigating.
250pub const warn = default.warn;239pub const warn = default.warn;
251240
252/// Deprecated. TODO: replace with @compileError() after 0.9.0 is released241pub const notice = @compileError("deprecated; use info instead of notice");
253pub const notice = default.info;
254242
255/// Log an info message using the default scope. This log level is intended to243/// Log an info message using the default scope. This log level is intended to
256/// be used for general messages about the state of the program.244/// be used for general messages about the state of the program.
lib/std/math.zig+7-2
...@@ -158,8 +158,13 @@ pub fn approxEqRel(comptime T: type, x: T, y: T, tolerance: T) bool {...@@ -158,8 +158,13 @@ pub fn approxEqRel(comptime T: type, x: T, y: T, tolerance: T) bool {
158 return fabs(x - y) <= max(fabs(x), fabs(y)) * tolerance;158 return fabs(x - y) <= max(fabs(x), fabs(y)) * tolerance;
159}159}
160160
161/// Deprecated, use `approxEqAbs` or `approxEqRel`.161pub fn approxEq(comptime T: type, x: T, y: T, tolerance: T) bool {
162pub const approxEq = approxEqAbs;162 _ = T;
163 _ = x;
164 _ = y;
165 _ = tolerance;
166 @compileError("deprecated; use `approxEqAbs` or `approxEqRel`");
167}
163168
164test "approxEqAbs and approxEqRel" {169test "approxEqAbs and approxEqRel" {
165 inline for ([_]type{ f16, f32, f64, f128 }) |T| {170 inline for ([_]type{ f16, f32, f64, f128 }) |T| {
lib/std/math/big/int.zig+6-6
...@@ -185,9 +185,9 @@ pub const Mutable = struct {...@@ -185,9 +185,9 @@ pub const Mutable = struct {
185185
186 pub fn dump(self: Mutable) void {186 pub fn dump(self: Mutable) void {
187 for (self.limbs[0..self.len]) |limb| {187 for (self.limbs[0..self.len]) |limb| {
188 std.debug.warn("{x} ", .{limb});188 std.debug.print("{x} ", .{limb});
189 }189 }
190 std.debug.warn("capacity={} positive={}\n", .{ self.limbs.len, self.positive });190 std.debug.print("capacity={} positive={}\n", .{ self.limbs.len, self.positive });
191 }191 }
192192
193 /// Clones an Mutable and returns a new Mutable with the same value. The new Mutable is a deep copy and193 /// Clones an Mutable and returns a new Mutable with the same value. The new Mutable is a deep copy and
...@@ -1685,9 +1685,9 @@ pub const Const = struct {...@@ -1685,9 +1685,9 @@ pub const Const = struct {
16851685
1686 pub fn dump(self: Const) void {1686 pub fn dump(self: Const) void {
1687 for (self.limbs[0..self.limbs.len]) |limb| {1687 for (self.limbs[0..self.limbs.len]) |limb| {
1688 std.debug.warn("{x} ", .{limb});1688 std.debug.print("{x} ", .{limb});
1689 }1689 }
1690 std.debug.warn("positive={}\n", .{self.positive});1690 std.debug.print("positive={}\n", .{self.positive});
1691 }1691 }
16921692
1693 pub fn abs(self: Const) Const {1693 pub fn abs(self: Const) Const {
...@@ -2237,9 +2237,9 @@ pub const Managed = struct {...@@ -2237,9 +2237,9 @@ pub const Managed = struct {
2237 /// Debugging tool: prints the state to stderr.2237 /// Debugging tool: prints the state to stderr.
2238 pub fn dump(self: Managed) void {2238 pub fn dump(self: Managed) void {
2239 for (self.limbs[0..self.len()]) |limb| {2239 for (self.limbs[0..self.len()]) |limb| {
2240 std.debug.warn("{x} ", .{limb});2240 std.debug.print("{x} ", .{limb});
2241 }2241 }
2242 std.debug.warn("capacity={} positive={}\n", .{ self.limbs.len, self.isPositive() });2242 std.debug.print("capacity={} positive={}\n", .{ self.limbs.len, self.isPositive() });
2243 }2243 }
22442244
2245 /// Negate the sign.2245 /// Negate the sign.
lib/std/math/complex.zig+1-2
...@@ -34,8 +34,7 @@ pub fn Complex(comptime T: type) type {...@@ -34,8 +34,7 @@ pub fn Complex(comptime T: type) type {
34 /// Imaginary part.34 /// Imaginary part.
35 im: T,35 im: T,
3636
37 /// Deprecated, use init()37 pub const new = @compileError("deprecated; use init()");
38 pub const new = init;
3938
40 /// Create a new Complex number from the given real and imaginary parts.39 /// Create a new Complex number from the given real and imaginary parts.
41 pub fn init(re: T, im: T) Self {40 pub fn init(re: T, im: T) Self {
lib/std/mem.zig+5-98
...@@ -553,9 +553,6 @@ test "indexOfDiff" {...@@ -553,9 +553,6 @@ test "indexOfDiff" {
553 try testing.expectEqual(indexOfDiff(u8, "xne", "one"), 0);553 try testing.expectEqual(indexOfDiff(u8, "xne", "one"), 0);
554}554}
555555
556pub const toSliceConst = @compileError("deprecated; use std.mem.spanZ");
557pub const toSlice = @compileError("deprecated; use std.mem.spanZ");
558
559/// Takes a pointer to an array, a sentinel-terminated pointer, or a slice, and556/// Takes a pointer to an array, a sentinel-terminated pointer, or a slice, and
560/// returns a slice. If there is a sentinel on the input type, there will be a557/// returns a slice. If there is a sentinel on the input type, there will be a
561/// sentinel on the output type. The constness of the output type matches558/// sentinel on the output type. The constness of the output type matches
...@@ -644,34 +641,7 @@ test "span" {...@@ -644,34 +641,7 @@ test "span" {
644 try testing.expectEqual(@as(?[:0]u16, null), span(@as(?[*:0]u16, null)));641 try testing.expectEqual(@as(?[:0]u16, null), span(@as(?[*:0]u16, null)));
645}642}
646643
647/// Deprecated: use std.mem.span() or std.mem.sliceTo()644pub const spanZ = @compileError("deprecated; use use std.mem.span() or std.mem.sliceTo()");
648/// Same as `span`, except when there is both a sentinel and an array
649/// length or slice length, scans the memory for the sentinel value
650/// rather than using the length.
651pub fn spanZ(ptr: anytype) Span(@TypeOf(ptr)) {
652 if (@typeInfo(@TypeOf(ptr)) == .Optional) {
653 if (ptr) |non_null| {
654 return spanZ(non_null);
655 } else {
656 return null;
657 }
658 }
659 const Result = Span(@TypeOf(ptr));
660 const l = lenZ(ptr);
661 if (@typeInfo(Result).Pointer.sentinel) |s| {
662 return ptr[0..l :s];
663 } else {
664 return ptr[0..l];
665 }
666}
667
668test "spanZ" {
669 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
670 const ptr = @as([*:3]u16, array[0..2 :3]);
671 try testing.expect(eql(u16, spanZ(ptr), &[_]u16{ 1, 2 }));
672 try testing.expect(eql(u16, spanZ(&array), &[_]u16{ 1, 2, 3, 4, 5 }));
673 try testing.expectEqual(@as(?[:0]u16, null), spanZ(@as(?[*:0]u16, null)));
674}
675645
676/// Helper for the return type of sliceTo()646/// Helper for the return type of sliceTo()
677fn SliceTo(comptime T: type, comptime end: meta.Elem(T)) type {647fn SliceTo(comptime T: type, comptime end: meta.Elem(T)) type {
...@@ -917,61 +887,7 @@ test "len" {...@@ -917,61 +887,7 @@ test "len" {
917 }887 }
918}888}
919889
920/// Deprecated: use std.mem.len() or std.mem.sliceTo().len890pub const lenZ = @compileError("deprecated; use std.mem.len() or std.mem.sliceTo().len");
921/// Takes a pointer to an array, an array, a sentinel-terminated pointer,
922/// or a slice, and returns the length.
923/// In the case of a sentinel-terminated array, it scans the array
924/// for a sentinel and uses that for the length, rather than using the array length.
925/// For C pointers it assumes it is a pointer-to-many with a 0 sentinel.
926pub fn lenZ(ptr: anytype) usize {
927 return switch (@typeInfo(@TypeOf(ptr))) {
928 .Array => |info| if (info.sentinel) |sentinel|
929 indexOfSentinel(info.child, sentinel, &ptr)
930 else
931 info.len,
932 .Pointer => |info| switch (info.size) {
933 .One => switch (@typeInfo(info.child)) {
934 .Array => |x| if (x.sentinel) |sentinel|
935 indexOfSentinel(x.child, sentinel, ptr)
936 else
937 ptr.len,
938 else => @compileError("invalid type given to std.mem.lenZ"),
939 },
940 .Many => if (info.sentinel) |sentinel|
941 indexOfSentinel(info.child, sentinel, ptr)
942 else
943 @compileError("length of pointer with no sentinel"),
944 .C => {
945 assert(ptr != null);
946 return indexOfSentinel(info.child, 0, ptr);
947 },
948 .Slice => if (info.sentinel) |sentinel|
949 indexOfSentinel(info.child, sentinel, ptr.ptr)
950 else
951 ptr.len,
952 },
953 else => @compileError("invalid type given to std.mem.lenZ"),
954 };
955}
956
957test "lenZ" {
958 try testing.expect(lenZ("aoeu") == 4);
959
960 {
961 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
962 try testing.expect(lenZ(&array) == 5);
963 try testing.expect(lenZ(array[0..3]) == 3);
964 array[2] = 0;
965 const ptr = @as([*:0]u16, array[0..2 :0]);
966 try testing.expect(lenZ(ptr) == 2);
967 }
968 {
969 var array: [5:0]u16 = [_:0]u16{ 1, 2, 3, 4, 5 };
970 try testing.expect(lenZ(&array) == 5);
971 array[2] = 0;
972 try testing.expect(lenZ(&array) == 2);
973 }
974}
975891
976pub fn indexOfSentinel(comptime Elem: type, comptime sentinel: Elem, ptr: [*:sentinel]const Elem) usize {892pub fn indexOfSentinel(comptime Elem: type, comptime sentinel: Elem, ptr: [*:sentinel]const Elem) usize {
977 var i: usize = 0;893 var i: usize = 0;
...@@ -989,15 +905,8 @@ pub fn allEqual(comptime T: type, slice: []const T, scalar: T) bool {...@@ -989,15 +905,8 @@ pub fn allEqual(comptime T: type, slice: []const T, scalar: T) bool {
989 return true;905 return true;
990}906}
991907
992/// Deprecated, use `Allocator.dupe`.908pub const dupe = @compileError("deprecated; use `Allocator.dupe`");
993pub fn dupe(allocator: *Allocator, comptime T: type, m: []const T) ![]T {909pub const dupeZ = @compileError("deprecated; use `Allocator.dupeZ`");
994 return allocator.dupe(T, m);
995}
996
997/// Deprecated, use `Allocator.dupeZ`.
998pub fn dupeZ(allocator: *Allocator, comptime T: type, m: []const T) ![:0]T {
999 return allocator.dupeZ(T, m);
1000}
1001910
1002/// Remove values from the beginning of a slice.911/// Remove values from the beginning of a slice.
1003pub fn trimLeft(comptime T: type, slice: []const T, values_to_strip: []const T) []const T {912pub fn trimLeft(comptime T: type, slice: []const T, values_to_strip: []const T) []const T {
...@@ -1727,8 +1636,6 @@ pub fn split(comptime T: type, buffer: []const T, delimiter: []const T) SplitIte...@@ -1727,8 +1636,6 @@ pub fn split(comptime T: type, buffer: []const T, delimiter: []const T) SplitIte
1727 };1636 };
1728}1637}
17291638
1730pub const separate = @compileError("deprecated: renamed to split (behavior remains unchanged)");
1731
1732test "mem.split" {1639test "mem.split" {
1733 var it = split(u8, "abc|def||ghi", "|");1640 var it = split(u8, "abc|def||ghi", "|");
1734 try testing.expect(eql(u8, it.next().?, "abc"));1641 try testing.expect(eql(u8, it.next().?, "abc"));
...@@ -3024,7 +2931,7 @@ test "isAligned" {...@@ -3024,7 +2931,7 @@ test "isAligned" {
3024}2931}
30252932
3026test "freeing empty string with null-terminated sentinel" {2933test "freeing empty string with null-terminated sentinel" {
3027 const empty_string = try dupeZ(testing.allocator, u8, "");2934 const empty_string = try testing.allocator.dupeZ(u8, "");
3028 testing.allocator.free(empty_string);2935 testing.allocator.free(empty_string);
3029}2936}
30302937
lib/std/mem/Allocator.zig-1
...@@ -235,7 +235,6 @@ pub fn allocSentinel(...@@ -235,7 +235,6 @@ pub fn allocSentinel(
235 return self.allocWithOptionsRetAddr(Elem, n, null, sentinel, @returnAddress());235 return self.allocWithOptionsRetAddr(Elem, n, null, sentinel, @returnAddress());
236}236}
237237
238/// Deprecated: use `allocAdvanced`
239pub fn alignedAlloc(238pub fn alignedAlloc(
240 self: *Allocator,239 self: *Allocator,
241 comptime T: type,240 comptime T: type,
lib/std/meta.zig+1-2
...@@ -594,8 +594,7 @@ test "std.meta.FieldEnum" {...@@ -594,8 +594,7 @@ test "std.meta.FieldEnum" {
594 try expectEqualEnum(enum { a, b, c }, FieldEnum(union { a: u8, b: void, c: f32 }));594 try expectEqualEnum(enum { a, b, c }, FieldEnum(union { a: u8, b: void, c: f32 }));
595}595}
596596
597// Deprecated: use Tag597pub const TagType = @compileError("deprecated; use Tag");
598pub const TagType = Tag;
599598
600pub fn Tag(comptime T: type) type {599pub fn Tag(comptime T: type) type {
601 return switch (@typeInfo(T)) {600 return switch (@typeInfo(T)) {
lib/std/meta/trait.zig-1
...@@ -2,7 +2,6 @@ const std = @import("../std.zig");...@@ -2,7 +2,6 @@ const std = @import("../std.zig");
2const mem = std.mem;2const mem = std.mem;
3const debug = std.debug;3const debug = std.debug;
4const testing = std.testing;4const testing = std.testing;
5const warn = debug.warn;
65
7const meta = @import("../meta.zig");6const meta = @import("../meta.zig");
87
lib/std/multi_array_list.zig+1-2
...@@ -309,8 +309,7 @@ pub fn MultiArrayList(comptime S: type) type {...@@ -309,8 +309,7 @@ pub fn MultiArrayList(comptime S: type) type {
309 self.len = new_len;309 self.len = new_len;
310 }310 }
311311
312 /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.312 pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`");
313 pub const ensureCapacity = ensureTotalCapacity;
314313
315 /// Modify the array so that it can hold at least `new_capacity` items.314 /// Modify the array so that it can hold at least `new_capacity` items.
316 /// Implements super-linear growth to achieve amortized O(1) append operations.315 /// Implements super-linear growth to achieve amortized O(1) append operations.
lib/std/net.zig+2-2
...@@ -785,7 +785,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*...@@ -785,7 +785,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
785785
786 if (info.canonname) |n| {786 if (info.canonname) |n| {
787 if (result.canon_name == null) {787 if (result.canon_name == null) {
788 result.canon_name = try arena.dupe(u8, mem.spanZ(n));788 result.canon_name = try arena.dupe(u8, mem.sliceTo(n, 0));
789 }789 }
790 }790 }
791 i += 1;791 i += 1;
...@@ -1588,7 +1588,7 @@ fn dnsParseCallback(ctx: dpc_ctx, rr: u8, data: []const u8, packet: []const u8)...@@ -1588,7 +1588,7 @@ fn dnsParseCallback(ctx: dpc_ctx, rr: u8, data: []const u8, packet: []const u8)
1588 var tmp: [256]u8 = undefined;1588 var tmp: [256]u8 = undefined;
1589 // Returns len of compressed name. strlen to get canon name.1589 // Returns len of compressed name. strlen to get canon name.
1590 _ = try os.dn_expand(packet, data, &tmp);1590 _ = try os.dn_expand(packet, data, &tmp);
1591 const canon_name = mem.spanZ(std.meta.assumeSentinel(&tmp, 0));1591 const canon_name = mem.sliceTo(std.meta.assumeSentinel(&tmp, 0), 0);
1592 if (isValidHostName(canon_name)) {1592 if (isValidHostName(canon_name)) {
1593 ctx.canon.items.len = 0;1593 ctx.canon.items.len = 0;
1594 try ctx.canon.appendSlice(canon_name);1594 try ctx.canon.appendSlice(canon_name);
lib/std/os.zig+10-52
...@@ -1289,8 +1289,6 @@ pub fn open(file_path: []const u8, flags: u32, perm: mode_t) OpenError!fd_t {...@@ -1289,8 +1289,6 @@ pub fn open(file_path: []const u8, flags: u32, perm: mode_t) OpenError!fd_t {
1289 return openZ(&file_path_c, flags, perm);1289 return openZ(&file_path_c, flags, perm);
1290}1290}
12911291
1292pub const openC = @compileError("deprecated: renamed to openZ");
1293
1294/// Open and possibly create a file. Keeps trying if it gets interrupted.1292/// Open and possibly create a file. Keeps trying if it gets interrupted.
1295/// See also `open`.1293/// See also `open`.
1296pub fn openZ(file_path: [*:0]const u8, flags: u32, perm: mode_t) OpenError!fd_t {1294pub fn openZ(file_path: [*:0]const u8, flags: u32, perm: mode_t) OpenError!fd_t {
...@@ -1429,8 +1427,6 @@ pub fn openatWasi(dir_fd: fd_t, file_path: []const u8, lookup_flags: lookupflags...@@ -1429,8 +1427,6 @@ pub fn openatWasi(dir_fd: fd_t, file_path: []const u8, lookup_flags: lookupflags
1429 }1427 }
1430}1428}
14311429
1432pub const openatC = @compileError("deprecated: renamed to openatZ");
1433
1434/// Open and possibly create a file. Keeps trying if it gets interrupted.1430/// Open and possibly create a file. Keeps trying if it gets interrupted.
1435/// `file_path` is relative to the open directory handle `dir_fd`.1431/// `file_path` is relative to the open directory handle `dir_fd`.
1436/// See also `openat`.1432/// See also `openat`.
...@@ -1529,8 +1525,6 @@ pub const ExecveError = error{...@@ -1529,8 +1525,6 @@ pub const ExecveError = error{
1529 NameTooLong,1525 NameTooLong,
1530} || UnexpectedError;1526} || UnexpectedError;
15311527
1532pub const execveC = @compileError("deprecated: use execveZ");
1533
1534/// Like `execve` except the parameters are null-terminated,1528/// Like `execve` except the parameters are null-terminated,
1535/// matching the syscall API on all targets. This removes the need for an allocator.1529/// matching the syscall API on all targets. This removes the need for an allocator.
1536/// This function ignores PATH environment variable. See `execvpeZ` for that.1530/// This function ignores PATH environment variable. See `execvpeZ` for that.
...@@ -1561,8 +1555,6 @@ pub fn execveZ(...@@ -1561,8 +1555,6 @@ pub fn execveZ(
1561 }1555 }
1562}1556}
15631557
1564pub const execvpeC = @compileError("deprecated in favor of execvpeZ");
1565
1566pub const Arg0Expand = enum {1558pub const Arg0Expand = enum {
1567 expand,1559 expand,
1568 no_expand,1560 no_expand,
...@@ -1580,7 +1572,7 @@ pub fn execvpeZ_expandArg0(...@@ -1580,7 +1572,7 @@ pub fn execvpeZ_expandArg0(
1580 },1572 },
1581 envp: [*:null]const ?[*:0]const u8,1573 envp: [*:null]const ?[*:0]const u8,
1582) ExecveError {1574) ExecveError {
1583 const file_slice = mem.spanZ(file);1575 const file_slice = mem.sliceTo(file, 0);
1584 if (mem.indexOfScalar(u8, file_slice, '/') != null) return execveZ(file, child_argv, envp);1576 if (mem.indexOfScalar(u8, file_slice, '/') != null) return execveZ(file, child_argv, envp);
15851577
1586 const PATH = getenvZ("PATH") orelse "/usr/local/bin:/bin/:/usr/bin";1578 const PATH = getenvZ("PATH") orelse "/usr/local/bin:/bin/:/usr/bin";
...@@ -1680,19 +1672,17 @@ pub fn getenv(key: []const u8) ?[]const u8 {...@@ -1680,19 +1672,17 @@ pub fn getenv(key: []const u8) ?[]const u8 {
1680 return null;1672 return null;
1681}1673}
16821674
1683pub const getenvC = @compileError("Deprecated in favor of `getenvZ`");
1684
1685/// Get an environment variable with a null-terminated name.1675/// Get an environment variable with a null-terminated name.
1686/// See also `getenv`.1676/// See also `getenv`.
1687pub fn getenvZ(key: [*:0]const u8) ?[]const u8 {1677pub fn getenvZ(key: [*:0]const u8) ?[]const u8 {
1688 if (builtin.link_libc) {1678 if (builtin.link_libc) {
1689 const value = system.getenv(key) orelse return null;1679 const value = system.getenv(key) orelse return null;
1690 return mem.spanZ(value);1680 return mem.sliceTo(value, 0);
1691 }1681 }
1692 if (builtin.os.tag == .windows) {1682 if (builtin.os.tag == .windows) {
1693 @compileError("std.os.getenvZ is unavailable for Windows because environment string is in WTF-16 format. See std.process.getEnvVarOwned for cross-platform API or std.os.getenvW for Windows-specific API.");1683 @compileError("std.os.getenvZ is unavailable for Windows because environment string is in WTF-16 format. See std.process.getEnvVarOwned for cross-platform API or std.os.getenvW for Windows-specific API.");
1694 }1684 }
1695 return getenv(mem.spanZ(key));1685 return getenv(mem.sliceTo(key, 0));
1696}1686}
16971687
1698/// Windows-only. Get an environment variable with a null-terminated, WTF-16 encoded name.1688/// Windows-only. Get an environment variable with a null-terminated, WTF-16 encoded name.
...@@ -1703,7 +1693,7 @@ pub fn getenvW(key: [*:0]const u16) ?[:0]const u16 {...@@ -1703,7 +1693,7 @@ pub fn getenvW(key: [*:0]const u16) ?[:0]const u16 {
1703 if (builtin.os.tag != .windows) {1693 if (builtin.os.tag != .windows) {
1704 @compileError("std.os.getenvW is a Windows-only API");1694 @compileError("std.os.getenvW is a Windows-only API");
1705 }1695 }
1706 const key_slice = mem.spanZ(key);1696 const key_slice = mem.sliceTo(key, 0);
1707 const ptr = windows.peb().ProcessParameters.Environment;1697 const ptr = windows.peb().ProcessParameters.Environment;
1708 var ascii_match: ?[:0]const u16 = null;1698 var ascii_match: ?[:0]const u16 = null;
1709 var i: usize = 0;1699 var i: usize = 0;
...@@ -1758,7 +1748,7 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {...@@ -1758,7 +1748,7 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
1758 break :blk errno(system.getcwd(out_buffer.ptr, out_buffer.len));1748 break :blk errno(system.getcwd(out_buffer.ptr, out_buffer.len));
1759 };1749 };
1760 switch (err) {1750 switch (err) {
1761 .SUCCESS => return mem.spanZ(std.meta.assumeSentinel(out_buffer.ptr, 0)),1751 .SUCCESS => return mem.sliceTo(std.meta.assumeSentinel(out_buffer.ptr, 0), 0),
1762 .FAULT => unreachable,1752 .FAULT => unreachable,
1763 .INVAL => unreachable,1753 .INVAL => unreachable,
1764 .NOENT => return error.CurrentWorkingDirectoryUnlinked,1754 .NOENT => return error.CurrentWorkingDirectoryUnlinked,
...@@ -1802,8 +1792,6 @@ pub fn symlink(target_path: []const u8, sym_link_path: []const u8) SymLinkError!...@@ -1802,8 +1792,6 @@ pub fn symlink(target_path: []const u8, sym_link_path: []const u8) SymLinkError!
1802 return symlinkZ(&target_path_c, &sym_link_path_c);1792 return symlinkZ(&target_path_c, &sym_link_path_c);
1803}1793}
18041794
1805pub const symlinkC = @compileError("deprecated: renamed to symlinkZ");
1806
1807/// This is the same as `symlink` except the parameters are null-terminated pointers.1795/// This is the same as `symlink` except the parameters are null-terminated pointers.
1808/// See also `symlink`.1796/// See also `symlink`.
1809pub fn symlinkZ(target_path: [*:0]const u8, sym_link_path: [*:0]const u8) SymLinkError!void {1797pub fn symlinkZ(target_path: [*:0]const u8, sym_link_path: [*:0]const u8) SymLinkError!void {
...@@ -1848,8 +1836,6 @@ pub fn symlinkat(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const...@@ -1848,8 +1836,6 @@ pub fn symlinkat(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const
1848 return symlinkatZ(&target_path_c, newdirfd, &sym_link_path_c);1836 return symlinkatZ(&target_path_c, newdirfd, &sym_link_path_c);
1849}1837}
18501838
1851pub const symlinkatC = @compileError("deprecated: renamed to symlinkatZ");
1852
1853/// WASI-only. The same as `symlinkat` but targeting WASI.1839/// WASI-only. The same as `symlinkat` but targeting WASI.
1854/// See also `symlinkat`.1840/// See also `symlinkat`.
1855pub fn symlinkatWasi(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkError!void {1841pub fn symlinkatWasi(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkError!void {
...@@ -2023,8 +2009,6 @@ pub fn unlink(file_path: []const u8) UnlinkError!void {...@@ -2023,8 +2009,6 @@ pub fn unlink(file_path: []const u8) UnlinkError!void {
2023 }2009 }
2024}2010}
20252011
2026pub const unlinkC = @compileError("deprecated: renamed to unlinkZ");
2027
2028/// Same as `unlink` except the parameter is a null terminated UTF8-encoded string.2012/// Same as `unlink` except the parameter is a null terminated UTF8-encoded string.
2029pub fn unlinkZ(file_path: [*:0]const u8) UnlinkError!void {2013pub fn unlinkZ(file_path: [*:0]const u8) UnlinkError!void {
2030 if (builtin.os.tag == .windows) {2014 if (builtin.os.tag == .windows) {
...@@ -2074,8 +2058,6 @@ pub fn unlinkat(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatError!vo...@@ -2074,8 +2058,6 @@ pub fn unlinkat(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatError!vo
2074 }2058 }
2075}2059}
20762060
2077pub const unlinkatC = @compileError("deprecated: renamed to unlinkatZ");
2078
2079/// WASI-only. Same as `unlinkat` but targeting WASI.2061/// WASI-only. Same as `unlinkat` but targeting WASI.
2080/// See also `unlinkat`.2062/// See also `unlinkat`.
2081pub fn unlinkatWasi(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatError!void {2063pub fn unlinkatWasi(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatError!void {
...@@ -2183,8 +2165,6 @@ pub fn rename(old_path: []const u8, new_path: []const u8) RenameError!void {...@@ -2183,8 +2165,6 @@ pub fn rename(old_path: []const u8, new_path: []const u8) RenameError!void {
2183 }2165 }
2184}2166}
21852167
2186pub const renameC = @compileError("deprecated: renamed to renameZ");
2187
2188/// Same as `rename` except the parameters are null-terminated byte arrays.2168/// Same as `rename` except the parameters are null-terminated byte arrays.
2189pub fn renameZ(old_path: [*:0]const u8, new_path: [*:0]const u8) RenameError!void {2169pub fn renameZ(old_path: [*:0]const u8, new_path: [*:0]const u8) RenameError!void {
2190 if (builtin.os.tag == .windows) {2170 if (builtin.os.tag == .windows) {
...@@ -2378,8 +2358,6 @@ pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!v...@@ -2378,8 +2358,6 @@ pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!v
2378 }2358 }
2379}2359}
23802360
2381pub const mkdiratC = @compileError("deprecated: renamed to mkdiratZ");
2382
2383pub fn mkdiratWasi(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!void {2361pub fn mkdiratWasi(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!void {
2384 _ = mode;2362 _ = mode;
2385 switch (wasi.path_create_directory(dir_fd, sub_dir_path.ptr, sub_dir_path.len)) {2363 switch (wasi.path_create_directory(dir_fd, sub_dir_path.ptr, sub_dir_path.len)) {
...@@ -2548,8 +2526,6 @@ pub fn rmdir(dir_path: []const u8) DeleteDirError!void {...@@ -2548,8 +2526,6 @@ pub fn rmdir(dir_path: []const u8) DeleteDirError!void {
2548 }2526 }
2549}2527}
25502528
2551pub const rmdirC = @compileError("deprecated: renamed to rmdirZ");
2552
2553/// Same as `rmdir` except the parameter is null-terminated.2529/// Same as `rmdir` except the parameter is null-terminated.
2554pub fn rmdirZ(dir_path: [*:0]const u8) DeleteDirError!void {2530pub fn rmdirZ(dir_path: [*:0]const u8) DeleteDirError!void {
2555 if (builtin.os.tag == .windows) {2531 if (builtin.os.tag == .windows) {
...@@ -2613,8 +2589,6 @@ pub fn chdir(dir_path: []const u8) ChangeCurDirError!void {...@@ -2613,8 +2589,6 @@ pub fn chdir(dir_path: []const u8) ChangeCurDirError!void {
2613 }2589 }
2614}2590}
26152591
2616pub const chdirC = @compileError("deprecated: renamed to chdirZ");
2617
2618/// Same as `chdir` except the parameter is null-terminated.2592/// Same as `chdir` except the parameter is null-terminated.
2619pub fn chdirZ(dir_path: [*:0]const u8) ChangeCurDirError!void {2593pub fn chdirZ(dir_path: [*:0]const u8) ChangeCurDirError!void {
2620 if (builtin.os.tag == .windows) {2594 if (builtin.os.tag == .windows) {
...@@ -2697,8 +2671,6 @@ pub fn readlink(file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 {...@@ -2697,8 +2671,6 @@ pub fn readlink(file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 {
2697 }2671 }
2698}2672}
26992673
2700pub const readlinkC = @compileError("deprecated: renamed to readlinkZ");
2701
2702/// Windows-only. Same as `readlink` except `file_path` is WTF16 encoded.2674/// Windows-only. Same as `readlink` except `file_path` is WTF16 encoded.
2703/// See also `readlinkZ`.2675/// See also `readlinkZ`.
2704pub fn readlinkW(file_path: []const u16, out_buffer: []u8) ReadLinkError![]u8 {2676pub fn readlinkW(file_path: []const u16, out_buffer: []u8) ReadLinkError![]u8 {
...@@ -2742,8 +2714,6 @@ pub fn readlinkat(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) ReadLink...@@ -2742,8 +2714,6 @@ pub fn readlinkat(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) ReadLink
2742 return readlinkatZ(dirfd, &file_path_c, out_buffer);2714 return readlinkatZ(dirfd, &file_path_c, out_buffer);
2743}2715}
27442716
2745pub const readlinkatC = @compileError("deprecated: renamed to readlinkatZ");
2746
2747/// WASI-only. Same as `readlinkat` but targets WASI.2717/// WASI-only. Same as `readlinkat` but targets WASI.
2748/// See also `readlinkat`.2718/// See also `readlinkat`.
2749pub fn readlinkatWasi(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 {2719pub fn readlinkatWasi(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 {
...@@ -3737,8 +3707,6 @@ pub fn fstatat(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat...@@ -3737,8 +3707,6 @@ pub fn fstatat(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat
3737 }3707 }
3738}3708}
37393709
3740pub const fstatatC = @compileError("deprecated: renamed to fstatatZ");
3741
3742/// WASI-only. Same as `fstatat` but targeting WASI.3710/// WASI-only. Same as `fstatat` but targeting WASI.
3743/// See also `fstatat`.3711/// See also `fstatat`.
3744pub fn fstatatWasi(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat {3712pub fn fstatatWasi(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat {
...@@ -3883,8 +3851,6 @@ pub fn inotify_add_watch(inotify_fd: i32, pathname: []const u8, mask: u32) INoti...@@ -3883,8 +3851,6 @@ pub fn inotify_add_watch(inotify_fd: i32, pathname: []const u8, mask: u32) INoti
3883 return inotify_add_watchZ(inotify_fd, &pathname_c, mask);3851 return inotify_add_watchZ(inotify_fd, &pathname_c, mask);
3884}3852}
38853853
3886pub const inotify_add_watchC = @compileError("deprecated: renamed to inotify_add_watchZ");
3887
3888/// Same as `inotify_add_watch` except pathname is null-terminated.3854/// Same as `inotify_add_watch` except pathname is null-terminated.
3889pub fn inotify_add_watchZ(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) INotifyAddWatchError!i32 {3855pub fn inotify_add_watchZ(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) INotifyAddWatchError!i32 {
3890 const rc = system.inotify_add_watch(inotify_fd, pathname, mask);3856 const rc = system.inotify_add_watch(inotify_fd, pathname, mask);
...@@ -4053,8 +4019,6 @@ pub fn access(path: []const u8, mode: u32) AccessError!void {...@@ -4053,8 +4019,6 @@ pub fn access(path: []const u8, mode: u32) AccessError!void {
4053 return accessZ(&path_c, mode);4019 return accessZ(&path_c, mode);
4054}4020}
40554021
4056pub const accessC = @compileError("Deprecated in favor of `accessZ`");
4057
4058/// Same as `access` except `path` is null-terminated.4022/// Same as `access` except `path` is null-terminated.
4059pub fn accessZ(path: [*:0]const u8, mode: u32) AccessError!void {4023pub fn accessZ(path: [*:0]const u8, mode: u32) AccessError!void {
4060 if (builtin.os.tag == .windows) {4024 if (builtin.os.tag == .windows) {
...@@ -4143,7 +4107,7 @@ pub fn faccessatW(dirfd: fd_t, sub_path_w: [*:0]const u16, mode: u32, flags: u32...@@ -4143,7 +4107,7 @@ pub fn faccessatW(dirfd: fd_t, sub_path_w: [*:0]const u16, mode: u32, flags: u32
4143 return;4107 return;
4144 }4108 }
41454109
4146 const path_len_bytes = math.cast(u16, mem.lenZ(sub_path_w) * 2) catch |err| switch (err) {4110 const path_len_bytes = math.cast(u16, mem.sliceTo(sub_path_w, 0).len * 2) catch |err| switch (err) {
4147 error.Overflow => return error.NameTooLong,4111 error.Overflow => return error.NameTooLong,
4148 };4112 };
4149 var nt_name = windows.UNICODE_STRING{4113 var nt_name = windows.UNICODE_STRING{
...@@ -4273,8 +4237,6 @@ pub fn sysctl(...@@ -4273,8 +4237,6 @@ pub fn sysctl(
4273 }4237 }
4274}4238}
42754239
4276pub const sysctlbynameC = @compileError("deprecated: renamed to sysctlbynameZ");
4277
4278pub fn sysctlbynameZ(4240pub fn sysctlbynameZ(
4279 name: [*:0]const u8,4241 name: [*:0]const u8,
4280 oldp: ?*c_void,4242 oldp: ?*c_void,
...@@ -4651,8 +4613,6 @@ pub fn realpath(pathname: []const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathE...@@ -4651,8 +4613,6 @@ pub fn realpath(pathname: []const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathE
4651 return realpathZ(&pathname_c, out_buffer);4613 return realpathZ(&pathname_c, out_buffer);
4652}4614}
46534615
4654pub const realpathC = @compileError("deprecated: renamed realpathZ");
4655
4656/// Same as `realpath` except `pathname` is null-terminated.4616/// Same as `realpath` except `pathname` is null-terminated.
4657pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {4617pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
4658 if (builtin.os.tag == .windows) {4618 if (builtin.os.tag == .windows) {
...@@ -4684,7 +4644,7 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP...@@ -4684,7 +4644,7 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP
4684 .IO => return error.InputOutput,4644 .IO => return error.InputOutput,
4685 else => |err| return unexpectedErrno(err),4645 else => |err| return unexpectedErrno(err),
4686 };4646 };
4687 return mem.spanZ(result_path);4647 return mem.sliceTo(result_path, 0);
4688}4648}
46894649
4690/// Same as `realpath` except `pathname` is UTF16LE-encoded.4650/// Same as `realpath` except `pathname` is UTF16LE-encoded.
...@@ -4997,7 +4957,7 @@ pub const UnexpectedError = error{...@@ -4997,7 +4957,7 @@ pub const UnexpectedError = error{
4997/// and you get an unexpected error.4957/// and you get an unexpected error.
4998pub fn unexpectedErrno(err: E) UnexpectedError {4958pub fn unexpectedErrno(err: E) UnexpectedError {
4999 if (unexpected_error_tracing) {4959 if (unexpected_error_tracing) {
5000 std.debug.warn("unexpected errno: {d}\n", .{@enumToInt(err)});4960 std.debug.print("unexpected errno: {d}\n", .{@enumToInt(err)});
5001 std.debug.dumpCurrentStackTrace(null);4961 std.debug.dumpCurrentStackTrace(null);
5002 }4962 }
5003 return error.Unexpected;4963 return error.Unexpected;
...@@ -5092,7 +5052,7 @@ pub const GetHostNameError = error{PermissionDenied} || UnexpectedError;...@@ -5092,7 +5052,7 @@ pub const GetHostNameError = error{PermissionDenied} || UnexpectedError;
5092pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {5052pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
5093 if (builtin.link_libc) {5053 if (builtin.link_libc) {
5094 switch (errno(system.gethostname(name_buffer, name_buffer.len))) {5054 switch (errno(system.gethostname(name_buffer, name_buffer.len))) {
5095 .SUCCESS => return mem.spanZ(std.meta.assumeSentinel(name_buffer, 0)),5055 .SUCCESS => return mem.sliceTo(std.meta.assumeSentinel(name_buffer, 0), 0),
5096 .FAULT => unreachable,5056 .FAULT => unreachable,
5097 .NAMETOOLONG => unreachable, // HOST_NAME_MAX prevents this5057 .NAMETOOLONG => unreachable, // HOST_NAME_MAX prevents this
5098 .PERM => return error.PermissionDenied,5058 .PERM => return error.PermissionDenied,
...@@ -5101,7 +5061,7 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {...@@ -5101,7 +5061,7 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
5101 }5061 }
5102 if (builtin.os.tag == .linux) {5062 if (builtin.os.tag == .linux) {
5103 const uts = uname();5063 const uts = uname();
5104 const hostname = mem.spanZ(std.meta.assumeSentinel(&uts.nodename, 0));5064 const hostname = mem.sliceTo(std.meta.assumeSentinel(&uts.nodename, 0), 0);
5105 mem.copy(u8, name_buffer, hostname);5065 mem.copy(u8, name_buffer, hostname);
5106 return name_buffer[0..hostname.len];5066 return name_buffer[0..hostname.len];
5107 }5067 }
...@@ -6130,8 +6090,6 @@ pub const MemFdCreateError = error{...@@ -6130,8 +6090,6 @@ pub const MemFdCreateError = error{
6130 SystemOutdated,6090 SystemOutdated,
6131} || UnexpectedError;6091} || UnexpectedError;
61326092
6133pub const memfd_createC = @compileError("deprecated: renamed to memfd_createZ");
6134
6135pub fn memfd_createZ(name: [*:0]const u8, flags: u32) MemFdCreateError!fd_t {6093pub fn memfd_createZ(name: [*:0]const u8, flags: u32) MemFdCreateError!fd_t {
6136 // memfd_create is available only in glibc versions starting with 2.27.6094 // memfd_create is available only in glibc versions starting with 2.27.
6137 const use_c = std.c.versionCheck(.{ .major = 2, .minor = 27, .patch = 0 }).ok;6095 const use_c = std.c.versionCheck(.{ .major = 2, .minor = 27, .patch = 0 }).ok;
lib/std/os/linux/vdso.zig+2-2
...@@ -69,7 +69,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {...@@ -69,7 +69,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
69 if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue;69 if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue;
70 if (0 == syms[i].st_shndx) continue;70 if (0 == syms[i].st_shndx) continue;
71 const sym_name = std.meta.assumeSentinel(strings + syms[i].st_name, 0);71 const sym_name = std.meta.assumeSentinel(strings + syms[i].st_name, 0);
72 if (!mem.eql(u8, name, mem.spanZ(sym_name))) continue;72 if (!mem.eql(u8, name, mem.sliceTo(sym_name, 0))) continue;
73 if (maybe_versym) |versym| {73 if (maybe_versym) |versym| {
74 if (!checkver(maybe_verdef.?, versym[i], vername, strings))74 if (!checkver(maybe_verdef.?, versym[i], vername, strings))
75 continue;75 continue;
...@@ -92,5 +92,5 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [...@@ -92,5 +92,5 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [
92 }92 }
93 const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux);93 const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux);
94 const vda_name = std.meta.assumeSentinel(strings + aux.vda_name, 0);94 const vda_name = std.meta.assumeSentinel(strings + aux.vda_name, 0);
95 return mem.eql(u8, vername, mem.spanZ(vda_name));95 return mem.eql(u8, vername, mem.sliceTo(vda_name, 0));
96}96}
lib/std/os/windows.zig+4-4
...@@ -813,7 +813,7 @@ pub fn ReadLink(dir: ?HANDLE, sub_path_w: []const u16, out_buffer: []u8) ReadLin...@@ -813,7 +813,7 @@ pub fn ReadLink(dir: ?HANDLE, sub_path_w: []const u16, out_buffer: []u8) ReadLin
813 return parseReadlinkPath(path_buf[offset .. offset + len], false, out_buffer);813 return parseReadlinkPath(path_buf[offset .. offset + len], false, out_buffer);
814 },814 },
815 else => |value| {815 else => |value| {
816 std.debug.warn("unsupported symlink type: {}", .{value});816 std.debug.print("unsupported symlink type: {}", .{value});
817 return error.UnsupportedReparsePointType;817 return error.UnsupportedReparsePointType;
818 },818 },
819 }819 }
...@@ -1862,7 +1862,7 @@ pub fn normalizePath(comptime T: type, path: []T) RemoveDotDirsError!usize {...@@ -1862,7 +1862,7 @@ pub fn normalizePath(comptime T: type, path: []T) RemoveDotDirsError!usize {
1862/// Same as `sliceToPrefixedFileW` but accepts a pointer1862/// Same as `sliceToPrefixedFileW` but accepts a pointer
1863/// to a null-terminated path.1863/// to a null-terminated path.
1864pub fn cStrToPrefixedFileW(s: [*:0]const u8) !PathSpace {1864pub fn cStrToPrefixedFileW(s: [*:0]const u8) !PathSpace {
1865 return sliceToPrefixedFileW(mem.spanZ(s));1865 return sliceToPrefixedFileW(mem.sliceTo(s, 0));
1866}1866}
18671867
1868/// Converts the path `s` to WTF16, null-terminated. If the path is absolute,1868/// Converts the path `s` to WTF16, null-terminated. If the path is absolute,
...@@ -1995,7 +1995,7 @@ pub fn unexpectedError(err: Win32Error) std.os.UnexpectedError {...@@ -1995,7 +1995,7 @@ pub fn unexpectedError(err: Win32Error) std.os.UnexpectedError {
1995 null,1995 null,
1996 );1996 );
1997 _ = std.unicode.utf16leToUtf8(&buf_utf8, buf_wstr[0..len]) catch unreachable;1997 _ = std.unicode.utf16leToUtf8(&buf_utf8, buf_wstr[0..len]) catch unreachable;
1998 std.debug.warn("error.Unexpected: GetLastError({}): {s}\n", .{ @enumToInt(err), buf_utf8[0..len] });1998 std.debug.print("error.Unexpected: GetLastError({}): {s}\n", .{ @enumToInt(err), buf_utf8[0..len] });
1999 std.debug.dumpCurrentStackTrace(null);1999 std.debug.dumpCurrentStackTrace(null);
2000 }2000 }
2001 return error.Unexpected;2001 return error.Unexpected;
...@@ -2009,7 +2009,7 @@ pub fn unexpectedWSAError(err: ws2_32.WinsockError) std.os.UnexpectedError {...@@ -2009,7 +2009,7 @@ pub fn unexpectedWSAError(err: ws2_32.WinsockError) std.os.UnexpectedError {
2009/// and you get an unexpected status.2009/// and you get an unexpected status.
2010pub fn unexpectedStatus(status: NTSTATUS) std.os.UnexpectedError {2010pub fn unexpectedStatus(status: NTSTATUS) std.os.UnexpectedError {
2011 if (std.os.unexpected_error_tracing) {2011 if (std.os.unexpected_error_tracing) {
2012 std.debug.warn("error.Unexpected NTSTATUS=0x{x}\n", .{@enumToInt(status)});2012 std.debug.print("error.Unexpected NTSTATUS=0x{x}\n", .{@enumToInt(status)});
2013 std.debug.dumpCurrentStackTrace(null);2013 std.debug.dumpCurrentStackTrace(null);
2014 }2014 }
2015 return error.Unexpected;2015 return error.Unexpected;
lib/std/pdb.zig+2-3
...@@ -3,7 +3,6 @@ const io = std.io;...@@ -3,7 +3,6 @@ const io = std.io;
3const math = std.math;3const math = std.math;
4const mem = std.mem;4const mem = std.mem;
5const os = std.os;5const os = std.os;
6const warn = std.debug.warn;
7const coff = std.coff;6const coff = std.coff;
8const fs = std.fs;7const fs = std.fs;
9const File = std.fs.File;8const File = std.fs.File;
...@@ -656,7 +655,7 @@ pub const Pdb = struct {...@@ -656,7 +655,7 @@ pub const Pdb = struct {
656 const name_index = try reader.readIntLittle(u32);655 const name_index = try reader.readIntLittle(u32);
657 if (name_offset > name_bytes.len)656 if (name_offset > name_bytes.len)
658 return error.InvalidDebugInfo;657 return error.InvalidDebugInfo;
659 const name = mem.spanZ(std.meta.assumeSentinel(name_bytes.ptr + name_offset, 0));658 const name = mem.sliceTo(std.meta.assumeSentinel(name_bytes.ptr + name_offset, 0), 0);
660 if (mem.eql(u8, name, "/names")) {659 if (mem.eql(u8, name, "/names")) {
661 break :str_tab_index name_index;660 break :str_tab_index name_index;
662 }661 }
...@@ -681,7 +680,7 @@ pub const Pdb = struct {...@@ -681,7 +680,7 @@ pub const Pdb = struct {
681 .S_LPROC32, .S_GPROC32 => {680 .S_LPROC32, .S_GPROC32 => {
682 const proc_sym = @ptrCast(*ProcSym, &module.symbols[symbol_i + @sizeOf(RecordPrefix)]);681 const proc_sym = @ptrCast(*ProcSym, &module.symbols[symbol_i + @sizeOf(RecordPrefix)]);
683 if (address >= proc_sym.CodeOffset and address < proc_sym.CodeOffset + proc_sym.CodeSize) {682 if (address >= proc_sym.CodeOffset and address < proc_sym.CodeOffset + proc_sym.CodeSize) {
684 return mem.spanZ(@ptrCast([*:0]u8, proc_sym) + @sizeOf(ProcSym));683 return mem.sliceTo(@ptrCast([*:0]u8, proc_sym) + @sizeOf(ProcSym), 0);
685 }684 }
686 },685 },
687 else => {},686 else => {},
lib/std/priority_dequeue.zig+10-11
...@@ -1,7 +1,6 @@...@@ -1,7 +1,6 @@
1const std = @import("std.zig");1const std = @import("std.zig");
2const Allocator = std.mem.Allocator;2const Allocator = std.mem.Allocator;
3const assert = std.debug.assert;3const assert = std.debug.assert;
4const warn = std.debug.warn;
5const Order = std.math.Order;4const Order = std.math.Order;
6const testing = std.testing;5const testing = std.testing;
7const expect = testing.expect;6const expect = testing.expect;
...@@ -355,8 +354,7 @@ pub fn PriorityDequeue(comptime T: type, comptime compareFn: fn (T, T) Order) ty...@@ -355,8 +354,7 @@ pub fn PriorityDequeue(comptime T: type, comptime compareFn: fn (T, T) Order) ty
355 return queue;354 return queue;
356 }355 }
357356
358 /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.357 pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`");
359 pub const ensureCapacity = ensureTotalCapacity;
360358
361 /// Ensure that the dequeue can fit at least `new_capacity` items.359 /// Ensure that the dequeue can fit at least `new_capacity` items.
362 pub fn ensureTotalCapacity(self: *Self, new_capacity: usize) !void {360 pub fn ensureTotalCapacity(self: *Self, new_capacity: usize) !void {
...@@ -421,19 +419,20 @@ pub fn PriorityDequeue(comptime T: type, comptime compareFn: fn (T, T) Order) ty...@@ -421,19 +419,20 @@ pub fn PriorityDequeue(comptime T: type, comptime compareFn: fn (T, T) Order) ty
421 }419 }
422420
423 fn dump(self: *Self) void {421 fn dump(self: *Self) void {
424 warn("{{ ", .{});422 const print = std.debug.print;
425 warn("items: ", .{});423 print("{{ ", .{});
424 print("items: ", .{});
426 for (self.items) |e, i| {425 for (self.items) |e, i| {
427 if (i >= self.len) break;426 if (i >= self.len) break;
428 warn("{}, ", .{e});427 print("{}, ", .{e});
429 }428 }
430 warn("array: ", .{});429 print("array: ", .{});
431 for (self.items) |e| {430 for (self.items) |e| {
432 warn("{}, ", .{e});431 print("{}, ", .{e});
433 }432 }
434 warn("len: {} ", .{self.len});433 print("len: {} ", .{self.len});
435 warn("capacity: {}", .{self.capacity()});434 print("capacity: {}", .{self.capacity()});
436 warn(" }}\n", .{});435 print(" }}\n", .{});
437 }436 }
438437
439 fn parentIndex(index: usize) usize {438 fn parentIndex(index: usize) usize {
lib/std/priority_queue.zig+10-11
...@@ -1,7 +1,6 @@...@@ -1,7 +1,6 @@
1const std = @import("std.zig");1const std = @import("std.zig");
2const Allocator = std.mem.Allocator;2const Allocator = std.mem.Allocator;
3const assert = std.debug.assert;3const assert = std.debug.assert;
4const warn = std.debug.warn;
5const Order = std.math.Order;4const Order = std.math.Order;
6const testing = std.testing;5const testing = std.testing;
7const expect = testing.expect;6const expect = testing.expect;
...@@ -171,8 +170,7 @@ pub fn PriorityQueue(comptime T: type, comptime compareFn: fn (a: T, b: T) Order...@@ -171,8 +170,7 @@ pub fn PriorityQueue(comptime T: type, comptime compareFn: fn (a: T, b: T) Order
171 return queue;170 return queue;
172 }171 }
173172
174 /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.173 pub const ensureCapacity = @compileError("deprecated; use ensureUnusedCapacity or ensureTotalCapacity");
175 pub const ensureCapacity = ensureTotalCapacity;
176174
177 /// Ensure that the queue can fit at least `new_capacity` items.175 /// Ensure that the queue can fit at least `new_capacity` items.
178 pub fn ensureTotalCapacity(self: *Self, new_capacity: usize) !void {176 pub fn ensureTotalCapacity(self: *Self, new_capacity: usize) !void {
...@@ -242,19 +240,20 @@ pub fn PriorityQueue(comptime T: type, comptime compareFn: fn (a: T, b: T) Order...@@ -242,19 +240,20 @@ pub fn PriorityQueue(comptime T: type, comptime compareFn: fn (a: T, b: T) Order
242 }240 }
243241
244 fn dump(self: *Self) void {242 fn dump(self: *Self) void {
245 warn("{{ ", .{});243 const print = std.debug.print;
246 warn("items: ", .{});244 print("{{ ", .{});
245 print("items: ", .{});
247 for (self.items) |e, i| {246 for (self.items) |e, i| {
248 if (i >= self.len) break;247 if (i >= self.len) break;
249 warn("{}, ", .{e});248 print("{}, ", .{e});
250 }249 }
251 warn("array: ", .{});250 print("array: ", .{});
252 for (self.items) |e| {251 for (self.items) |e| {
253 warn("{}, ", .{e});252 print("{}, ", .{e});
254 }253 }
255 warn("len: {} ", .{self.len});254 print("len: {} ", .{self.len});
256 warn("capacity: {}", .{self.capacity()});255 print("capacity: {}", .{self.capacity()});
257 warn(" }}\n", .{});256 print(" }}\n", .{});
258 }257 }
259 };258 };
260}259}
lib/std/process.zig+6-6
...@@ -103,7 +103,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap {...@@ -103,7 +103,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap {
103 }103 }
104104
105 for (environ) |env| {105 for (environ) |env| {
106 const pair = mem.spanZ(env);106 const pair = mem.sliceTo(env, 0);
107 var parts = mem.split(u8, pair, "=");107 var parts = mem.split(u8, pair, "=");
108 const key = parts.next().?;108 const key = parts.next().?;
109 const value = parts.next().?;109 const value = parts.next().?;
...@@ -215,7 +215,7 @@ pub const ArgIteratorPosix = struct {...@@ -215,7 +215,7 @@ pub const ArgIteratorPosix = struct {
215215
216 const s = os.argv[self.index];216 const s = os.argv[self.index];
217 self.index += 1;217 self.index += 1;
218 return mem.spanZ(s);218 return mem.sliceTo(s, 0);
219 }219 }
220220
221 pub fn skip(self: *ArgIteratorPosix) bool {221 pub fn skip(self: *ArgIteratorPosix) bool {
...@@ -267,7 +267,7 @@ pub const ArgIteratorWasi = struct {...@@ -267,7 +267,7 @@ pub const ArgIteratorWasi = struct {
267 var result_args = try allocator.alloc([:0]u8, count);267 var result_args = try allocator.alloc([:0]u8, count);
268 var i: usize = 0;268 var i: usize = 0;
269 while (i < count) : (i += 1) {269 while (i < count) : (i += 1) {
270 result_args[i] = mem.spanZ(argv[i]);270 result_args[i] = mem.sliceTo(argv[i], 0);
271 }271 }
272272
273 return result_args;273 return result_args;
...@@ -768,7 +768,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]...@@ -768,7 +768,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]
768 _ = size;768 _ = size;
769 const name = info.dlpi_name orelse return;769 const name = info.dlpi_name orelse return;
770 if (name[0] == '/') {770 if (name[0] == '/') {
771 const item = try list.allocator.dupeZ(u8, mem.spanZ(name));771 const item = try list.allocator.dupeZ(u8, mem.sliceTo(name, 0));
772 errdefer list.allocator.free(item);772 errdefer list.allocator.free(item);
773 try list.append(item);773 try list.append(item);
774 }774 }
...@@ -789,7 +789,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]...@@ -789,7 +789,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]
789 var i: u32 = 0;789 var i: u32 = 0;
790 while (i < img_count) : (i += 1) {790 while (i < img_count) : (i += 1) {
791 const name = std.c._dyld_get_image_name(i);791 const name = std.c._dyld_get_image_name(i);
792 const item = try allocator.dupeZ(u8, mem.spanZ(name));792 const item = try allocator.dupeZ(u8, mem.sliceTo(name, 0));
793 errdefer allocator.free(item);793 errdefer allocator.free(item);
794 try paths.append(item);794 try paths.append(item);
795 }795 }
...@@ -807,7 +807,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]...@@ -807,7 +807,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]
807 }807 }
808808
809 var b = "/boot/system/runtime_loader";809 var b = "/boot/system/runtime_loader";
810 const item = try allocator.dupeZ(u8, mem.spanZ(b));810 const item = try allocator.dupeZ(u8, mem.sliceTo(b, 0));
811 errdefer allocator.free(item);811 errdefer allocator.free(item);
812 try paths.append(item);812 try paths.append(item);
813813
lib/std/rand.zig-4
...@@ -245,10 +245,6 @@ pub const Random = struct {...@@ -245,10 +245,6 @@ pub const Random = struct {
245 }245 }
246 }246 }
247247
248 pub const scalar = @compileError("deprecated; use boolean() or int() instead");
249
250 pub const range = @compileError("deprecated; use intRangeLessThan()");
251
252 /// Return a floating point value evenly distributed in the range [0, 1).248 /// Return a floating point value evenly distributed in the range [0, 1).
253 pub fn float(r: Random, comptime T: type) T {249 pub fn float(r: Random, comptime T: type) T {
254 // Generate a uniform value between [1, 2) and scale down to [0, 1).250 // Generate a uniform value between [1, 2) and scale down to [0, 1).
lib/std/special/build_runner.zig+17-18
...@@ -7,7 +7,6 @@ const Builder = std.build.Builder;...@@ -7,7 +7,6 @@ const Builder = std.build.Builder;
7const mem = std.mem;7const mem = std.mem;
8const process = std.process;8const process = std.process;
9const ArrayList = std.ArrayList;9const ArrayList = std.ArrayList;
10const warn = std.debug.warn;
11const File = std.fs.File;10const File = std.fs.File;
1211
13pub fn main() !void {12pub fn main() !void {
...@@ -25,19 +24,19 @@ pub fn main() !void {...@@ -25,19 +24,19 @@ pub fn main() !void {
25 var arg_idx: usize = 1;24 var arg_idx: usize = 1;
2625
27 const zig_exe = nextArg(args, &arg_idx) orelse {26 const zig_exe = nextArg(args, &arg_idx) orelse {
28 warn("Expected first argument to be path to zig compiler\n", .{});27 std.debug.print("Expected first argument to be path to zig compiler\n", .{});
29 return error.InvalidArgs;28 return error.InvalidArgs;
30 };29 };
31 const build_root = nextArg(args, &arg_idx) orelse {30 const build_root = nextArg(args, &arg_idx) orelse {
32 warn("Expected second argument to be build root directory path\n", .{});31 std.debug.print("Expected second argument to be build root directory path\n", .{});
33 return error.InvalidArgs;32 return error.InvalidArgs;
34 };33 };
35 const cache_root = nextArg(args, &arg_idx) orelse {34 const cache_root = nextArg(args, &arg_idx) orelse {
36 warn("Expected third argument to be cache root directory path\n", .{});35 std.debug.print("Expected third argument to be cache root directory path\n", .{});
37 return error.InvalidArgs;36 return error.InvalidArgs;
38 };37 };
39 const global_cache_root = nextArg(args, &arg_idx) orelse {38 const global_cache_root = nextArg(args, &arg_idx) orelse {
40 warn("Expected third argument to be global cache root directory path\n", .{});39 std.debug.print("Expected third argument to be global cache root directory path\n", .{});
41 return error.InvalidArgs;40 return error.InvalidArgs;
42 };41 };
4342
...@@ -68,7 +67,7 @@ pub fn main() !void {...@@ -68,7 +67,7 @@ pub fn main() !void {
68 if (mem.startsWith(u8, arg, "-D")) {67 if (mem.startsWith(u8, arg, "-D")) {
69 const option_contents = arg[2..];68 const option_contents = arg[2..];
70 if (option_contents.len == 0) {69 if (option_contents.len == 0) {
71 warn("Expected option name after '-D'\n\n", .{});70 std.debug.print("Expected option name after '-D'\n\n", .{});
72 return usageAndErr(builder, false, stderr_stream);71 return usageAndErr(builder, false, stderr_stream);
73 }72 }
74 if (mem.indexOfScalar(u8, option_contents, '=')) |name_end| {73 if (mem.indexOfScalar(u8, option_contents, '=')) |name_end| {
...@@ -87,59 +86,59 @@ pub fn main() !void {...@@ -87,59 +86,59 @@ pub fn main() !void {
87 return usage(builder, false, stdout_stream);86 return usage(builder, false, stdout_stream);
88 } else if (mem.eql(u8, arg, "-p") or mem.eql(u8, arg, "--prefix")) {87 } else if (mem.eql(u8, arg, "-p") or mem.eql(u8, arg, "--prefix")) {
89 install_prefix = nextArg(args, &arg_idx) orelse {88 install_prefix = nextArg(args, &arg_idx) orelse {
90 warn("Expected argument after {s}\n\n", .{arg});89 std.debug.print("Expected argument after {s}\n\n", .{arg});
91 return usageAndErr(builder, false, stderr_stream);90 return usageAndErr(builder, false, stderr_stream);
92 };91 };
93 } else if (mem.eql(u8, arg, "--prefix-lib-dir")) {92 } else if (mem.eql(u8, arg, "--prefix-lib-dir")) {
94 dir_list.lib_dir = nextArg(args, &arg_idx) orelse {93 dir_list.lib_dir = nextArg(args, &arg_idx) orelse {
95 warn("Expected argument after {s}\n\n", .{arg});94 std.debug.print("Expected argument after {s}\n\n", .{arg});
96 return usageAndErr(builder, false, stderr_stream);95 return usageAndErr(builder, false, stderr_stream);
97 };96 };
98 } else if (mem.eql(u8, arg, "--prefix-exe-dir")) {97 } else if (mem.eql(u8, arg, "--prefix-exe-dir")) {
99 dir_list.exe_dir = nextArg(args, &arg_idx) orelse {98 dir_list.exe_dir = nextArg(args, &arg_idx) orelse {
100 warn("Expected argument after {s}\n\n", .{arg});99 std.debug.print("Expected argument after {s}\n\n", .{arg});
101 return usageAndErr(builder, false, stderr_stream);100 return usageAndErr(builder, false, stderr_stream);
102 };101 };
103 } else if (mem.eql(u8, arg, "--prefix-include-dir")) {102 } else if (mem.eql(u8, arg, "--prefix-include-dir")) {
104 dir_list.include_dir = nextArg(args, &arg_idx) orelse {103 dir_list.include_dir = nextArg(args, &arg_idx) orelse {
105 warn("Expected argument after {s}\n\n", .{arg});104 std.debug.print("Expected argument after {s}\n\n", .{arg});
106 return usageAndErr(builder, false, stderr_stream);105 return usageAndErr(builder, false, stderr_stream);
107 };106 };
108 } else if (mem.eql(u8, arg, "--sysroot")) {107 } else if (mem.eql(u8, arg, "--sysroot")) {
109 const sysroot = nextArg(args, &arg_idx) orelse {108 const sysroot = nextArg(args, &arg_idx) orelse {
110 warn("Expected argument after --sysroot\n\n", .{});109 std.debug.print("Expected argument after --sysroot\n\n", .{});
111 return usageAndErr(builder, false, stderr_stream);110 return usageAndErr(builder, false, stderr_stream);
112 };111 };
113 builder.sysroot = sysroot;112 builder.sysroot = sysroot;
114 } else if (mem.eql(u8, arg, "--search-prefix")) {113 } else if (mem.eql(u8, arg, "--search-prefix")) {
115 const search_prefix = nextArg(args, &arg_idx) orelse {114 const search_prefix = nextArg(args, &arg_idx) orelse {
116 warn("Expected argument after --search-prefix\n\n", .{});115 std.debug.print("Expected argument after --search-prefix\n\n", .{});
117 return usageAndErr(builder, false, stderr_stream);116 return usageAndErr(builder, false, stderr_stream);
118 };117 };
119 builder.addSearchPrefix(search_prefix);118 builder.addSearchPrefix(search_prefix);
120 } else if (mem.eql(u8, arg, "--libc")) {119 } else if (mem.eql(u8, arg, "--libc")) {
121 const libc_file = nextArg(args, &arg_idx) orelse {120 const libc_file = nextArg(args, &arg_idx) orelse {
122 warn("Expected argument after --libc\n\n", .{});121 std.debug.print("Expected argument after --libc\n\n", .{});
123 return usageAndErr(builder, false, stderr_stream);122 return usageAndErr(builder, false, stderr_stream);
124 };123 };
125 builder.libc_file = libc_file;124 builder.libc_file = libc_file;
126 } else if (mem.eql(u8, arg, "--color")) {125 } else if (mem.eql(u8, arg, "--color")) {
127 const next_arg = nextArg(args, &arg_idx) orelse {126 const next_arg = nextArg(args, &arg_idx) orelse {
128 warn("expected [auto|on|off] after --color", .{});127 std.debug.print("expected [auto|on|off] after --color", .{});
129 return usageAndErr(builder, false, stderr_stream);128 return usageAndErr(builder, false, stderr_stream);
130 };129 };
131 builder.color = std.meta.stringToEnum(@TypeOf(builder.color), next_arg) orelse {130 builder.color = std.meta.stringToEnum(@TypeOf(builder.color), next_arg) orelse {
132 warn("expected [auto|on|off] after --color, found '{s}'", .{next_arg});131 std.debug.print("expected [auto|on|off] after --color, found '{s}'", .{next_arg});
133 return usageAndErr(builder, false, stderr_stream);132 return usageAndErr(builder, false, stderr_stream);
134 };133 };
135 } else if (mem.eql(u8, arg, "--zig-lib-dir")) {134 } else if (mem.eql(u8, arg, "--zig-lib-dir")) {
136 builder.override_lib_dir = nextArg(args, &arg_idx) orelse {135 builder.override_lib_dir = nextArg(args, &arg_idx) orelse {
137 warn("Expected argument after --zig-lib-dir\n\n", .{});136 std.debug.print("Expected argument after --zig-lib-dir\n\n", .{});
138 return usageAndErr(builder, false, stderr_stream);137 return usageAndErr(builder, false, stderr_stream);
139 };138 };
140 } else if (mem.eql(u8, arg, "--debug-log")) {139 } else if (mem.eql(u8, arg, "--debug-log")) {
141 const next_arg = nextArg(args, &arg_idx) orelse {140 const next_arg = nextArg(args, &arg_idx) orelse {
142 warn("Expected argument after {s}\n\n", .{arg});141 std.debug.print("Expected argument after {s}\n\n", .{arg});
143 return usageAndErr(builder, false, stderr_stream);142 return usageAndErr(builder, false, stderr_stream);
144 };143 };
145 try debug_log_scopes.append(next_arg);144 try debug_log_scopes.append(next_arg);
...@@ -165,7 +164,7 @@ pub fn main() !void {...@@ -165,7 +164,7 @@ pub fn main() !void {
165 builder.args = argsRest(args, arg_idx);164 builder.args = argsRest(args, arg_idx);
166 break;165 break;
167 } else {166 } else {
168 warn("Unrecognized argument: {s}\n\n", .{arg});167 std.debug.print("Unrecognized argument: {s}\n\n", .{arg});
169 return usageAndErr(builder, false, stderr_stream);168 return usageAndErr(builder, false, stderr_stream);
170 }169 }
171 } else {170 } else {
lib/std/special/c_stage1.zig+4-4
...@@ -59,7 +59,7 @@ test "strcpy" {...@@ -59,7 +59,7 @@ test "strcpy" {
5959
60 s1[0] = 0;60 s1[0] = 0;
61 _ = strcpy(&s1, "foobarbaz");61 _ = strcpy(&s1, "foobarbaz");
62 try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));62 try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.sliceTo(&s1, 0));
63}63}
6464
65fn strncpy(dest: [*:0]u8, src: [*:0]const u8, n: usize) callconv(.C) [*:0]u8 {65fn strncpy(dest: [*:0]u8, src: [*:0]const u8, n: usize) callconv(.C) [*:0]u8 {
...@@ -79,7 +79,7 @@ test "strncpy" {...@@ -79,7 +79,7 @@ test "strncpy" {
7979
80 s1[0] = 0;80 s1[0] = 0;
81 _ = strncpy(&s1, "foobarbaz", @sizeOf(@TypeOf(s1)));81 _ = strncpy(&s1, "foobarbaz", @sizeOf(@TypeOf(s1)));
82 try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));82 try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.sliceTo(&s1, 0));
83}83}
8484
85fn strcat(dest: [*:0]u8, src: [*:0]const u8) callconv(.C) [*:0]u8 {85fn strcat(dest: [*:0]u8, src: [*:0]const u8) callconv(.C) [*:0]u8 {
...@@ -102,7 +102,7 @@ test "strcat" {...@@ -102,7 +102,7 @@ test "strcat" {
102 _ = strcat(&s1, "foo");102 _ = strcat(&s1, "foo");
103 _ = strcat(&s1, "bar");103 _ = strcat(&s1, "bar");
104 _ = strcat(&s1, "baz");104 _ = strcat(&s1, "baz");
105 try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));105 try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.sliceTo(&s1, 0));
106}106}
107107
108fn strncat(dest: [*:0]u8, src: [*:0]const u8, avail: usize) callconv(.C) [*:0]u8 {108fn strncat(dest: [*:0]u8, src: [*:0]const u8, avail: usize) callconv(.C) [*:0]u8 {
...@@ -125,7 +125,7 @@ test "strncat" {...@@ -125,7 +125,7 @@ test "strncat" {
125 _ = strncat(&s1, "foo1111", 3);125 _ = strncat(&s1, "foo1111", 3);
126 _ = strncat(&s1, "bar1111", 3);126 _ = strncat(&s1, "bar1111", 3);
127 _ = strncat(&s1, "baz1111", 3);127 _ = strncat(&s1, "baz1111", 3);
128 try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));128 try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.sliceTo(&s1, 0));
129}129}
130130
131fn strcmp(s1: [*:0]const u8, s2: [*:0]const u8) callconv(.C) c_int {131fn strcmp(s1: [*:0]const u8, s2: [*:0]const u8) callconv(.C) c_int {
lib/std/special/compiler_rt/fixdfdi_test.zig-3
...@@ -2,16 +2,13 @@ const __fixdfdi = @import("fixdfdi.zig").__fixdfdi;...@@ -2,16 +2,13 @@ const __fixdfdi = @import("fixdfdi.zig").__fixdfdi;
2const std = @import("std");2const std = @import("std");
3const math = std.math;3const math = std.math;
4const testing = std.testing;4const testing = std.testing;
5const warn = std.debug.warn;
65
7fn test__fixdfdi(a: f64, expected: i64) !void {6fn test__fixdfdi(a: f64, expected: i64) !void {
8 const x = __fixdfdi(a);7 const x = __fixdfdi(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u64, expected)});
10 try testing.expect(x == expected);8 try testing.expect(x == expected);
11}9}
1210
13test "fixdfdi" {11test "fixdfdi" {
14 //warn("\n", .{});
15 try test__fixdfdi(-math.f64_max, math.minInt(i64));12 try test__fixdfdi(-math.f64_max, math.minInt(i64));
1613
17 try test__fixdfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64));14 try test__fixdfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64));
lib/std/special/compiler_rt/fixdfsi_test.zig-3
...@@ -2,16 +2,13 @@ const __fixdfsi = @import("fixdfsi.zig").__fixdfsi;...@@ -2,16 +2,13 @@ const __fixdfsi = @import("fixdfsi.zig").__fixdfsi;
2const std = @import("std");2const std = @import("std");
3const math = std.math;3const math = std.math;
4const testing = std.testing;4const testing = std.testing;
5const warn = std.debug.warn;
65
7fn test__fixdfsi(a: f64, expected: i32) !void {6fn test__fixdfsi(a: f64, expected: i32) !void {
8 const x = __fixdfsi(a);7 const x = __fixdfsi(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u32, expected)});
10 try testing.expect(x == expected);8 try testing.expect(x == expected);
11}9}
1210
13test "fixdfsi" {11test "fixdfsi" {
14 //warn("\n", .{});
15 try test__fixdfsi(-math.f64_max, math.minInt(i32));12 try test__fixdfsi(-math.f64_max, math.minInt(i32));
1613
17 try test__fixdfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32));14 try test__fixdfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32));
lib/std/special/compiler_rt/fixdfti_test.zig-3
...@@ -2,16 +2,13 @@ const __fixdfti = @import("fixdfti.zig").__fixdfti;...@@ -2,16 +2,13 @@ const __fixdfti = @import("fixdfti.zig").__fixdfti;
2const std = @import("std");2const std = @import("std");
3const math = std.math;3const math = std.math;
4const testing = std.testing;4const testing = std.testing;
5const warn = std.debug.warn;
65
7fn test__fixdfti(a: f64, expected: i128) !void {6fn test__fixdfti(a: f64, expected: i128) !void {
8 const x = __fixdfti(a);7 const x = __fixdfti(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u128, expected)});
10 try testing.expect(x == expected);8 try testing.expect(x == expected);
11}9}
1210
13test "fixdfti" {11test "fixdfti" {
14 //warn("\n", .{});
15 try test__fixdfti(-math.f64_max, math.minInt(i128));12 try test__fixdfti(-math.f64_max, math.minInt(i128));
1613
17 try test__fixdfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128));14 try test__fixdfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128));
lib/std/special/compiler_rt/fixint_test.zig-2
...@@ -2,13 +2,11 @@ const is_test = @import("builtin").is_test;...@@ -2,13 +2,11 @@ const is_test = @import("builtin").is_test;
2const std = @import("std");2const std = @import("std");
3const math = std.math;3const math = std.math;
4const testing = std.testing;4const testing = std.testing;
5const warn = std.debug.warn;
65
7const fixint = @import("fixint.zig").fixint;6const fixint = @import("fixint.zig").fixint;
87
9fn test__fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t, expected: fixint_t) !void {8fn test__fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t, expected: fixint_t) !void {
10 const x = fixint(fp_t, fixint_t, a);9 const x = fixint(fp_t, fixint_t, a);
11 //warn("a={} x={}:{x} expected={}:{x})\n", .{a, x, x, expected, expected});
12 try testing.expect(x == expected);10 try testing.expect(x == expected);
13}11}
1412
lib/std/special/compiler_rt/fixsfdi_test.zig-3
...@@ -2,16 +2,13 @@ const __fixsfdi = @import("fixsfdi.zig").__fixsfdi;...@@ -2,16 +2,13 @@ const __fixsfdi = @import("fixsfdi.zig").__fixsfdi;
2const std = @import("std");2const std = @import("std");
3const math = std.math;3const math = std.math;
4const testing = std.testing;4const testing = std.testing;
5const warn = std.debug.warn;
65
7fn test__fixsfdi(a: f32, expected: i64) !void {6fn test__fixsfdi(a: f32, expected: i64) !void {
8 const x = __fixsfdi(a);7 const x = __fixsfdi(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", .{a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u64, expected)});
10 try testing.expect(x == expected);8 try testing.expect(x == expected);
11}9}
1210
13test "fixsfdi" {11test "fixsfdi" {
14 //warn("\n", .{});
15 try test__fixsfdi(-math.f32_max, math.minInt(i64));12 try test__fixsfdi(-math.f32_max, math.minInt(i64));
1613
17 try test__fixsfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64));14 try test__fixsfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64));
lib/std/special/compiler_rt/fixsfsi_test.zig-3
...@@ -2,16 +2,13 @@ const __fixsfsi = @import("fixsfsi.zig").__fixsfsi;...@@ -2,16 +2,13 @@ const __fixsfsi = @import("fixsfsi.zig").__fixsfsi;
2const std = @import("std");2const std = @import("std");
3const math = std.math;3const math = std.math;
4const testing = std.testing;4const testing = std.testing;
5const warn = std.debug.warn;
65
7fn test__fixsfsi(a: f32, expected: i32) !void {6fn test__fixsfsi(a: f32, expected: i32) !void {
8 const x = __fixsfsi(a);7 const x = __fixsfsi(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", .{a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u32, expected)});
10 try testing.expect(x == expected);8 try testing.expect(x == expected);
11}9}
1210
13test "fixsfsi" {11test "fixsfsi" {
14 //warn("\n", .{});
15 try test__fixsfsi(-math.f32_max, math.minInt(i32));12 try test__fixsfsi(-math.f32_max, math.minInt(i32));
1613
17 try test__fixsfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32));14 try test__fixsfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32));
lib/std/special/compiler_rt/fixsfti_test.zig-3
...@@ -2,16 +2,13 @@ const __fixsfti = @import("fixsfti.zig").__fixsfti;...@@ -2,16 +2,13 @@ const __fixsfti = @import("fixsfti.zig").__fixsfti;
2const std = @import("std");2const std = @import("std");
3const math = std.math;3const math = std.math;
4const testing = std.testing;4const testing = std.testing;
5const warn = std.debug.warn;
65
7fn test__fixsfti(a: f32, expected: i128) !void {6fn test__fixsfti(a: f32, expected: i128) !void {
8 const x = __fixsfti(a);7 const x = __fixsfti(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", .{a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u128, expected)});
10 try testing.expect(x == expected);8 try testing.expect(x == expected);
11}9}
1210
13test "fixsfti" {11test "fixsfti" {
14 //warn("\n", .{});
15 try test__fixsfti(-math.f32_max, math.minInt(i128));12 try test__fixsfti(-math.f32_max, math.minInt(i128));
1613
17 try test__fixsfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128));14 try test__fixsfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128));
lib/std/special/compiler_rt/fixtfdi_test.zig-3
...@@ -2,16 +2,13 @@ const __fixtfdi = @import("fixtfdi.zig").__fixtfdi;...@@ -2,16 +2,13 @@ const __fixtfdi = @import("fixtfdi.zig").__fixtfdi;
2const std = @import("std");2const std = @import("std");
3const math = std.math;3const math = std.math;
4const testing = std.testing;4const testing = std.testing;
5const warn = std.debug.warn;
65
7fn test__fixtfdi(a: f128, expected: i64) !void {6fn test__fixtfdi(a: f128, expected: i64) !void {
8 const x = __fixtfdi(a);7 const x = __fixtfdi(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u64, expected)});
10 try testing.expect(x == expected);8 try testing.expect(x == expected);
11}9}
1210
13test "fixtfdi" {11test "fixtfdi" {
14 //warn("\n", .{});
15 try test__fixtfdi(-math.f128_max, math.minInt(i64));12 try test__fixtfdi(-math.f128_max, math.minInt(i64));
1613
17 try test__fixtfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64));14 try test__fixtfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64));
lib/std/special/compiler_rt/fixtfsi_test.zig-3
...@@ -2,16 +2,13 @@ const __fixtfsi = @import("fixtfsi.zig").__fixtfsi;...@@ -2,16 +2,13 @@ const __fixtfsi = @import("fixtfsi.zig").__fixtfsi;
2const std = @import("std");2const std = @import("std");
3const math = std.math;3const math = std.math;
4const testing = std.testing;4const testing = std.testing;
5const warn = std.debug.warn;
65
7fn test__fixtfsi(a: f128, expected: i32) !void {6fn test__fixtfsi(a: f128, expected: i32) !void {
8 const x = __fixtfsi(a);7 const x = __fixtfsi(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", .{a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u32, expected)});
10 try testing.expect(x == expected);8 try testing.expect(x == expected);
11}9}
1210
13test "fixtfsi" {11test "fixtfsi" {
14 //warn("\n", .{});
15 try test__fixtfsi(-math.f128_max, math.minInt(i32));12 try test__fixtfsi(-math.f128_max, math.minInt(i32));
1613
17 try test__fixtfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32));14 try test__fixtfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32));
lib/std/special/compiler_rt/fixtfti_test.zig-3
...@@ -2,16 +2,13 @@ const __fixtfti = @import("fixtfti.zig").__fixtfti;...@@ -2,16 +2,13 @@ const __fixtfti = @import("fixtfti.zig").__fixtfti;
2const std = @import("std");2const std = @import("std");
3const math = std.math;3const math = std.math;
4const testing = std.testing;4const testing = std.testing;
5const warn = std.debug.warn;
65
7fn test__fixtfti(a: f128, expected: i128) !void {6fn test__fixtfti(a: f128, expected: i128) !void {
8 const x = __fixtfti(a);7 const x = __fixtfti(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", .{a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u128, expected)});
10 try testing.expect(x == expected);8 try testing.expect(x == expected);
11}9}
1210
13test "fixtfti" {11test "fixtfti" {
14 //warn("\n", .{});
15 try test__fixtfti(-math.f128_max, math.minInt(i128));12 try test__fixtfti(-math.f128_max, math.minInt(i128));
1613
17 try test__fixtfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128));14 try test__fixtfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128));
lib/std/special/compiler_rt/truncXfYf2_test.zig+2-2
...@@ -217,7 +217,7 @@ fn test__truncdfsf2(a: f64, expected: u32) void {...@@ -217,7 +217,7 @@ fn test__truncdfsf2(a: f64, expected: u32) void {
217 }217 }
218 }218 }
219219
220 @import("std").debug.warn("got 0x{x} wanted 0x{x}\n", .{ rep, expected });220 @import("std").debug.print("got 0x{x} wanted 0x{x}\n", .{ rep, expected });
221221
222 @panic("__trunctfsf2 test failure");222 @panic("__trunctfsf2 test failure");
223}223}
...@@ -248,7 +248,7 @@ fn test__trunctfhf2(a: f128, expected: u16) void {...@@ -248,7 +248,7 @@ fn test__trunctfhf2(a: f128, expected: u16) void {
248 return;248 return;
249 }249 }
250250
251 @import("std").debug.warn("got 0x{x} wanted 0x{x}\n", .{ rep, expected });251 @import("std").debug.print("got 0x{x} wanted 0x{x}\n", .{ rep, expected });
252252
253 @panic("__trunctfhf2 test failure");253 @panic("__trunctfhf2 test failure");
254}254}
lib/std/testing.zig-3
...@@ -208,9 +208,6 @@ pub fn expectFmt(expected: []const u8, comptime template: []const u8, args: anyt...@@ -208,9 +208,6 @@ pub fn expectFmt(expected: []const u8, comptime template: []const u8, args: anyt
208 return error.TestExpectedFmt;208 return error.TestExpectedFmt;
209}209}
210210
211pub const expectWithinMargin = @compileError("expectWithinMargin is deprecated, use expectApproxEqAbs or expectApproxEqRel");
212pub const expectWithinEpsilon = @compileError("expectWithinEpsilon is deprecated, use expectApproxEqAbs or expectApproxEqRel");
213
214/// This function is intended to be used only in tests. When the actual value is211/// This function is intended to be used only in tests. When the actual value is
215/// not approximately equal to the expected value, prints diagnostics to stderr212/// not approximately equal to the expected value, prints diagnostics to stderr
216/// to show exactly how they are not equal, then aborts.213/// to show exactly how they are not equal, then aborts.
lib/std/unicode.zig+1-1
...@@ -216,7 +216,7 @@ pub fn utf8ValidateSlice(s: []const u8) bool {...@@ -216,7 +216,7 @@ pub fn utf8ValidateSlice(s: []const u8) bool {
216/// ```216/// ```
217/// var utf8 = (try std.unicode.Utf8View.init("hi there")).iterator();217/// var utf8 = (try std.unicode.Utf8View.init("hi there")).iterator();
218/// while (utf8.nextCodepointSlice()) |codepoint| {218/// while (utf8.nextCodepointSlice()) |codepoint| {
219/// std.debug.warn("got codepoint {}\n", .{codepoint});219/// std.debug.print("got codepoint {}\n", .{codepoint});
220/// }220/// }
221/// ```221/// ```
222pub const Utf8View = struct {222pub const Utf8View = struct {
lib/std/zig.zig+1-1
...@@ -12,7 +12,7 @@ pub const parse = @import("zig/parse.zig").parse;...@@ -12,7 +12,7 @@ pub const parse = @import("zig/parse.zig").parse;
12pub const string_literal = @import("zig/string_literal.zig");12pub const string_literal = @import("zig/string_literal.zig");
13pub const Ast = @import("zig/Ast.zig");13pub const Ast = @import("zig/Ast.zig");
14pub const system = @import("zig/system.zig");14pub const system = @import("zig/system.zig");
15pub const CrossTarget = @import("zig/cross_target.zig").CrossTarget;15pub const CrossTarget = @import("zig/CrossTarget.zig");
1616
17// Files needed by translate-c.17// Files needed by translate-c.
18pub const c_builtins = @import("zig/c_builtins.zig");18pub const c_builtins = @import("zig/c_builtins.zig");
lib/std/zig/CrossTarget.zig created+909
...@@ -0,0 +1,909 @@
1//! Contains all the same data as `Target`, additionally introducing the concept of "the native target".
2//! The purpose of this abstraction is to provide meaningful and unsurprising defaults.
3//! This struct does reference any resources and it is copyable.
4
5const CrossTarget = @This();
6const std = @import("../std.zig");
7const builtin = @import("builtin");
8const assert = std.debug.assert;
9const Target = std.Target;
10const mem = std.mem;
11
12/// `null` means native.
13cpu_arch: ?Target.Cpu.Arch = null,
14
15cpu_model: CpuModel = CpuModel.determined_by_cpu_arch,
16
17/// Sparse set of CPU features to add to the set from `cpu_model`.
18cpu_features_add: Target.Cpu.Feature.Set = Target.Cpu.Feature.Set.empty,
19
20/// Sparse set of CPU features to remove from the set from `cpu_model`.
21cpu_features_sub: Target.Cpu.Feature.Set = Target.Cpu.Feature.Set.empty,
22
23/// `null` means native.
24os_tag: ?Target.Os.Tag = null,
25
26/// `null` means the default version range for `os_tag`. If `os_tag` is `null` (native)
27/// then `null` for this field means native.
28os_version_min: ?OsVersion = null,
29
30/// When cross compiling, `null` means default (latest known OS version).
31/// When `os_tag` is native, `null` means equal to the native OS version.
32os_version_max: ?OsVersion = null,
33
34/// `null` means default when cross compiling, or native when os_tag is native.
35/// If `isGnuLibC()` is `false`, this must be `null` and is ignored.
36glibc_version: ?SemVer = null,
37
38/// `null` means the native C ABI, if `os_tag` is native, otherwise it means the default C ABI.
39abi: ?Target.Abi = null,
40
41/// When `os_tag` is `null`, then `null` means native. Otherwise it means the standard path
42/// based on the `os_tag`.
43dynamic_linker: DynamicLinker = DynamicLinker{},
44
45pub const CpuModel = union(enum) {
46 /// Always native
47 native,
48
49 /// Always baseline
50 baseline,
51
52 /// If CPU Architecture is native, then the CPU model will be native. Otherwise,
53 /// it will be baseline.
54 determined_by_cpu_arch,
55
56 explicit: *const Target.Cpu.Model,
57};
58
59pub const OsVersion = union(enum) {
60 none: void,
61 semver: SemVer,
62 windows: Target.Os.WindowsVersion,
63};
64
65pub const SemVer = std.builtin.Version;
66
67pub const DynamicLinker = Target.DynamicLinker;
68
69pub fn fromTarget(target: Target) CrossTarget {
70 var result: CrossTarget = .{
71 .cpu_arch = target.cpu.arch,
72 .cpu_model = .{ .explicit = target.cpu.model },
73 .os_tag = target.os.tag,
74 .os_version_min = undefined,
75 .os_version_max = undefined,
76 .abi = target.abi,
77 .glibc_version = if (target.isGnuLibC())
78 target.os.version_range.linux.glibc
79 else
80 null,
81 };
82 result.updateOsVersionRange(target.os);
83
84 const all_features = target.cpu.arch.allFeaturesList();
85 var cpu_model_set = target.cpu.model.features;
86 cpu_model_set.populateDependencies(all_features);
87 {
88 // The "add" set is the full set with the CPU Model set removed.
89 const add_set = &result.cpu_features_add;
90 add_set.* = target.cpu.features;
91 add_set.removeFeatureSet(cpu_model_set);
92 }
93 {
94 // The "sub" set is the features that are on in CPU Model set and off in the full set.
95 const sub_set = &result.cpu_features_sub;
96 sub_set.* = cpu_model_set;
97 sub_set.removeFeatureSet(target.cpu.features);
98 }
99 return result;
100}
101
102fn updateOsVersionRange(self: *CrossTarget, os: Target.Os) void {
103 switch (os.tag) {
104 .freestanding,
105 .ananas,
106 .cloudabi,
107 .fuchsia,
108 .kfreebsd,
109 .lv2,
110 .solaris,
111 .zos,
112 .haiku,
113 .minix,
114 .rtems,
115 .nacl,
116 .aix,
117 .cuda,
118 .nvcl,
119 .amdhsa,
120 .ps4,
121 .elfiamcu,
122 .mesa3d,
123 .contiki,
124 .amdpal,
125 .hermit,
126 .hurd,
127 .wasi,
128 .emscripten,
129 .uefi,
130 .opencl,
131 .glsl450,
132 .vulkan,
133 .plan9,
134 .other,
135 => {
136 self.os_version_min = .{ .none = {} };
137 self.os_version_max = .{ .none = {} };
138 },
139
140 .freebsd,
141 .macos,
142 .ios,
143 .tvos,
144 .watchos,
145 .netbsd,
146 .openbsd,
147 .dragonfly,
148 => {
149 self.os_version_min = .{ .semver = os.version_range.semver.min };
150 self.os_version_max = .{ .semver = os.version_range.semver.max };
151 },
152
153 .linux => {
154 self.os_version_min = .{ .semver = os.version_range.linux.range.min };
155 self.os_version_max = .{ .semver = os.version_range.linux.range.max };
156 },
157
158 .windows => {
159 self.os_version_min = .{ .windows = os.version_range.windows.min };
160 self.os_version_max = .{ .windows = os.version_range.windows.max };
161 },
162 }
163}
164
165/// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.
166pub fn toTarget(self: CrossTarget) Target {
167 return .{
168 .cpu = self.getCpu(),
169 .os = self.getOs(),
170 .abi = self.getAbi(),
171 };
172}
173
174pub const ParseOptions = struct {
175 /// This is sometimes called a "triple". It looks roughly like this:
176 /// riscv64-linux-musl
177 /// The fields are, respectively:
178 /// * CPU Architecture
179 /// * Operating System (and optional version range)
180 /// * C ABI (optional, with optional glibc version)
181 /// The string "native" can be used for CPU architecture as well as Operating System.
182 /// If the CPU Architecture is specified as "native", then the Operating System and C ABI may be omitted.
183 arch_os_abi: []const u8 = "native",
184
185 /// Looks like "name+a+b-c-d+e", where "name" is a CPU Model name, "a", "b", and "e"
186 /// are examples of CPU features to add to the set, and "c" and "d" are examples of CPU features
187 /// to remove from the set.
188 /// The following special strings are recognized for CPU Model name:
189 /// * "baseline" - The "default" set of CPU features for cross-compiling. A conservative set
190 /// of features that is expected to be supported on most available hardware.
191 /// * "native" - The native CPU model is to be detected when compiling.
192 /// If this field is not provided (`null`), then the value will depend on the
193 /// parsed CPU Architecture. If native, then this will be "native". Otherwise, it will be "baseline".
194 cpu_features: ?[]const u8 = null,
195
196 /// Absolute path to dynamic linker, to override the default, which is either a natively
197 /// detected path, or a standard path.
198 dynamic_linker: ?[]const u8 = null,
199
200 /// If this is provided, the function will populate some information about parsing failures,
201 /// so that user-friendly error messages can be delivered.
202 diagnostics: ?*Diagnostics = null,
203
204 pub const Diagnostics = struct {
205 /// If the architecture was determined, this will be populated.
206 arch: ?Target.Cpu.Arch = null,
207
208 /// If the OS name was determined, this will be populated.
209 os_name: ?[]const u8 = null,
210
211 /// If the OS tag was determined, this will be populated.
212 os_tag: ?Target.Os.Tag = null,
213
214 /// If the ABI was determined, this will be populated.
215 abi: ?Target.Abi = null,
216
217 /// If the CPU name was determined, this will be populated.
218 cpu_name: ?[]const u8 = null,
219
220 /// If error.UnknownCpuFeature is returned, this will be populated.
221 unknown_feature_name: ?[]const u8 = null,
222 };
223};
224
225pub fn parse(args: ParseOptions) !CrossTarget {
226 var dummy_diags: ParseOptions.Diagnostics = undefined;
227 const diags = args.diagnostics orelse &dummy_diags;
228
229 var result: CrossTarget = .{
230 .dynamic_linker = DynamicLinker.init(args.dynamic_linker),
231 };
232
233 var it = mem.split(u8, args.arch_os_abi, "-");
234 const arch_name = it.next().?;
235 const arch_is_native = mem.eql(u8, arch_name, "native");
236 if (!arch_is_native) {
237 result.cpu_arch = std.meta.stringToEnum(Target.Cpu.Arch, arch_name) orelse
238 return error.UnknownArchitecture;
239 }
240 const arch = result.getCpuArch();
241 diags.arch = arch;
242
243 if (it.next()) |os_text| {
244 try parseOs(&result, diags, os_text);
245 } else if (!arch_is_native) {
246 return error.MissingOperatingSystem;
247 }
248
249 const opt_abi_text = it.next();
250 if (opt_abi_text) |abi_text| {
251 var abi_it = mem.split(u8, abi_text, ".");
252 const abi = std.meta.stringToEnum(Target.Abi, abi_it.next().?) orelse
253 return error.UnknownApplicationBinaryInterface;
254 result.abi = abi;
255 diags.abi = abi;
256
257 const abi_ver_text = abi_it.rest();
258 if (abi_it.next() != null) {
259 if (result.isGnuLibC()) {
260 result.glibc_version = SemVer.parse(abi_ver_text) catch |err| switch (err) {
261 error.Overflow => return error.InvalidAbiVersion,
262 error.InvalidCharacter => return error.InvalidAbiVersion,
263 error.InvalidVersion => return error.InvalidAbiVersion,
264 };
265 } else {
266 return error.InvalidAbiVersion;
267 }
268 }
269 }
270
271 if (it.next() != null) return error.UnexpectedExtraField;
272
273 if (args.cpu_features) |cpu_features| {
274 const all_features = arch.allFeaturesList();
275 var index: usize = 0;
276 while (index < cpu_features.len and
277 cpu_features[index] != '+' and
278 cpu_features[index] != '-')
279 {
280 index += 1;
281 }
282 const cpu_name = cpu_features[0..index];
283 diags.cpu_name = cpu_name;
284
285 const add_set = &result.cpu_features_add;
286 const sub_set = &result.cpu_features_sub;
287 if (mem.eql(u8, cpu_name, "native")) {
288 result.cpu_model = .native;
289 } else if (mem.eql(u8, cpu_name, "baseline")) {
290 result.cpu_model = .baseline;
291 } else {
292 result.cpu_model = .{ .explicit = try arch.parseCpuModel(cpu_name) };
293 }
294
295 while (index < cpu_features.len) {
296 const op = cpu_features[index];
297 const set = switch (op) {
298 '+' => add_set,
299 '-' => sub_set,
300 else => unreachable,
301 };
302 index += 1;
303 const start = index;
304 while (index < cpu_features.len and
305 cpu_features[index] != '+' and
306 cpu_features[index] != '-')
307 {
308 index += 1;
309 }
310 const feature_name = cpu_features[start..index];
311 for (all_features) |feature, feat_index_usize| {
312 const feat_index = @intCast(Target.Cpu.Feature.Set.Index, feat_index_usize);
313 if (mem.eql(u8, feature_name, feature.name)) {
314 set.addFeature(feat_index);
315 break;
316 }
317 } else {
318 diags.unknown_feature_name = feature_name;
319 return error.UnknownCpuFeature;
320 }
321 }
322 }
323
324 return result;
325}
326
327/// Similar to `parse` except instead of fully parsing, it only determines the CPU
328/// architecture and returns it if it can be determined, and returns `null` otherwise.
329/// This is intended to be used if the API user of CrossTarget needs to learn the
330/// target CPU architecture in order to fully populate `ParseOptions`.
331pub fn parseCpuArch(args: ParseOptions) ?Target.Cpu.Arch {
332 var it = mem.split(u8, args.arch_os_abi, "-");
333 const arch_name = it.next().?;
334 const arch_is_native = mem.eql(u8, arch_name, "native");
335 if (arch_is_native) {
336 return builtin.cpu.arch;
337 } else {
338 return std.meta.stringToEnum(Target.Cpu.Arch, arch_name);
339 }
340}
341
342/// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.
343pub fn getCpu(self: CrossTarget) Target.Cpu {
344 switch (self.cpu_model) {
345 .native => {
346 // This works when doing `zig build` because Zig generates a build executable using
347 // native CPU model & features. However this will not be accurate otherwise, and
348 // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`.
349 return builtin.cpu;
350 },
351 .baseline => {
352 var adjusted_baseline = Target.Cpu.baseline(self.getCpuArch());
353 self.updateCpuFeatures(&adjusted_baseline.features);
354 return adjusted_baseline;
355 },
356 .determined_by_cpu_arch => if (self.cpu_arch == null) {
357 // This works when doing `zig build` because Zig generates a build executable using
358 // native CPU model & features. However this will not be accurate otherwise, and
359 // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`.
360 return builtin.cpu;
361 } else {
362 var adjusted_baseline = Target.Cpu.baseline(self.getCpuArch());
363 self.updateCpuFeatures(&adjusted_baseline.features);
364 return adjusted_baseline;
365 },
366 .explicit => |model| {
367 var adjusted_model = model.toCpu(self.getCpuArch());
368 self.updateCpuFeatures(&adjusted_model.features);
369 return adjusted_model;
370 },
371 }
372}
373
374pub fn getCpuArch(self: CrossTarget) Target.Cpu.Arch {
375 return self.cpu_arch orelse builtin.cpu.arch;
376}
377
378pub fn getCpuModel(self: CrossTarget) *const Target.Cpu.Model {
379 return switch (self.cpu_model) {
380 .explicit => |cpu_model| cpu_model,
381 else => self.getCpu().model,
382 };
383}
384
385pub fn getCpuFeatures(self: CrossTarget) Target.Cpu.Feature.Set {
386 return self.getCpu().features;
387}
388
389/// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.
390pub fn getOs(self: CrossTarget) Target.Os {
391 // `builtin.os` works when doing `zig build` because Zig generates a build executable using
392 // native OS version range. However this will not be accurate otherwise, and
393 // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`.
394 var adjusted_os = if (self.os_tag) |os_tag| os_tag.defaultVersionRange(self.getCpuArch()) else builtin.os;
395
396 if (self.os_version_min) |min| switch (min) {
397 .none => {},
398 .semver => |semver| switch (self.getOsTag()) {
399 .linux => adjusted_os.version_range.linux.range.min = semver,
400 else => adjusted_os.version_range.semver.min = semver,
401 },
402 .windows => |win_ver| adjusted_os.version_range.windows.min = win_ver,
403 };
404
405 if (self.os_version_max) |max| switch (max) {
406 .none => {},
407 .semver => |semver| switch (self.getOsTag()) {
408 .linux => adjusted_os.version_range.linux.range.max = semver,
409 else => adjusted_os.version_range.semver.max = semver,
410 },
411 .windows => |win_ver| adjusted_os.version_range.windows.max = win_ver,
412 };
413
414 if (self.glibc_version) |glibc| {
415 assert(self.isGnuLibC());
416 adjusted_os.version_range.linux.glibc = glibc;
417 }
418
419 return adjusted_os;
420}
421
422pub fn getOsTag(self: CrossTarget) Target.Os.Tag {
423 return self.os_tag orelse builtin.os.tag;
424}
425
426/// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.
427pub fn getOsVersionMin(self: CrossTarget) OsVersion {
428 if (self.os_version_min) |version_min| return version_min;
429 var tmp: CrossTarget = undefined;
430 tmp.updateOsVersionRange(self.getOs());
431 return tmp.os_version_min.?;
432}
433
434/// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.
435pub fn getOsVersionMax(self: CrossTarget) OsVersion {
436 if (self.os_version_max) |version_max| return version_max;
437 var tmp: CrossTarget = undefined;
438 tmp.updateOsVersionRange(self.getOs());
439 return tmp.os_version_max.?;
440}
441
442/// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.
443pub fn getAbi(self: CrossTarget) Target.Abi {
444 if (self.abi) |abi| return abi;
445
446 if (self.os_tag == null) {
447 // This works when doing `zig build` because Zig generates a build executable using
448 // native CPU model & features. However this will not be accurate otherwise, and
449 // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`.
450 return builtin.abi;
451 }
452
453 return Target.Abi.default(self.getCpuArch(), self.getOs());
454}
455
456pub fn isFreeBSD(self: CrossTarget) bool {
457 return self.getOsTag() == .freebsd;
458}
459
460pub fn isDarwin(self: CrossTarget) bool {
461 return self.getOsTag().isDarwin();
462}
463
464pub fn isNetBSD(self: CrossTarget) bool {
465 return self.getOsTag() == .netbsd;
466}
467
468pub fn isOpenBSD(self: CrossTarget) bool {
469 return self.getOsTag() == .openbsd;
470}
471
472pub fn isUefi(self: CrossTarget) bool {
473 return self.getOsTag() == .uefi;
474}
475
476pub fn isDragonFlyBSD(self: CrossTarget) bool {
477 return self.getOsTag() == .dragonfly;
478}
479
480pub fn isLinux(self: CrossTarget) bool {
481 return self.getOsTag() == .linux;
482}
483
484pub fn isWindows(self: CrossTarget) bool {
485 return self.getOsTag() == .windows;
486}
487
488pub fn exeFileExt(self: CrossTarget) [:0]const u8 {
489 return Target.exeFileExtSimple(self.getCpuArch(), self.getOsTag());
490}
491
492pub fn staticLibSuffix(self: CrossTarget) [:0]const u8 {
493 return Target.staticLibSuffix_os_abi(self.getOsTag(), self.getAbi());
494}
495
496pub fn dynamicLibSuffix(self: CrossTarget) [:0]const u8 {
497 return self.getOsTag().dynamicLibSuffix();
498}
499
500pub fn libPrefix(self: CrossTarget) [:0]const u8 {
501 return Target.libPrefix_os_abi(self.getOsTag(), self.getAbi());
502}
503
504pub fn isNativeCpu(self: CrossTarget) bool {
505 return self.cpu_arch == null and
506 (self.cpu_model == .native or self.cpu_model == .determined_by_cpu_arch) and
507 self.cpu_features_sub.isEmpty() and self.cpu_features_add.isEmpty();
508}
509
510pub fn isNativeOs(self: CrossTarget) bool {
511 return self.os_tag == null and self.os_version_min == null and self.os_version_max == null and
512 self.dynamic_linker.get() == null and self.glibc_version == null;
513}
514
515pub fn isNativeAbi(self: CrossTarget) bool {
516 return self.os_tag == null and self.abi == null;
517}
518
519pub fn isNative(self: CrossTarget) bool {
520 return self.isNativeCpu() and self.isNativeOs() and self.isNativeAbi();
521}
522
523pub fn zigTriple(self: CrossTarget, allocator: *mem.Allocator) error{OutOfMemory}![]u8 {
524 if (self.isNative()) {
525 return allocator.dupe(u8, "native");
526 }
527
528 const arch_name = if (self.cpu_arch) |arch| @tagName(arch) else "native";
529 const os_name = if (self.os_tag) |os_tag| @tagName(os_tag) else "native";
530
531 var result = std.ArrayList(u8).init(allocator);
532 defer result.deinit();
533
534 try result.writer().print("{s}-{s}", .{ arch_name, os_name });
535
536 // The zig target syntax does not allow specifying a max os version with no min, so
537 // if either are present, we need the min.
538 if (self.os_version_min != null or self.os_version_max != null) {
539 switch (self.getOsVersionMin()) {
540 .none => {},
541 .semver => |v| try result.writer().print(".{}", .{v}),
542 .windows => |v| try result.writer().print("{s}", .{v}),
543 }
544 }
545 if (self.os_version_max) |max| {
546 switch (max) {
547 .none => {},
548 .semver => |v| try result.writer().print("...{}", .{v}),
549 .windows => |v| try result.writer().print("..{s}", .{v}),
550 }
551 }
552
553 if (self.glibc_version) |v| {
554 try result.writer().print("-{s}.{}", .{ @tagName(self.getAbi()), v });
555 } else if (self.abi) |abi| {
556 try result.writer().print("-{s}", .{@tagName(abi)});
557 }
558
559 return result.toOwnedSlice();
560}
561
562pub fn allocDescription(self: CrossTarget, allocator: *mem.Allocator) ![]u8 {
563 // TODO is there anything else worthy of the description that is not
564 // already captured in the triple?
565 return self.zigTriple(allocator);
566}
567
568pub fn linuxTriple(self: CrossTarget, allocator: *mem.Allocator) ![]u8 {
569 return Target.linuxTripleSimple(allocator, self.getCpuArch(), self.getOsTag(), self.getAbi());
570}
571
572pub fn wantSharedLibSymLinks(self: CrossTarget) bool {
573 return self.getOsTag() != .windows;
574}
575
576pub const VcpkgLinkage = std.builtin.LinkMode;
577
578/// Returned slice must be freed by the caller.
579pub fn vcpkgTriplet(self: CrossTarget, allocator: *mem.Allocator, linkage: VcpkgLinkage) ![]u8 {
580 const arch = switch (self.getCpuArch()) {
581 .i386 => "x86",
582 .x86_64 => "x64",
583
584 .arm,
585 .armeb,
586 .thumb,
587 .thumbeb,
588 .aarch64_32,
589 => "arm",
590
591 .aarch64,
592 .aarch64_be,
593 => "arm64",
594
595 else => return error.UnsupportedVcpkgArchitecture,
596 };
597
598 const os = switch (self.getOsTag()) {
599 .windows => "windows",
600 .linux => "linux",
601 .macos => "macos",
602 else => return error.UnsupportedVcpkgOperatingSystem,
603 };
604
605 const static_suffix = switch (linkage) {
606 .Static => "-static",
607 .Dynamic => "",
608 };
609
610 return std.fmt.allocPrint(allocator, "{s}-{s}{s}", .{ arch, os, static_suffix });
611}
612
613pub const Executor = union(enum) {
614 native,
615 qemu: []const u8,
616 wine: []const u8,
617 wasmtime: []const u8,
618 darling: []const u8,
619 unavailable,
620};
621
622/// Note that even a `CrossTarget` which returns `false` for `isNative` could still be natively executed.
623/// For example `-target arm-native` running on an aarch64 host.
624pub fn getExternalExecutor(self: CrossTarget) Executor {
625 const cpu_arch = self.getCpuArch();
626 const os_tag = self.getOsTag();
627 const os_match = os_tag == builtin.os.tag;
628
629 // If the OS and CPU arch match, the binary can be considered native.
630 // TODO additionally match the CPU features. This `getExternalExecutor` function should
631 // be moved to std.Target and match any chosen target against the native target.
632 if (os_match and cpu_arch == builtin.cpu.arch) {
633 // However, we also need to verify that the dynamic linker path is valid.
634 if (self.os_tag == null) {
635 return .native;
636 }
637 // TODO here we call toTarget, a deprecated function, because of the above TODO about moving
638 // this code to std.Target.
639 const opt_dl = self.dynamic_linker.get() orelse self.toTarget().standardDynamicLinkerPath().get();
640 if (opt_dl) |dl| blk: {
641 std.fs.cwd().access(dl, .{}) catch break :blk;
642 return .native;
643 }
644 }
645
646 // If the OS matches, we can use QEMU to emulate a foreign architecture.
647 if (os_match) {
648 return switch (cpu_arch) {
649 .aarch64 => Executor{ .qemu = "qemu-aarch64" },
650 .aarch64_be => Executor{ .qemu = "qemu-aarch64_be" },
651 .arm => Executor{ .qemu = "qemu-arm" },
652 .armeb => Executor{ .qemu = "qemu-armeb" },
653 .i386 => Executor{ .qemu = "qemu-i386" },
654 .mips => Executor{ .qemu = "qemu-mips" },
655 .mipsel => Executor{ .qemu = "qemu-mipsel" },
656 .mips64 => Executor{ .qemu = "qemu-mips64" },
657 .mips64el => Executor{ .qemu = "qemu-mips64el" },
658 .powerpc => Executor{ .qemu = "qemu-ppc" },
659 .powerpc64 => Executor{ .qemu = "qemu-ppc64" },
660 .powerpc64le => Executor{ .qemu = "qemu-ppc64le" },
661 .riscv32 => Executor{ .qemu = "qemu-riscv32" },
662 .riscv64 => Executor{ .qemu = "qemu-riscv64" },
663 .s390x => Executor{ .qemu = "qemu-s390x" },
664 .sparc => Executor{ .qemu = "qemu-sparc" },
665 .x86_64 => Executor{ .qemu = "qemu-x86_64" },
666 else => return .unavailable,
667 };
668 }
669
670 switch (os_tag) {
671 .windows => switch (cpu_arch.ptrBitWidth()) {
672 32 => return Executor{ .wine = "wine" },
673 64 => return Executor{ .wine = "wine64" },
674 else => return .unavailable,
675 },
676 .wasi => switch (cpu_arch.ptrBitWidth()) {
677 32 => return Executor{ .wasmtime = "wasmtime" },
678 else => return .unavailable,
679 },
680 .macos => {
681 // TODO loosen this check once upstream adds QEMU-based emulation
682 // layer for non-host architectures:
683 // https://github.com/darlinghq/darling/issues/863
684 if (cpu_arch != builtin.cpu.arch) {
685 return .unavailable;
686 }
687 return Executor{ .darling = "darling" };
688 },
689 else => return .unavailable,
690 }
691}
692
693pub fn isGnuLibC(self: CrossTarget) bool {
694 return Target.isGnuLibC_os_tag_abi(self.getOsTag(), self.getAbi());
695}
696
697pub fn setGnuLibCVersion(self: *CrossTarget, major: u32, minor: u32, patch: u32) void {
698 assert(self.isGnuLibC());
699 self.glibc_version = SemVer{ .major = major, .minor = minor, .patch = patch };
700}
701
702pub fn getObjectFormat(self: CrossTarget) Target.ObjectFormat {
703 return Target.getObjectFormatSimple(self.getOsTag(), self.getCpuArch());
704}
705
706pub fn updateCpuFeatures(self: CrossTarget, set: *Target.Cpu.Feature.Set) void {
707 set.removeFeatureSet(self.cpu_features_sub);
708 set.addFeatureSet(self.cpu_features_add);
709 set.populateDependencies(self.getCpuArch().allFeaturesList());
710 set.removeFeatureSet(self.cpu_features_sub);
711}
712
713fn parseOs(result: *CrossTarget, diags: *ParseOptions.Diagnostics, text: []const u8) !void {
714 var it = mem.split(u8, text, ".");
715 const os_name = it.next().?;
716 diags.os_name = os_name;
717 const os_is_native = mem.eql(u8, os_name, "native");
718 if (!os_is_native) {
719 result.os_tag = std.meta.stringToEnum(Target.Os.Tag, os_name) orelse
720 return error.UnknownOperatingSystem;
721 }
722 const tag = result.getOsTag();
723 diags.os_tag = tag;
724
725 const version_text = it.rest();
726 if (it.next() == null) return;
727
728 switch (tag) {
729 .freestanding,
730 .ananas,
731 .cloudabi,
732 .fuchsia,
733 .kfreebsd,
734 .lv2,
735 .solaris,
736 .zos,
737 .haiku,
738 .minix,
739 .rtems,
740 .nacl,
741 .aix,
742 .cuda,
743 .nvcl,
744 .amdhsa,
745 .ps4,
746 .elfiamcu,
747 .mesa3d,
748 .contiki,
749 .amdpal,
750 .hermit,
751 .hurd,
752 .wasi,
753 .emscripten,
754 .uefi,
755 .opencl,
756 .glsl450,
757 .vulkan,
758 .plan9,
759 .other,
760 => return error.InvalidOperatingSystemVersion,
761
762 .freebsd,
763 .macos,
764 .ios,
765 .tvos,
766 .watchos,
767 .netbsd,
768 .openbsd,
769 .linux,
770 .dragonfly,
771 => {
772 var range_it = mem.split(u8, version_text, "...");
773
774 const min_text = range_it.next().?;
775 const min_ver = SemVer.parse(min_text) catch |err| switch (err) {
776 error.Overflow => return error.InvalidOperatingSystemVersion,
777 error.InvalidCharacter => return error.InvalidOperatingSystemVersion,
778 error.InvalidVersion => return error.InvalidOperatingSystemVersion,
779 };
780 result.os_version_min = .{ .semver = min_ver };
781
782 const max_text = range_it.next() orelse return;
783 const max_ver = SemVer.parse(max_text) catch |err| switch (err) {
784 error.Overflow => return error.InvalidOperatingSystemVersion,
785 error.InvalidCharacter => return error.InvalidOperatingSystemVersion,
786 error.InvalidVersion => return error.InvalidOperatingSystemVersion,
787 };
788 result.os_version_max = .{ .semver = max_ver };
789 },
790
791 .windows => {
792 var range_it = mem.split(u8, version_text, "...");
793
794 const min_text = range_it.next().?;
795 const min_ver = std.meta.stringToEnum(Target.Os.WindowsVersion, min_text) orelse
796 return error.InvalidOperatingSystemVersion;
797 result.os_version_min = .{ .windows = min_ver };
798
799 const max_text = range_it.next() orelse return;
800 const max_ver = std.meta.stringToEnum(Target.Os.WindowsVersion, max_text) orelse
801 return error.InvalidOperatingSystemVersion;
802 result.os_version_max = .{ .windows = max_ver };
803 },
804 }
805}
806
807test "CrossTarget.parse" {
808 if (builtin.target.isGnuLibC()) {
809 var cross_target = try CrossTarget.parse(.{});
810 cross_target.setGnuLibCVersion(2, 1, 1);
811
812 const text = try cross_target.zigTriple(std.testing.allocator);
813 defer std.testing.allocator.free(text);
814
815 var buf: [256]u8 = undefined;
816 const triple = std.fmt.bufPrint(
817 buf[0..],
818 "native-native-{s}.2.1.1",
819 .{@tagName(builtin.abi)},
820 ) catch unreachable;
821
822 try std.testing.expectEqualSlices(u8, triple, text);
823 }
824 {
825 const cross_target = try CrossTarget.parse(.{
826 .arch_os_abi = "aarch64-linux",
827 .cpu_features = "native",
828 });
829
830 try std.testing.expect(cross_target.cpu_arch.? == .aarch64);
831 try std.testing.expect(cross_target.cpu_model == .native);
832 }
833 {
834 const cross_target = try CrossTarget.parse(.{ .arch_os_abi = "native" });
835
836 try std.testing.expect(cross_target.cpu_arch == null);
837 try std.testing.expect(cross_target.isNative());
838
839 const text = try cross_target.zigTriple(std.testing.allocator);
840 defer std.testing.allocator.free(text);
841 try std.testing.expectEqualSlices(u8, "native", text);
842 }
843 {
844 const cross_target = try CrossTarget.parse(.{
845 .arch_os_abi = "x86_64-linux-gnu",
846 .cpu_features = "x86_64-sse-sse2-avx-cx8",
847 });
848 const target = cross_target.toTarget();
849
850 try std.testing.expect(target.os.tag == .linux);
851 try std.testing.expect(target.abi == .gnu);
852 try std.testing.expect(target.cpu.arch == .x86_64);
853 try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .sse));
854 try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .avx));
855 try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .cx8));
856 try std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .cmov));
857 try std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .fxsr));
858
859 try std.testing.expect(Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx, .cmov }));
860 try std.testing.expect(!Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx }));
861 try std.testing.expect(Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87 }));
862 try std.testing.expect(!Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87, .sse }));
863
864 const text = try cross_target.zigTriple(std.testing.allocator);
865 defer std.testing.allocator.free(text);
866 try std.testing.expectEqualSlices(u8, "x86_64-linux-gnu", text);
867 }
868 {
869 const cross_target = try CrossTarget.parse(.{
870 .arch_os_abi = "arm-linux-musleabihf",
871 .cpu_features = "generic+v8a",
872 });
873 const target = cross_target.toTarget();
874
875 try std.testing.expect(target.os.tag == .linux);
876 try std.testing.expect(target.abi == .musleabihf);
877 try std.testing.expect(target.cpu.arch == .arm);
878 try std.testing.expect(target.cpu.model == &Target.arm.cpu.generic);
879 try std.testing.expect(Target.arm.featureSetHas(target.cpu.features, .v8a));
880
881 const text = try cross_target.zigTriple(std.testing.allocator);
882 defer std.testing.allocator.free(text);
883 try std.testing.expectEqualSlices(u8, "arm-linux-musleabihf", text);
884 }
885 {
886 const cross_target = try CrossTarget.parse(.{
887 .arch_os_abi = "aarch64-linux.3.10...4.4.1-gnu.2.27",
888 .cpu_features = "generic+v8a",
889 });
890 const target = cross_target.toTarget();
891
892 try std.testing.expect(target.cpu.arch == .aarch64);
893 try std.testing.expect(target.os.tag == .linux);
894 try std.testing.expect(target.os.version_range.linux.range.min.major == 3);
895 try std.testing.expect(target.os.version_range.linux.range.min.minor == 10);
896 try std.testing.expect(target.os.version_range.linux.range.min.patch == 0);
897 try std.testing.expect(target.os.version_range.linux.range.max.major == 4);
898 try std.testing.expect(target.os.version_range.linux.range.max.minor == 4);
899 try std.testing.expect(target.os.version_range.linux.range.max.patch == 1);
900 try std.testing.expect(target.os.version_range.linux.glibc.major == 2);
901 try std.testing.expect(target.os.version_range.linux.glibc.minor == 27);
902 try std.testing.expect(target.os.version_range.linux.glibc.patch == 0);
903 try std.testing.expect(target.abi == .gnu);
904
905 const text = try cross_target.zigTriple(std.testing.allocator);
906 defer std.testing.allocator.free(text);
907 try std.testing.expectEqualSlices(u8, "aarch64-linux.3.10...4.4.1-gnu.2.27", text);
908 }
909}
lib/std/zig/c_builtins.zig+1-1
...@@ -123,7 +123,7 @@ pub inline fn __builtin_roundf(val: f32) f32 {...@@ -123,7 +123,7 @@ pub inline fn __builtin_roundf(val: f32) f32 {
123}123}
124124
125pub inline fn __builtin_strlen(s: [*c]const u8) usize {125pub inline fn __builtin_strlen(s: [*c]const u8) usize {
126 return std.mem.lenZ(s);126 return std.mem.sliceTo(s, 0).len;
127}127}
128pub inline fn __builtin_strcmp(s1: [*c]const u8, s2: [*c]const u8) c_int {128pub inline fn __builtin_strcmp(s1: [*c]const u8, s2: [*c]const u8) c_int {
129 return @as(c_int, std.cstr.cmp(s1, s2));129 return @as(c_int, std.cstr.cmp(s1, s2));
lib/std/zig/cross_target.zig deleted-909
...@@ -1,909 +0,0 @@
1const std = @import("../std.zig");
2const builtin = @import("builtin");
3const assert = std.debug.assert;
4const Target = std.Target;
5const mem = std.mem;
6
7/// Contains all the same data as `Target`, additionally introducing the concept of "the native target".
8/// The purpose of this abstraction is to provide meaningful and unsurprising defaults.
9/// This struct does reference any resources and it is copyable.
10pub const CrossTarget = struct {
11 /// `null` means native.
12 cpu_arch: ?Target.Cpu.Arch = null,
13
14 cpu_model: CpuModel = CpuModel.determined_by_cpu_arch,
15
16 /// Sparse set of CPU features to add to the set from `cpu_model`.
17 cpu_features_add: Target.Cpu.Feature.Set = Target.Cpu.Feature.Set.empty,
18
19 /// Sparse set of CPU features to remove from the set from `cpu_model`.
20 cpu_features_sub: Target.Cpu.Feature.Set = Target.Cpu.Feature.Set.empty,
21
22 /// `null` means native.
23 os_tag: ?Target.Os.Tag = null,
24
25 /// `null` means the default version range for `os_tag`. If `os_tag` is `null` (native)
26 /// then `null` for this field means native.
27 os_version_min: ?OsVersion = null,
28
29 /// When cross compiling, `null` means default (latest known OS version).
30 /// When `os_tag` is native, `null` means equal to the native OS version.
31 os_version_max: ?OsVersion = null,
32
33 /// `null` means default when cross compiling, or native when os_tag is native.
34 /// If `isGnuLibC()` is `false`, this must be `null` and is ignored.
35 glibc_version: ?SemVer = null,
36
37 /// `null` means the native C ABI, if `os_tag` is native, otherwise it means the default C ABI.
38 abi: ?Target.Abi = null,
39
40 /// When `os_tag` is `null`, then `null` means native. Otherwise it means the standard path
41 /// based on the `os_tag`.
42 dynamic_linker: DynamicLinker = DynamicLinker{},
43
44 pub const CpuModel = union(enum) {
45 /// Always native
46 native,
47
48 /// Always baseline
49 baseline,
50
51 /// If CPU Architecture is native, then the CPU model will be native. Otherwise,
52 /// it will be baseline.
53 determined_by_cpu_arch,
54
55 explicit: *const Target.Cpu.Model,
56 };
57
58 pub const OsVersion = union(enum) {
59 none: void,
60 semver: SemVer,
61 windows: Target.Os.WindowsVersion,
62 };
63
64 pub const SemVer = std.builtin.Version;
65
66 pub const DynamicLinker = Target.DynamicLinker;
67
68 pub fn fromTarget(target: Target) CrossTarget {
69 var result: CrossTarget = .{
70 .cpu_arch = target.cpu.arch,
71 .cpu_model = .{ .explicit = target.cpu.model },
72 .os_tag = target.os.tag,
73 .os_version_min = undefined,
74 .os_version_max = undefined,
75 .abi = target.abi,
76 .glibc_version = if (target.isGnuLibC())
77 target.os.version_range.linux.glibc
78 else
79 null,
80 };
81 result.updateOsVersionRange(target.os);
82
83 const all_features = target.cpu.arch.allFeaturesList();
84 var cpu_model_set = target.cpu.model.features;
85 cpu_model_set.populateDependencies(all_features);
86 {
87 // The "add" set is the full set with the CPU Model set removed.
88 const add_set = &result.cpu_features_add;
89 add_set.* = target.cpu.features;
90 add_set.removeFeatureSet(cpu_model_set);
91 }
92 {
93 // The "sub" set is the features that are on in CPU Model set and off in the full set.
94 const sub_set = &result.cpu_features_sub;
95 sub_set.* = cpu_model_set;
96 sub_set.removeFeatureSet(target.cpu.features);
97 }
98 return result;
99 }
100
101 fn updateOsVersionRange(self: *CrossTarget, os: Target.Os) void {
102 switch (os.tag) {
103 .freestanding,
104 .ananas,
105 .cloudabi,
106 .fuchsia,
107 .kfreebsd,
108 .lv2,
109 .solaris,
110 .zos,
111 .haiku,
112 .minix,
113 .rtems,
114 .nacl,
115 .aix,
116 .cuda,
117 .nvcl,
118 .amdhsa,
119 .ps4,
120 .elfiamcu,
121 .mesa3d,
122 .contiki,
123 .amdpal,
124 .hermit,
125 .hurd,
126 .wasi,
127 .emscripten,
128 .uefi,
129 .opencl,
130 .glsl450,
131 .vulkan,
132 .plan9,
133 .other,
134 => {
135 self.os_version_min = .{ .none = {} };
136 self.os_version_max = .{ .none = {} };
137 },
138
139 .freebsd,
140 .macos,
141 .ios,
142 .tvos,
143 .watchos,
144 .netbsd,
145 .openbsd,
146 .dragonfly,
147 => {
148 self.os_version_min = .{ .semver = os.version_range.semver.min };
149 self.os_version_max = .{ .semver = os.version_range.semver.max };
150 },
151
152 .linux => {
153 self.os_version_min = .{ .semver = os.version_range.linux.range.min };
154 self.os_version_max = .{ .semver = os.version_range.linux.range.max };
155 },
156
157 .windows => {
158 self.os_version_min = .{ .windows = os.version_range.windows.min };
159 self.os_version_max = .{ .windows = os.version_range.windows.max };
160 },
161 }
162 }
163
164 /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.
165 pub fn toTarget(self: CrossTarget) Target {
166 return .{
167 .cpu = self.getCpu(),
168 .os = self.getOs(),
169 .abi = self.getAbi(),
170 };
171 }
172
173 pub const ParseOptions = struct {
174 /// This is sometimes called a "triple". It looks roughly like this:
175 /// riscv64-linux-musl
176 /// The fields are, respectively:
177 /// * CPU Architecture
178 /// * Operating System (and optional version range)
179 /// * C ABI (optional, with optional glibc version)
180 /// The string "native" can be used for CPU architecture as well as Operating System.
181 /// If the CPU Architecture is specified as "native", then the Operating System and C ABI may be omitted.
182 arch_os_abi: []const u8 = "native",
183
184 /// Looks like "name+a+b-c-d+e", where "name" is a CPU Model name, "a", "b", and "e"
185 /// are examples of CPU features to add to the set, and "c" and "d" are examples of CPU features
186 /// to remove from the set.
187 /// The following special strings are recognized for CPU Model name:
188 /// * "baseline" - The "default" set of CPU features for cross-compiling. A conservative set
189 /// of features that is expected to be supported on most available hardware.
190 /// * "native" - The native CPU model is to be detected when compiling.
191 /// If this field is not provided (`null`), then the value will depend on the
192 /// parsed CPU Architecture. If native, then this will be "native". Otherwise, it will be "baseline".
193 cpu_features: ?[]const u8 = null,
194
195 /// Absolute path to dynamic linker, to override the default, which is either a natively
196 /// detected path, or a standard path.
197 dynamic_linker: ?[]const u8 = null,
198
199 /// If this is provided, the function will populate some information about parsing failures,
200 /// so that user-friendly error messages can be delivered.
201 diagnostics: ?*Diagnostics = null,
202
203 pub const Diagnostics = struct {
204 /// If the architecture was determined, this will be populated.
205 arch: ?Target.Cpu.Arch = null,
206
207 /// If the OS name was determined, this will be populated.
208 os_name: ?[]const u8 = null,
209
210 /// If the OS tag was determined, this will be populated.
211 os_tag: ?Target.Os.Tag = null,
212
213 /// If the ABI was determined, this will be populated.
214 abi: ?Target.Abi = null,
215
216 /// If the CPU name was determined, this will be populated.
217 cpu_name: ?[]const u8 = null,
218
219 /// If error.UnknownCpuFeature is returned, this will be populated.
220 unknown_feature_name: ?[]const u8 = null,
221 };
222 };
223
224 pub fn parse(args: ParseOptions) !CrossTarget {
225 var dummy_diags: ParseOptions.Diagnostics = undefined;
226 const diags = args.diagnostics orelse &dummy_diags;
227
228 var result: CrossTarget = .{
229 .dynamic_linker = DynamicLinker.init(args.dynamic_linker),
230 };
231
232 var it = mem.split(u8, args.arch_os_abi, "-");
233 const arch_name = it.next().?;
234 const arch_is_native = mem.eql(u8, arch_name, "native");
235 if (!arch_is_native) {
236 result.cpu_arch = std.meta.stringToEnum(Target.Cpu.Arch, arch_name) orelse
237 return error.UnknownArchitecture;
238 }
239 const arch = result.getCpuArch();
240 diags.arch = arch;
241
242 if (it.next()) |os_text| {
243 try parseOs(&result, diags, os_text);
244 } else if (!arch_is_native) {
245 return error.MissingOperatingSystem;
246 }
247
248 const opt_abi_text = it.next();
249 if (opt_abi_text) |abi_text| {
250 var abi_it = mem.split(u8, abi_text, ".");
251 const abi = std.meta.stringToEnum(Target.Abi, abi_it.next().?) orelse
252 return error.UnknownApplicationBinaryInterface;
253 result.abi = abi;
254 diags.abi = abi;
255
256 const abi_ver_text = abi_it.rest();
257 if (abi_it.next() != null) {
258 if (result.isGnuLibC()) {
259 result.glibc_version = SemVer.parse(abi_ver_text) catch |err| switch (err) {
260 error.Overflow => return error.InvalidAbiVersion,
261 error.InvalidCharacter => return error.InvalidAbiVersion,
262 error.InvalidVersion => return error.InvalidAbiVersion,
263 };
264 } else {
265 return error.InvalidAbiVersion;
266 }
267 }
268 }
269
270 if (it.next() != null) return error.UnexpectedExtraField;
271
272 if (args.cpu_features) |cpu_features| {
273 const all_features = arch.allFeaturesList();
274 var index: usize = 0;
275 while (index < cpu_features.len and
276 cpu_features[index] != '+' and
277 cpu_features[index] != '-')
278 {
279 index += 1;
280 }
281 const cpu_name = cpu_features[0..index];
282 diags.cpu_name = cpu_name;
283
284 const add_set = &result.cpu_features_add;
285 const sub_set = &result.cpu_features_sub;
286 if (mem.eql(u8, cpu_name, "native")) {
287 result.cpu_model = .native;
288 } else if (mem.eql(u8, cpu_name, "baseline")) {
289 result.cpu_model = .baseline;
290 } else {
291 result.cpu_model = .{ .explicit = try arch.parseCpuModel(cpu_name) };
292 }
293
294 while (index < cpu_features.len) {
295 const op = cpu_features[index];
296 const set = switch (op) {
297 '+' => add_set,
298 '-' => sub_set,
299 else => unreachable,
300 };
301 index += 1;
302 const start = index;
303 while (index < cpu_features.len and
304 cpu_features[index] != '+' and
305 cpu_features[index] != '-')
306 {
307 index += 1;
308 }
309 const feature_name = cpu_features[start..index];
310 for (all_features) |feature, feat_index_usize| {
311 const feat_index = @intCast(Target.Cpu.Feature.Set.Index, feat_index_usize);
312 if (mem.eql(u8, feature_name, feature.name)) {
313 set.addFeature(feat_index);
314 break;
315 }
316 } else {
317 diags.unknown_feature_name = feature_name;
318 return error.UnknownCpuFeature;
319 }
320 }
321 }
322
323 return result;
324 }
325
326 /// Similar to `parse` except instead of fully parsing, it only determines the CPU
327 /// architecture and returns it if it can be determined, and returns `null` otherwise.
328 /// This is intended to be used if the API user of CrossTarget needs to learn the
329 /// target CPU architecture in order to fully populate `ParseOptions`.
330 pub fn parseCpuArch(args: ParseOptions) ?Target.Cpu.Arch {
331 var it = mem.split(u8, args.arch_os_abi, "-");
332 const arch_name = it.next().?;
333 const arch_is_native = mem.eql(u8, arch_name, "native");
334 if (arch_is_native) {
335 return builtin.cpu.arch;
336 } else {
337 return std.meta.stringToEnum(Target.Cpu.Arch, arch_name);
338 }
339 }
340
341 /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.
342 pub fn getCpu(self: CrossTarget) Target.Cpu {
343 switch (self.cpu_model) {
344 .native => {
345 // This works when doing `zig build` because Zig generates a build executable using
346 // native CPU model & features. However this will not be accurate otherwise, and
347 // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`.
348 return builtin.cpu;
349 },
350 .baseline => {
351 var adjusted_baseline = Target.Cpu.baseline(self.getCpuArch());
352 self.updateCpuFeatures(&adjusted_baseline.features);
353 return adjusted_baseline;
354 },
355 .determined_by_cpu_arch => if (self.cpu_arch == null) {
356 // This works when doing `zig build` because Zig generates a build executable using
357 // native CPU model & features. However this will not be accurate otherwise, and
358 // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`.
359 return builtin.cpu;
360 } else {
361 var adjusted_baseline = Target.Cpu.baseline(self.getCpuArch());
362 self.updateCpuFeatures(&adjusted_baseline.features);
363 return adjusted_baseline;
364 },
365 .explicit => |model| {
366 var adjusted_model = model.toCpu(self.getCpuArch());
367 self.updateCpuFeatures(&adjusted_model.features);
368 return adjusted_model;
369 },
370 }
371 }
372
373 pub fn getCpuArch(self: CrossTarget) Target.Cpu.Arch {
374 return self.cpu_arch orelse builtin.cpu.arch;
375 }
376
377 pub fn getCpuModel(self: CrossTarget) *const Target.Cpu.Model {
378 return switch (self.cpu_model) {
379 .explicit => |cpu_model| cpu_model,
380 else => self.getCpu().model,
381 };
382 }
383
384 pub fn getCpuFeatures(self: CrossTarget) Target.Cpu.Feature.Set {
385 return self.getCpu().features;
386 }
387
388 /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.
389 pub fn getOs(self: CrossTarget) Target.Os {
390 // `builtin.os` works when doing `zig build` because Zig generates a build executable using
391 // native OS version range. However this will not be accurate otherwise, and
392 // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`.
393 var adjusted_os = if (self.os_tag) |os_tag| os_tag.defaultVersionRange(self.getCpuArch()) else builtin.os;
394
395 if (self.os_version_min) |min| switch (min) {
396 .none => {},
397 .semver => |semver| switch (self.getOsTag()) {
398 .linux => adjusted_os.version_range.linux.range.min = semver,
399 else => adjusted_os.version_range.semver.min = semver,
400 },
401 .windows => |win_ver| adjusted_os.version_range.windows.min = win_ver,
402 };
403
404 if (self.os_version_max) |max| switch (max) {
405 .none => {},
406 .semver => |semver| switch (self.getOsTag()) {
407 .linux => adjusted_os.version_range.linux.range.max = semver,
408 else => adjusted_os.version_range.semver.max = semver,
409 },
410 .windows => |win_ver| adjusted_os.version_range.windows.max = win_ver,
411 };
412
413 if (self.glibc_version) |glibc| {
414 assert(self.isGnuLibC());
415 adjusted_os.version_range.linux.glibc = glibc;
416 }
417
418 return adjusted_os;
419 }
420
421 pub fn getOsTag(self: CrossTarget) Target.Os.Tag {
422 return self.os_tag orelse builtin.os.tag;
423 }
424
425 /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.
426 pub fn getOsVersionMin(self: CrossTarget) OsVersion {
427 if (self.os_version_min) |version_min| return version_min;
428 var tmp: CrossTarget = undefined;
429 tmp.updateOsVersionRange(self.getOs());
430 return tmp.os_version_min.?;
431 }
432
433 /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.
434 pub fn getOsVersionMax(self: CrossTarget) OsVersion {
435 if (self.os_version_max) |version_max| return version_max;
436 var tmp: CrossTarget = undefined;
437 tmp.updateOsVersionRange(self.getOs());
438 return tmp.os_version_max.?;
439 }
440
441 /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.
442 pub fn getAbi(self: CrossTarget) Target.Abi {
443 if (self.abi) |abi| return abi;
444
445 if (self.os_tag == null) {
446 // This works when doing `zig build` because Zig generates a build executable using
447 // native CPU model & features. However this will not be accurate otherwise, and
448 // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`.
449 return builtin.abi;
450 }
451
452 return Target.Abi.default(self.getCpuArch(), self.getOs());
453 }
454
455 pub fn isFreeBSD(self: CrossTarget) bool {
456 return self.getOsTag() == .freebsd;
457 }
458
459 pub fn isDarwin(self: CrossTarget) bool {
460 return self.getOsTag().isDarwin();
461 }
462
463 pub fn isNetBSD(self: CrossTarget) bool {
464 return self.getOsTag() == .netbsd;
465 }
466
467 pub fn isOpenBSD(self: CrossTarget) bool {
468 return self.getOsTag() == .openbsd;
469 }
470
471 pub fn isUefi(self: CrossTarget) bool {
472 return self.getOsTag() == .uefi;
473 }
474
475 pub fn isDragonFlyBSD(self: CrossTarget) bool {
476 return self.getOsTag() == .dragonfly;
477 }
478
479 pub fn isLinux(self: CrossTarget) bool {
480 return self.getOsTag() == .linux;
481 }
482
483 pub fn isWindows(self: CrossTarget) bool {
484 return self.getOsTag() == .windows;
485 }
486
487 pub fn exeFileExt(self: CrossTarget) [:0]const u8 {
488 return Target.exeFileExtSimple(self.getCpuArch(), self.getOsTag());
489 }
490
491 pub fn staticLibSuffix(self: CrossTarget) [:0]const u8 {
492 return Target.staticLibSuffix_os_abi(self.getOsTag(), self.getAbi());
493 }
494
495 pub fn dynamicLibSuffix(self: CrossTarget) [:0]const u8 {
496 return self.getOsTag().dynamicLibSuffix();
497 }
498
499 pub fn libPrefix(self: CrossTarget) [:0]const u8 {
500 return Target.libPrefix_os_abi(self.getOsTag(), self.getAbi());
501 }
502
503 pub fn isNativeCpu(self: CrossTarget) bool {
504 return self.cpu_arch == null and
505 (self.cpu_model == .native or self.cpu_model == .determined_by_cpu_arch) and
506 self.cpu_features_sub.isEmpty() and self.cpu_features_add.isEmpty();
507 }
508
509 pub fn isNativeOs(self: CrossTarget) bool {
510 return self.os_tag == null and self.os_version_min == null and self.os_version_max == null and
511 self.dynamic_linker.get() == null and self.glibc_version == null;
512 }
513
514 pub fn isNativeAbi(self: CrossTarget) bool {
515 return self.os_tag == null and self.abi == null;
516 }
517
518 pub fn isNative(self: CrossTarget) bool {
519 return self.isNativeCpu() and self.isNativeOs() and self.isNativeAbi();
520 }
521
522 pub fn zigTriple(self: CrossTarget, allocator: *mem.Allocator) error{OutOfMemory}![]u8 {
523 if (self.isNative()) {
524 return allocator.dupe(u8, "native");
525 }
526
527 const arch_name = if (self.cpu_arch) |arch| @tagName(arch) else "native";
528 const os_name = if (self.os_tag) |os_tag| @tagName(os_tag) else "native";
529
530 var result = std.ArrayList(u8).init(allocator);
531 defer result.deinit();
532
533 try result.writer().print("{s}-{s}", .{ arch_name, os_name });
534
535 // The zig target syntax does not allow specifying a max os version with no min, so
536 // if either are present, we need the min.
537 if (self.os_version_min != null or self.os_version_max != null) {
538 switch (self.getOsVersionMin()) {
539 .none => {},
540 .semver => |v| try result.writer().print(".{}", .{v}),
541 .windows => |v| try result.writer().print("{s}", .{v}),
542 }
543 }
544 if (self.os_version_max) |max| {
545 switch (max) {
546 .none => {},
547 .semver => |v| try result.writer().print("...{}", .{v}),
548 .windows => |v| try result.writer().print("..{s}", .{v}),
549 }
550 }
551
552 if (self.glibc_version) |v| {
553 try result.writer().print("-{s}.{}", .{ @tagName(self.getAbi()), v });
554 } else if (self.abi) |abi| {
555 try result.writer().print("-{s}", .{@tagName(abi)});
556 }
557
558 return result.toOwnedSlice();
559 }
560
561 pub fn allocDescription(self: CrossTarget, allocator: *mem.Allocator) ![]u8 {
562 // TODO is there anything else worthy of the description that is not
563 // already captured in the triple?
564 return self.zigTriple(allocator);
565 }
566
567 pub fn linuxTriple(self: CrossTarget, allocator: *mem.Allocator) ![]u8 {
568 return Target.linuxTripleSimple(allocator, self.getCpuArch(), self.getOsTag(), self.getAbi());
569 }
570
571 pub fn wantSharedLibSymLinks(self: CrossTarget) bool {
572 return self.getOsTag() != .windows;
573 }
574
575 pub const VcpkgLinkage = std.builtin.LinkMode;
576
577 /// Returned slice must be freed by the caller.
578 pub fn vcpkgTriplet(self: CrossTarget, allocator: *mem.Allocator, linkage: VcpkgLinkage) ![]u8 {
579 const arch = switch (self.getCpuArch()) {
580 .i386 => "x86",
581 .x86_64 => "x64",
582
583 .arm,
584 .armeb,
585 .thumb,
586 .thumbeb,
587 .aarch64_32,
588 => "arm",
589
590 .aarch64,
591 .aarch64_be,
592 => "arm64",
593
594 else => return error.UnsupportedVcpkgArchitecture,
595 };
596
597 const os = switch (self.getOsTag()) {
598 .windows => "windows",
599 .linux => "linux",
600 .macos => "macos",
601 else => return error.UnsupportedVcpkgOperatingSystem,
602 };
603
604 const static_suffix = switch (linkage) {
605 .Static => "-static",
606 .Dynamic => "",
607 };
608
609 return std.fmt.allocPrint(allocator, "{s}-{s}{s}", .{ arch, os, static_suffix });
610 }
611
612 pub const Executor = union(enum) {
613 native,
614 qemu: []const u8,
615 wine: []const u8,
616 wasmtime: []const u8,
617 darling: []const u8,
618 unavailable,
619 };
620
621 /// Note that even a `CrossTarget` which returns `false` for `isNative` could still be natively executed.
622 /// For example `-target arm-native` running on an aarch64 host.
623 pub fn getExternalExecutor(self: CrossTarget) Executor {
624 const cpu_arch = self.getCpuArch();
625 const os_tag = self.getOsTag();
626 const os_match = os_tag == builtin.os.tag;
627
628 // If the OS and CPU arch match, the binary can be considered native.
629 // TODO additionally match the CPU features. This `getExternalExecutor` function should
630 // be moved to std.Target and match any chosen target against the native target.
631 if (os_match and cpu_arch == builtin.cpu.arch) {
632 // However, we also need to verify that the dynamic linker path is valid.
633 if (self.os_tag == null) {
634 return .native;
635 }
636 // TODO here we call toTarget, a deprecated function, because of the above TODO about moving
637 // this code to std.Target.
638 const opt_dl = self.dynamic_linker.get() orelse self.toTarget().standardDynamicLinkerPath().get();
639 if (opt_dl) |dl| blk: {
640 std.fs.cwd().access(dl, .{}) catch break :blk;
641 return .native;
642 }
643 }
644
645 // If the OS matches, we can use QEMU to emulate a foreign architecture.
646 if (os_match) {
647 return switch (cpu_arch) {
648 .aarch64 => Executor{ .qemu = "qemu-aarch64" },
649 .aarch64_be => Executor{ .qemu = "qemu-aarch64_be" },
650 .arm => Executor{ .qemu = "qemu-arm" },
651 .armeb => Executor{ .qemu = "qemu-armeb" },
652 .i386 => Executor{ .qemu = "qemu-i386" },
653 .mips => Executor{ .qemu = "qemu-mips" },
654 .mipsel => Executor{ .qemu = "qemu-mipsel" },
655 .mips64 => Executor{ .qemu = "qemu-mips64" },
656 .mips64el => Executor{ .qemu = "qemu-mips64el" },
657 .powerpc => Executor{ .qemu = "qemu-ppc" },
658 .powerpc64 => Executor{ .qemu = "qemu-ppc64" },
659 .powerpc64le => Executor{ .qemu = "qemu-ppc64le" },
660 .riscv32 => Executor{ .qemu = "qemu-riscv32" },
661 .riscv64 => Executor{ .qemu = "qemu-riscv64" },
662 .s390x => Executor{ .qemu = "qemu-s390x" },
663 .sparc => Executor{ .qemu = "qemu-sparc" },
664 .x86_64 => Executor{ .qemu = "qemu-x86_64" },
665 else => return .unavailable,
666 };
667 }
668
669 switch (os_tag) {
670 .windows => switch (cpu_arch.ptrBitWidth()) {
671 32 => return Executor{ .wine = "wine" },
672 64 => return Executor{ .wine = "wine64" },
673 else => return .unavailable,
674 },
675 .wasi => switch (cpu_arch.ptrBitWidth()) {
676 32 => return Executor{ .wasmtime = "wasmtime" },
677 else => return .unavailable,
678 },
679 .macos => {
680 // TODO loosen this check once upstream adds QEMU-based emulation
681 // layer for non-host architectures:
682 // https://github.com/darlinghq/darling/issues/863
683 if (cpu_arch != builtin.cpu.arch) {
684 return .unavailable;
685 }
686 return Executor{ .darling = "darling" };
687 },
688 else => return .unavailable,
689 }
690 }
691
692 pub fn isGnuLibC(self: CrossTarget) bool {
693 return Target.isGnuLibC_os_tag_abi(self.getOsTag(), self.getAbi());
694 }
695
696 pub fn setGnuLibCVersion(self: *CrossTarget, major: u32, minor: u32, patch: u32) void {
697 assert(self.isGnuLibC());
698 self.glibc_version = SemVer{ .major = major, .minor = minor, .patch = patch };
699 }
700
701 pub fn getObjectFormat(self: CrossTarget) Target.ObjectFormat {
702 return Target.getObjectFormatSimple(self.getOsTag(), self.getCpuArch());
703 }
704
705 pub fn updateCpuFeatures(self: CrossTarget, set: *Target.Cpu.Feature.Set) void {
706 set.removeFeatureSet(self.cpu_features_sub);
707 set.addFeatureSet(self.cpu_features_add);
708 set.populateDependencies(self.getCpuArch().allFeaturesList());
709 set.removeFeatureSet(self.cpu_features_sub);
710 }
711
712 fn parseOs(result: *CrossTarget, diags: *ParseOptions.Diagnostics, text: []const u8) !void {
713 var it = mem.split(u8, text, ".");
714 const os_name = it.next().?;
715 diags.os_name = os_name;
716 const os_is_native = mem.eql(u8, os_name, "native");
717 if (!os_is_native) {
718 result.os_tag = std.meta.stringToEnum(Target.Os.Tag, os_name) orelse
719 return error.UnknownOperatingSystem;
720 }
721 const tag = result.getOsTag();
722 diags.os_tag = tag;
723
724 const version_text = it.rest();
725 if (it.next() == null) return;
726
727 switch (tag) {
728 .freestanding,
729 .ananas,
730 .cloudabi,
731 .fuchsia,
732 .kfreebsd,
733 .lv2,
734 .solaris,
735 .zos,
736 .haiku,
737 .minix,
738 .rtems,
739 .nacl,
740 .aix,
741 .cuda,
742 .nvcl,
743 .amdhsa,
744 .ps4,
745 .elfiamcu,
746 .mesa3d,
747 .contiki,
748 .amdpal,
749 .hermit,
750 .hurd,
751 .wasi,
752 .emscripten,
753 .uefi,
754 .opencl,
755 .glsl450,
756 .vulkan,
757 .plan9,
758 .other,
759 => return error.InvalidOperatingSystemVersion,
760
761 .freebsd,
762 .macos,
763 .ios,
764 .tvos,
765 .watchos,
766 .netbsd,
767 .openbsd,
768 .linux,
769 .dragonfly,
770 => {
771 var range_it = mem.split(u8, version_text, "...");
772
773 const min_text = range_it.next().?;
774 const min_ver = SemVer.parse(min_text) catch |err| switch (err) {
775 error.Overflow => return error.InvalidOperatingSystemVersion,
776 error.InvalidCharacter => return error.InvalidOperatingSystemVersion,
777 error.InvalidVersion => return error.InvalidOperatingSystemVersion,
778 };
779 result.os_version_min = .{ .semver = min_ver };
780
781 const max_text = range_it.next() orelse return;
782 const max_ver = SemVer.parse(max_text) catch |err| switch (err) {
783 error.Overflow => return error.InvalidOperatingSystemVersion,
784 error.InvalidCharacter => return error.InvalidOperatingSystemVersion,
785 error.InvalidVersion => return error.InvalidOperatingSystemVersion,
786 };
787 result.os_version_max = .{ .semver = max_ver };
788 },
789
790 .windows => {
791 var range_it = mem.split(u8, version_text, "...");
792
793 const min_text = range_it.next().?;
794 const min_ver = std.meta.stringToEnum(Target.Os.WindowsVersion, min_text) orelse
795 return error.InvalidOperatingSystemVersion;
796 result.os_version_min = .{ .windows = min_ver };
797
798 const max_text = range_it.next() orelse return;
799 const max_ver = std.meta.stringToEnum(Target.Os.WindowsVersion, max_text) orelse
800 return error.InvalidOperatingSystemVersion;
801 result.os_version_max = .{ .windows = max_ver };
802 },
803 }
804 }
805};
806
807test "CrossTarget.parse" {
808 if (builtin.target.isGnuLibC()) {
809 var cross_target = try CrossTarget.parse(.{});
810 cross_target.setGnuLibCVersion(2, 1, 1);
811
812 const text = try cross_target.zigTriple(std.testing.allocator);
813 defer std.testing.allocator.free(text);
814
815 var buf: [256]u8 = undefined;
816 const triple = std.fmt.bufPrint(
817 buf[0..],
818 "native-native-{s}.2.1.1",
819 .{@tagName(builtin.abi)},
820 ) catch unreachable;
821
822 try std.testing.expectEqualSlices(u8, triple, text);
823 }
824 {
825 const cross_target = try CrossTarget.parse(.{
826 .arch_os_abi = "aarch64-linux",
827 .cpu_features = "native",
828 });
829
830 try std.testing.expect(cross_target.cpu_arch.? == .aarch64);
831 try std.testing.expect(cross_target.cpu_model == .native);
832 }
833 {
834 const cross_target = try CrossTarget.parse(.{ .arch_os_abi = "native" });
835
836 try std.testing.expect(cross_target.cpu_arch == null);
837 try std.testing.expect(cross_target.isNative());
838
839 const text = try cross_target.zigTriple(std.testing.allocator);
840 defer std.testing.allocator.free(text);
841 try std.testing.expectEqualSlices(u8, "native", text);
842 }
843 {
844 const cross_target = try CrossTarget.parse(.{
845 .arch_os_abi = "x86_64-linux-gnu",
846 .cpu_features = "x86_64-sse-sse2-avx-cx8",
847 });
848 const target = cross_target.toTarget();
849
850 try std.testing.expect(target.os.tag == .linux);
851 try std.testing.expect(target.abi == .gnu);
852 try std.testing.expect(target.cpu.arch == .x86_64);
853 try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .sse));
854 try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .avx));
855 try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .cx8));
856 try std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .cmov));
857 try std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .fxsr));
858
859 try std.testing.expect(Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx, .cmov }));
860 try std.testing.expect(!Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx }));
861 try std.testing.expect(Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87 }));
862 try std.testing.expect(!Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87, .sse }));
863
864 const text = try cross_target.zigTriple(std.testing.allocator);
865 defer std.testing.allocator.free(text);
866 try std.testing.expectEqualSlices(u8, "x86_64-linux-gnu", text);
867 }
868 {
869 const cross_target = try CrossTarget.parse(.{
870 .arch_os_abi = "arm-linux-musleabihf",
871 .cpu_features = "generic+v8a",
872 });
873 const target = cross_target.toTarget();
874
875 try std.testing.expect(target.os.tag == .linux);
876 try std.testing.expect(target.abi == .musleabihf);
877 try std.testing.expect(target.cpu.arch == .arm);
878 try std.testing.expect(target.cpu.model == &Target.arm.cpu.generic);
879 try std.testing.expect(Target.arm.featureSetHas(target.cpu.features, .v8a));
880
881 const text = try cross_target.zigTriple(std.testing.allocator);
882 defer std.testing.allocator.free(text);
883 try std.testing.expectEqualSlices(u8, "arm-linux-musleabihf", text);
884 }
885 {
886 const cross_target = try CrossTarget.parse(.{
887 .arch_os_abi = "aarch64-linux.3.10...4.4.1-gnu.2.27",
888 .cpu_features = "generic+v8a",
889 });
890 const target = cross_target.toTarget();
891
892 try std.testing.expect(target.cpu.arch == .aarch64);
893 try std.testing.expect(target.os.tag == .linux);
894 try std.testing.expect(target.os.version_range.linux.range.min.major == 3);
895 try std.testing.expect(target.os.version_range.linux.range.min.minor == 10);
896 try std.testing.expect(target.os.version_range.linux.range.min.patch == 0);
897 try std.testing.expect(target.os.version_range.linux.range.max.major == 4);
898 try std.testing.expect(target.os.version_range.linux.range.max.minor == 4);
899 try std.testing.expect(target.os.version_range.linux.range.max.patch == 1);
900 try std.testing.expect(target.os.version_range.linux.glibc.major == 2);
901 try std.testing.expect(target.os.version_range.linux.glibc.minor == 27);
902 try std.testing.expect(target.os.version_range.linux.glibc.patch == 0);
903 try std.testing.expect(target.abi == .gnu);
904
905 const text = try cross_target.zigTriple(std.testing.allocator);
906 defer std.testing.allocator.free(text);
907 try std.testing.expectEqualSlices(u8, "aarch64-linux.3.10...4.4.1-gnu.2.27", text);
908 }
909}
lib/std/zig/perf_test.zig-1
...@@ -1,6 +1,5 @@...@@ -1,6 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const mem = std.mem;2const mem = std.mem;
3const warn = std.debug.warn;
4const Tokenizer = std.zig.Tokenizer;3const Tokenizer = std.zig.Tokenizer;
5const Parser = std.zig.Parser;4const Parser = std.zig.Parser;
6const io = std.io;5const io = std.io;
lib/std/zig/system.zig+8-8
...@@ -165,7 +165,7 @@ pub const NativePaths = struct {...@@ -165,7 +165,7 @@ pub const NativePaths = struct {
165 }165 }
166166
167 pub fn addIncludeDirFmt(self: *NativePaths, comptime fmt: []const u8, args: anytype) !void {167 pub fn addIncludeDirFmt(self: *NativePaths, comptime fmt: []const u8, args: anytype) !void {
168 const item = try std.fmt.allocPrint0(self.include_dirs.allocator, fmt, args);168 const item = try std.fmt.allocPrintZ(self.include_dirs.allocator, fmt, args);
169 errdefer self.include_dirs.allocator.free(item);169 errdefer self.include_dirs.allocator.free(item);
170 try self.include_dirs.append(item);170 try self.include_dirs.append(item);
171 }171 }
...@@ -175,7 +175,7 @@ pub const NativePaths = struct {...@@ -175,7 +175,7 @@ pub const NativePaths = struct {
175 }175 }
176176
177 pub fn addLibDirFmt(self: *NativePaths, comptime fmt: []const u8, args: anytype) !void {177 pub fn addLibDirFmt(self: *NativePaths, comptime fmt: []const u8, args: anytype) !void {
178 const item = try std.fmt.allocPrint0(self.lib_dirs.allocator, fmt, args);178 const item = try std.fmt.allocPrintZ(self.lib_dirs.allocator, fmt, args);
179 errdefer self.lib_dirs.allocator.free(item);179 errdefer self.lib_dirs.allocator.free(item);
180 try self.lib_dirs.append(item);180 try self.lib_dirs.append(item);
181 }181 }
...@@ -189,13 +189,13 @@ pub const NativePaths = struct {...@@ -189,13 +189,13 @@ pub const NativePaths = struct {
189 }189 }
190190
191 pub fn addFrameworkDirFmt(self: *NativePaths, comptime fmt: []const u8, args: anytype) !void {191 pub fn addFrameworkDirFmt(self: *NativePaths, comptime fmt: []const u8, args: anytype) !void {
192 const item = try std.fmt.allocPrint0(self.framework_dirs.allocator, fmt, args);192 const item = try std.fmt.allocPrintZ(self.framework_dirs.allocator, fmt, args);
193 errdefer self.framework_dirs.allocator.free(item);193 errdefer self.framework_dirs.allocator.free(item);
194 try self.framework_dirs.append(item);194 try self.framework_dirs.append(item);
195 }195 }
196196
197 pub fn addWarningFmt(self: *NativePaths, comptime fmt: []const u8, args: anytype) !void {197 pub fn addWarningFmt(self: *NativePaths, comptime fmt: []const u8, args: anytype) !void {
198 const item = try std.fmt.allocPrint0(self.warnings.allocator, fmt, args);198 const item = try std.fmt.allocPrintZ(self.warnings.allocator, fmt, args);
199 errdefer self.warnings.allocator.free(item);199 errdefer self.warnings.allocator.free(item);
200 try self.warnings.append(item);200 try self.warnings.append(item);
201 }201 }
...@@ -243,7 +243,7 @@ pub const NativeTargetInfo = struct {...@@ -243,7 +243,7 @@ pub const NativeTargetInfo = struct {
243 switch (builtin.target.os.tag) {243 switch (builtin.target.os.tag) {
244 .linux => {244 .linux => {
245 const uts = std.os.uname();245 const uts = std.os.uname();
246 const release = mem.spanZ(&uts.release);246 const release = mem.sliceTo(&uts.release, 0);
247 // The release field sometimes has a weird format,247 // The release field sometimes has a weird format,
248 // `Version.parse` will attempt to find some meaningful interpretation.248 // `Version.parse` will attempt to find some meaningful interpretation.
249 if (std.builtin.Version.parse(release)) |ver| {249 if (std.builtin.Version.parse(release)) |ver| {
...@@ -257,7 +257,7 @@ pub const NativeTargetInfo = struct {...@@ -257,7 +257,7 @@ pub const NativeTargetInfo = struct {
257 },257 },
258 .solaris => {258 .solaris => {
259 const uts = std.os.uname();259 const uts = std.os.uname();
260 const release = mem.spanZ(&uts.release);260 const release = mem.sliceTo(&uts.release, 0);
261 if (std.builtin.Version.parse(release)) |ver| {261 if (std.builtin.Version.parse(release)) |ver| {
262 os.version_range.semver.min = ver;262 os.version_range.semver.min = ver;
263 os.version_range.semver.max = ver;263 os.version_range.semver.max = ver;
...@@ -838,7 +838,7 @@ pub const NativeTargetInfo = struct {...@@ -838,7 +838,7 @@ pub const NativeTargetInfo = struct {
838 );838 );
839 const sh_name_off = elfInt(is_64, need_bswap, sh32.sh_name, sh64.sh_name);839 const sh_name_off = elfInt(is_64, need_bswap, sh32.sh_name, sh64.sh_name);
840 // TODO this pointer cast should not be necessary840 // TODO this pointer cast should not be necessary
841 const sh_name = mem.spanZ(std.meta.assumeSentinel(shstrtab[sh_name_off..].ptr, 0));841 const sh_name = mem.sliceTo(std.meta.assumeSentinel(shstrtab[sh_name_off..].ptr, 0), 0);
842 if (mem.eql(u8, sh_name, ".dynstr")) {842 if (mem.eql(u8, sh_name, ".dynstr")) {
843 break :find_dyn_str .{843 break :find_dyn_str .{
844 .offset = elfInt(is_64, need_bswap, sh32.sh_offset, sh64.sh_offset),844 .offset = elfInt(is_64, need_bswap, sh32.sh_offset, sh64.sh_offset),
...@@ -856,7 +856,7 @@ pub const NativeTargetInfo = struct {...@@ -856,7 +856,7 @@ pub const NativeTargetInfo = struct {
856 const rpoff_usize = std.math.cast(usize, rpoff) catch |err| switch (err) {856 const rpoff_usize = std.math.cast(usize, rpoff) catch |err| switch (err) {
857 error.Overflow => return error.InvalidElfFile,857 error.Overflow => return error.InvalidElfFile,
858 };858 };
859 const rpath_list = mem.spanZ(std.meta.assumeSentinel(strtab[rpoff_usize..].ptr, 0));859 const rpath_list = mem.sliceTo(std.meta.assumeSentinel(strtab[rpoff_usize..].ptr, 0), 0);
860 var it = mem.tokenize(u8, rpath_list, ":");860 var it = mem.tokenize(u8, rpath_list, ":");
861 while (it.next()) |rpath| {861 while (it.next()) |rpath| {
862 var dir = fs.cwd().openDir(rpath, .{}) catch |err| switch (err) {862 var dir = fs.cwd().openDir(rpath, .{}) catch |err| switch (err) {
lib/std/zig/tokenizer.zig+1-1
...@@ -334,7 +334,7 @@ pub const Tokenizer = struct {...@@ -334,7 +334,7 @@ pub const Tokenizer = struct {
334334
335 /// For debugging purposes335 /// For debugging purposes
336 pub fn dump(self: *Tokenizer, token: *const Token) void {336 pub fn dump(self: *Tokenizer, token: *const Token) void {
337 std.debug.warn("{s} \"{s}\"\n", .{ @tagName(token.tag), self.buffer[token.start..token.end] });337 std.debug.print("{s} \"{s}\"\n", .{ @tagName(token.tag), self.buffer[token.start..token.end] });
338 }338 }
339339
340 pub fn init(buffer: [:0]const u8) Tokenizer {340 pub fn init(buffer: [:0]const u8) Tokenizer {
src/AstGen.zig+6-26
...@@ -8399,7 +8399,7 @@ fn parseStrLit(...@@ -8399,7 +8399,7 @@ fn parseStrLit(
8399 const raw_string = bytes[offset..];8399 const raw_string = bytes[offset..];
8400 var buf_managed = buf.toManaged(astgen.gpa);8400 var buf_managed = buf.toManaged(astgen.gpa);
8401 const result = std.zig.string_literal.parseAppend(&buf_managed, raw_string);8401 const result = std.zig.string_literal.parseAppend(&buf_managed, raw_string);
8402 buf.* = buf_managed.toUnmanaged();8402 buf.* = buf_managed.moveToUnmanaged();
8403 switch (try result) {8403 switch (try result) {
8404 .success => return,8404 .success => return,
8405 .invalid_character => |bad_index| {8405 .invalid_character => |bad_index| {
...@@ -8472,11 +8472,7 @@ fn failNodeNotes(...@@ -8472,11 +8472,7 @@ fn failNodeNotes(
8472 @setCold(true);8472 @setCold(true);
8473 const string_bytes = &astgen.string_bytes;8473 const string_bytes = &astgen.string_bytes;
8474 const msg = @intCast(u32, string_bytes.items.len);8474 const msg = @intCast(u32, string_bytes.items.len);
8475 {8475 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);
8476 var managed = string_bytes.toManaged(astgen.gpa);
8477 defer string_bytes.* = managed.toUnmanaged();
8478 try managed.writer().print(format ++ "\x00", args);
8479 }
8480 const notes_index: u32 = if (notes.len != 0) blk: {8476 const notes_index: u32 = if (notes.len != 0) blk: {
8481 const notes_start = astgen.extra.items.len;8477 const notes_start = astgen.extra.items.len;
8482 try astgen.extra.ensureTotalCapacity(astgen.gpa, notes_start + 1 + notes.len);8478 try astgen.extra.ensureTotalCapacity(astgen.gpa, notes_start + 1 + notes.len);
...@@ -8513,11 +8509,7 @@ fn failTokNotes(...@@ -8513,11 +8509,7 @@ fn failTokNotes(
8513 @setCold(true);8509 @setCold(true);
8514 const string_bytes = &astgen.string_bytes;8510 const string_bytes = &astgen.string_bytes;
8515 const msg = @intCast(u32, string_bytes.items.len);8511 const msg = @intCast(u32, string_bytes.items.len);
8516 {8512 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);
8517 var managed = string_bytes.toManaged(astgen.gpa);
8518 defer string_bytes.* = managed.toUnmanaged();
8519 try managed.writer().print(format ++ "\x00", args);
8520 }
8521 const notes_index: u32 = if (notes.len != 0) blk: {8513 const notes_index: u32 = if (notes.len != 0) blk: {
8522 const notes_start = astgen.extra.items.len;8514 const notes_start = astgen.extra.items.len;
8523 try astgen.extra.ensureTotalCapacity(astgen.gpa, notes_start + 1 + notes.len);8515 try astgen.extra.ensureTotalCapacity(astgen.gpa, notes_start + 1 + notes.len);
...@@ -8546,11 +8538,7 @@ fn failOff(...@@ -8546,11 +8538,7 @@ fn failOff(
8546 @setCold(true);8538 @setCold(true);
8547 const string_bytes = &astgen.string_bytes;8539 const string_bytes = &astgen.string_bytes;
8548 const msg = @intCast(u32, string_bytes.items.len);8540 const msg = @intCast(u32, string_bytes.items.len);
8549 {8541 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);
8550 var managed = string_bytes.toManaged(astgen.gpa);
8551 defer string_bytes.* = managed.toUnmanaged();
8552 try managed.writer().print(format ++ "\x00", args);
8553 }
8554 try astgen.compile_errors.append(astgen.gpa, .{8542 try astgen.compile_errors.append(astgen.gpa, .{
8555 .msg = msg,8543 .msg = msg,
8556 .node = 0,8544 .node = 0,
...@@ -8570,11 +8558,7 @@ fn errNoteTok(...@@ -8570,11 +8558,7 @@ fn errNoteTok(
8570 @setCold(true);8558 @setCold(true);
8571 const string_bytes = &astgen.string_bytes;8559 const string_bytes = &astgen.string_bytes;
8572 const msg = @intCast(u32, string_bytes.items.len);8560 const msg = @intCast(u32, string_bytes.items.len);
8573 {8561 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);
8574 var managed = string_bytes.toManaged(astgen.gpa);
8575 defer string_bytes.* = managed.toUnmanaged();
8576 try managed.writer().print(format ++ "\x00", args);
8577 }
8578 return astgen.addExtra(Zir.Inst.CompileErrors.Item{8562 return astgen.addExtra(Zir.Inst.CompileErrors.Item{
8579 .msg = msg,8563 .msg = msg,
8580 .node = 0,8564 .node = 0,
...@@ -8593,11 +8577,7 @@ fn errNoteNode(...@@ -8593,11 +8577,7 @@ fn errNoteNode(
8593 @setCold(true);8577 @setCold(true);
8594 const string_bytes = &astgen.string_bytes;8578 const string_bytes = &astgen.string_bytes;
8595 const msg = @intCast(u32, string_bytes.items.len);8579 const msg = @intCast(u32, string_bytes.items.len);
8596 {8580 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);
8597 var managed = string_bytes.toManaged(astgen.gpa);
8598 defer string_bytes.* = managed.toUnmanaged();
8599 try managed.writer().print(format ++ "\x00", args);
8600 }
8601 return astgen.addExtra(Zir.Inst.CompileErrors.Item{8581 return astgen.addExtra(Zir.Inst.CompileErrors.Item{
8602 .msg = msg,8582 .msg = msg,
8603 .node = node,8583 .node = node,
src/Module.zig+9-9
...@@ -470,7 +470,7 @@ pub const Decl = struct {...@@ -470,7 +470,7 @@ pub const Decl = struct {
470 pub const DepsTable = std.AutoArrayHashMapUnmanaged(*Decl, void);470 pub const DepsTable = std.AutoArrayHashMapUnmanaged(*Decl, void);
471471
472 pub fn clearName(decl: *Decl, gpa: *Allocator) void {472 pub fn clearName(decl: *Decl, gpa: *Allocator) void {
473 gpa.free(mem.spanZ(decl.name));473 gpa.free(mem.sliceTo(decl.name, 0));
474 decl.name = undefined;474 decl.name = undefined;
475 }475 }
476476
...@@ -627,12 +627,12 @@ pub const Decl = struct {...@@ -627,12 +627,12 @@ pub const Decl = struct {
627 }627 }
628628
629 pub fn renderFullyQualifiedName(decl: Decl, writer: anytype) !void {629 pub fn renderFullyQualifiedName(decl: Decl, writer: anytype) !void {
630 const unqualified_name = mem.spanZ(decl.name);630 const unqualified_name = mem.sliceTo(decl.name, 0);
631 return decl.src_namespace.renderFullyQualifiedName(unqualified_name, writer);631 return decl.src_namespace.renderFullyQualifiedName(unqualified_name, writer);
632 }632 }
633633
634 pub fn renderFullyQualifiedDebugName(decl: Decl, writer: anytype) !void {634 pub fn renderFullyQualifiedDebugName(decl: Decl, writer: anytype) !void {
635 const unqualified_name = mem.spanZ(decl.name);635 const unqualified_name = mem.sliceTo(decl.name, 0);
636 return decl.src_namespace.renderFullyQualifiedDebugName(unqualified_name, writer);636 return decl.src_namespace.renderFullyQualifiedDebugName(unqualified_name, writer);
637 }637 }
638638
...@@ -737,7 +737,7 @@ pub const Decl = struct {...@@ -737,7 +737,7 @@ pub const Decl = struct {
737 decl.scope.sub_file_path,737 decl.scope.sub_file_path,
738 loc.line + 1,738 loc.line + 1,
739 loc.column + 1,739 loc.column + 1,
740 mem.spanZ(decl.name),740 mem.sliceTo(decl.name, 0),
741 @tagName(decl.analysis),741 @tagName(decl.analysis),
742 });742 });
743 if (decl.has_tv) {743 if (decl.has_tv) {
...@@ -1342,7 +1342,7 @@ pub const Namespace = struct {...@@ -1342,7 +1342,7 @@ pub const Namespace = struct {
1342 ) @TypeOf(writer).Error!void {1342 ) @TypeOf(writer).Error!void {
1343 if (ns.parent) |parent| {1343 if (ns.parent) |parent| {
1344 const decl = ns.getDecl();1344 const decl = ns.getDecl();
1345 try parent.renderFullyQualifiedName(mem.spanZ(decl.name), writer);1345 try parent.renderFullyQualifiedName(mem.sliceTo(decl.name, 0), writer);
1346 } else {1346 } else {
1347 try ns.file_scope.renderFullyQualifiedName(writer);1347 try ns.file_scope.renderFullyQualifiedName(writer);
1348 }1348 }
...@@ -1361,7 +1361,7 @@ pub const Namespace = struct {...@@ -1361,7 +1361,7 @@ pub const Namespace = struct {
1361 var separator_char: u8 = '.';1361 var separator_char: u8 = '.';
1362 if (ns.parent) |parent| {1362 if (ns.parent) |parent| {
1363 const decl = ns.getDecl();1363 const decl = ns.getDecl();
1364 try parent.renderFullyQualifiedDebugName(mem.spanZ(decl.name), writer);1364 try parent.renderFullyQualifiedDebugName(mem.sliceTo(decl.name, 0), writer);
1365 } else {1365 } else {
1366 try ns.file_scope.renderFullyQualifiedDebugName(writer);1366 try ns.file_scope.renderFullyQualifiedDebugName(writer);
1367 separator_char = ':';1367 separator_char = ':';
...@@ -3432,7 +3432,7 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool {...@@ -3432,7 +3432,7 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool {
3432 return sema.fail(&block_scope, export_src, "export of inline function", .{});3432 return sema.fail(&block_scope, export_src, "export of inline function", .{});
3433 }3433 }
3434 // The scope needs to have the decl in it.3434 // The scope needs to have the decl in it.
3435 const options: std.builtin.ExportOptions = .{ .name = mem.spanZ(decl.name) };3435 const options: std.builtin.ExportOptions = .{ .name = mem.sliceTo(decl.name, 0) };
3436 try sema.analyzeExport(&block_scope, export_src, options, decl);3436 try sema.analyzeExport(&block_scope, export_src, options, decl);
3437 }3437 }
3438 return type_changed or is_inline != prev_is_inline;3438 return type_changed or is_inline != prev_is_inline;
...@@ -3501,7 +3501,7 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool {...@@ -3501,7 +3501,7 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool {
3501 if (decl.is_exported) {3501 if (decl.is_exported) {
3502 const export_src = src; // TODO point to the export token3502 const export_src = src; // TODO point to the export token
3503 // The scope needs to have the decl in it.3503 // The scope needs to have the decl in it.
3504 const options: std.builtin.ExportOptions = .{ .name = mem.spanZ(decl.name) };3504 const options: std.builtin.ExportOptions = .{ .name = mem.sliceTo(decl.name, 0) };
3505 try sema.analyzeExport(&block_scope, export_src, options, decl);3505 try sema.analyzeExport(&block_scope, export_src, options, decl);
3506 }3506 }
35073507
...@@ -4675,7 +4675,7 @@ pub fn processOutdatedAndDeletedDecls(mod: *Module) !void {...@@ -4675,7 +4675,7 @@ pub fn processOutdatedAndDeletedDecls(mod: *Module) !void {
46754675
4676 // Remove from the namespace it resides in, preserving declaration order.4676 // Remove from the namespace it resides in, preserving declaration order.
4677 assert(decl.zir_decl_index != 0);4677 assert(decl.zir_decl_index != 0);
4678 _ = decl.src_namespace.decls.orderedRemove(mem.spanZ(decl.name));4678 _ = decl.src_namespace.decls.orderedRemove(mem.sliceTo(decl.name, 0));
46794679
4680 try mod.clearDecl(decl, &outdated_decls);4680 try mod.clearDecl(decl, &outdated_decls);
4681 decl.destroy(mod);4681 decl.destroy(mod);
src/Package.zig+1-1
...@@ -115,7 +115,7 @@ pub fn deinitTable(pkg: *Package, gpa: *Allocator) void {...@@ -115,7 +115,7 @@ pub fn deinitTable(pkg: *Package, gpa: *Allocator) void {
115115
116pub fn add(pkg: *Package, gpa: *Allocator, name: []const u8, package: *Package) !void {116pub fn add(pkg: *Package, gpa: *Allocator, name: []const u8, package: *Package) !void {
117 try pkg.table.ensureUnusedCapacity(gpa, 1);117 try pkg.table.ensureUnusedCapacity(gpa, 1);
118 const name_dupe = try mem.dupe(gpa, u8, name);118 const name_dupe = try gpa.dupe(u8, name);
119 pkg.table.putAssumeCapacityNoClobber(name_dupe, package);119 pkg.table.putAssumeCapacityNoClobber(name_dupe, package);
120}120}
121121
src/Sema.zig+1-1
...@@ -1639,7 +1639,7 @@ fn createTypeName(sema: *Sema, block: *Block, name_strategy: Zir.Inst.NameStrate...@@ -1639,7 +1639,7 @@ fn createTypeName(sema: *Sema, block: *Block, name_strategy: Zir.Inst.NameStrate
1639 block.src_decl.name, name_index,1639 block.src_decl.name, name_index,
1640 });1640 });
1641 },1641 },
1642 .parent => return sema.gpa.dupeZ(u8, mem.spanZ(block.src_decl.name)),1642 .parent => return sema.gpa.dupeZ(u8, mem.sliceTo(block.src_decl.name, 0)),
1643 .func => {1643 .func => {
1644 const name_index = sema.mod.getNextAnonNameIndex();1644 const name_index = sema.mod.getNextAnonNameIndex();
1645 const name = try std.fmt.allocPrintZ(sema.gpa, "{s}__anon_{d}", .{1645 const name = try std.fmt.allocPrintZ(sema.gpa, "{s}__anon_{d}", .{
src/arch/aarch64/CodeGen.zig+1-1
...@@ -1501,7 +1501,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index) !void {...@@ -1501,7 +1501,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index) !void {
1501 });1501 });
1502 } else if (func_value.castTag(.extern_fn)) |func_payload| {1502 } else if (func_value.castTag(.extern_fn)) |func_payload| {
1503 const decl = func_payload.data;1503 const decl = func_payload.data;
1504 const n_strx = try macho_file.addExternFn(mem.spanZ(decl.name));1504 const n_strx = try macho_file.addExternFn(mem.sliceTo(decl.name, 0));
15051505
1506 _ = try self.addInst(.{1506 _ = try self.addInst(.{
1507 .tag = .call_extern,1507 .tag = .call_extern,
src/arch/x86_64/CodeGen.zig+1-1
...@@ -1966,7 +1966,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index) !void {...@@ -1966,7 +1966,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index) !void {
1966 });1966 });
1967 } else if (func_value.castTag(.extern_fn)) |func_payload| {1967 } else if (func_value.castTag(.extern_fn)) |func_payload| {
1968 const decl = func_payload.data;1968 const decl = func_payload.data;
1969 const n_strx = try macho_file.addExternFn(mem.spanZ(decl.name));1969 const n_strx = try macho_file.addExternFn(mem.sliceTo(decl.name, 0));
1970 _ = try self.addInst(.{1970 _ = try self.addInst(.{
1971 .tag = .call_extern,1971 .tag = .call_extern,
1972 .ops = undefined,1972 .ops = undefined,
src/codegen/c.zig+1-1
...@@ -981,7 +981,7 @@ pub const DeclGen = struct {...@@ -981,7 +981,7 @@ pub const DeclGen = struct {
981 if (dg.module.decl_exports.get(decl)) |exports| {981 if (dg.module.decl_exports.get(decl)) |exports| {
982 return writer.writeAll(exports[0].options.name);982 return writer.writeAll(exports[0].options.name);
983 } else if (decl.val.tag() == .extern_fn) {983 } else if (decl.val.tag() == .extern_fn) {
984 return writer.writeAll(mem.spanZ(decl.name));984 return writer.writeAll(mem.sliceTo(decl.name, 0));
985 } else {985 } else {
986 const gpa = dg.module.gpa;986 const gpa = dg.module.gpa;
987 const name = try decl.getFullyQualifiedName(gpa);987 const name = try decl.getFullyQualifiedName(gpa);
src/libc_installation.zig+15-15
...@@ -76,7 +76,7 @@ pub const LibCInstallation = struct {...@@ -76,7 +76,7 @@ pub const LibCInstallation = struct {
76 if (value.len == 0) {76 if (value.len == 0) {
77 @field(self, field.name) = null;77 @field(self, field.name) = null;
78 } else {78 } else {
79 found_keys[i].allocated = try std.mem.dupeZ(allocator, u8, value);79 found_keys[i].allocated = try allocator.dupeZ(u8, value);
80 @field(self, field.name) = found_keys[i].allocated;80 @field(self, field.name) = found_keys[i].allocated;
81 }81 }
82 break;82 break;
...@@ -213,7 +213,7 @@ pub const LibCInstallation = struct {...@@ -213,7 +213,7 @@ pub const LibCInstallation = struct {
213 errdefer batch.wait() catch {};213 errdefer batch.wait() catch {};
214 batch.add(&async self.findNativeIncludeDirPosix(args));214 batch.add(&async self.findNativeIncludeDirPosix(args));
215 batch.add(&async self.findNativeCrtBeginDirHaiku(args));215 batch.add(&async self.findNativeCrtBeginDirHaiku(args));
216 self.crt_dir = try std.mem.dupeZ(args.allocator, u8, "/system/develop/lib");216 self.crt_dir = try args.allocator.dupeZ(u8, "/system/develop/lib");
217 break :blk batch.wait();217 break :blk batch.wait();
218 };218 };
219 } else {219 } else {
...@@ -222,8 +222,8 @@ pub const LibCInstallation = struct {...@@ -222,8 +222,8 @@ pub const LibCInstallation = struct {
222 errdefer batch.wait() catch {};222 errdefer batch.wait() catch {};
223 batch.add(&async self.findNativeIncludeDirPosix(args));223 batch.add(&async self.findNativeIncludeDirPosix(args));
224 switch (builtin.target.os.tag) {224 switch (builtin.target.os.tag) {
225 .freebsd, .netbsd, .openbsd, .dragonfly => self.crt_dir = try std.mem.dupeZ(args.allocator, u8, "/usr/lib"),225 .freebsd, .netbsd, .openbsd, .dragonfly => self.crt_dir = try args.allocator.dupeZ(u8, "/usr/lib"),
226 .solaris => self.crt_dir = try std.mem.dupeZ(args.allocator, u8, "/usr/lib/64"),226 .solaris => self.crt_dir = try args.allocator.dupeZ(u8, "/usr/lib/64"),
227 .linux => batch.add(&async self.findNativeCrtDirPosix(args)),227 .linux => batch.add(&async self.findNativeCrtDirPosix(args)),
228 else => {},228 else => {},
229 }229 }
...@@ -344,7 +344,7 @@ pub const LibCInstallation = struct {...@@ -344,7 +344,7 @@ pub const LibCInstallation = struct {
344344
345 if (self.include_dir == null) {345 if (self.include_dir == null) {
346 if (search_dir.accessZ(include_dir_example_file, .{})) |_| {346 if (search_dir.accessZ(include_dir_example_file, .{})) |_| {
347 self.include_dir = try std.mem.dupeZ(allocator, u8, search_path);347 self.include_dir = try allocator.dupeZ(u8, search_path);
348 } else |err| switch (err) {348 } else |err| switch (err) {
349 error.FileNotFound => {},349 error.FileNotFound => {},
350 else => return error.FileSystem,350 else => return error.FileSystem,
...@@ -353,7 +353,7 @@ pub const LibCInstallation = struct {...@@ -353,7 +353,7 @@ pub const LibCInstallation = struct {
353353
354 if (self.sys_include_dir == null) {354 if (self.sys_include_dir == null) {
355 if (search_dir.accessZ(sys_include_dir_example_file, .{})) |_| {355 if (search_dir.accessZ(sys_include_dir_example_file, .{})) |_| {
356 self.sys_include_dir = try std.mem.dupeZ(allocator, u8, search_path);356 self.sys_include_dir = try allocator.dupeZ(u8, search_path);
357 } else |err| switch (err) {357 } else |err| switch (err) {
358 error.FileNotFound => {},358 error.FileNotFound => {},
359 else => return error.FileSystem,359 else => return error.FileSystem,
...@@ -557,7 +557,7 @@ pub const LibCInstallation = struct {...@@ -557,7 +557,7 @@ pub const LibCInstallation = struct {
557 ) FindError!void {557 ) FindError!void {
558 const allocator = args.allocator;558 const allocator = args.allocator;
559 const msvc_lib_dir_ptr = sdk.msvc_lib_dir_ptr orelse return error.LibCRuntimeNotFound;559 const msvc_lib_dir_ptr = sdk.msvc_lib_dir_ptr orelse return error.LibCRuntimeNotFound;
560 self.msvc_lib_dir = try std.mem.dupeZ(allocator, u8, msvc_lib_dir_ptr[0..sdk.msvc_lib_dir_len]);560 self.msvc_lib_dir = try allocator.dupeZ(u8, msvc_lib_dir_ptr[0..sdk.msvc_lib_dir_len]);
561 }561 }
562};562};
563563
...@@ -631,10 +631,10 @@ fn ccPrintFileName(args: CCPrintFileNameOptions) ![:0]u8 {...@@ -631,10 +631,10 @@ fn ccPrintFileName(args: CCPrintFileNameOptions) ![:0]u8 {
631 // So we detect failure by checking if the output matches exactly the input.631 // So we detect failure by checking if the output matches exactly the input.
632 if (std.mem.eql(u8, line, args.search_basename)) return error.LibCRuntimeNotFound;632 if (std.mem.eql(u8, line, args.search_basename)) return error.LibCRuntimeNotFound;
633 switch (args.want_dirname) {633 switch (args.want_dirname) {
634 .full_path => return std.mem.dupeZ(allocator, u8, line),634 .full_path => return allocator.dupeZ(u8, line),
635 .only_dir => {635 .only_dir => {
636 const dirname = fs.path.dirname(line) orelse return error.LibCRuntimeNotFound;636 const dirname = fs.path.dirname(line) orelse return error.LibCRuntimeNotFound;
637 return std.mem.dupeZ(allocator, u8, dirname);637 return allocator.dupeZ(u8, dirname);
638 },638 },
639 }639 }
640}640}
...@@ -648,17 +648,17 @@ fn printVerboseInvocation(...@@ -648,17 +648,17 @@ fn printVerboseInvocation(
648 if (!verbose) return;648 if (!verbose) return;
649649
650 if (search_basename) |s| {650 if (search_basename) |s| {
651 std.debug.warn("Zig attempted to find the file '{s}' by executing this command:\n", .{s});651 std.debug.print("Zig attempted to find the file '{s}' by executing this command:\n", .{s});
652 } else {652 } else {
653 std.debug.warn("Zig attempted to find the path to native system libc headers by executing this command:\n", .{});653 std.debug.print("Zig attempted to find the path to native system libc headers by executing this command:\n", .{});
654 }654 }
655 for (argv) |arg, i| {655 for (argv) |arg, i| {
656 if (i != 0) std.debug.warn(" ", .{});656 if (i != 0) std.debug.print(" ", .{});
657 std.debug.warn("{s}", .{arg});657 std.debug.print("{s}", .{arg});
658 }658 }
659 std.debug.warn("\n", .{});659 std.debug.print("\n", .{});
660 if (stderr) |s| {660 if (stderr) |s| {
661 std.debug.warn("Output:\n==========\n{s}\n==========\n", .{s});661 std.debug.print("Output:\n==========\n{s}\n==========\n", .{s});
662 }662 }
663}663}
664664
src/link/Coff.zig+1-1
...@@ -752,7 +752,7 @@ fn finishUpdateDecl(self: *Coff, module: *Module, decl: *Module.Decl, code: []co...@@ -752,7 +752,7 @@ fn finishUpdateDecl(self: *Coff, module: *Module, decl: *Module.Decl, code: []co
752 } else {752 } else {
753 const vaddr = try self.allocateTextBlock(&decl.link.coff, code.len, required_alignment);753 const vaddr = try self.allocateTextBlock(&decl.link.coff, code.len, required_alignment);
754 log.debug("allocated text block for {s} at 0x{x} (size: {Bi})\n", .{754 log.debug("allocated text block for {s} at 0x{x} (size: {Bi})\n", .{
755 mem.spanZ(decl.name),755 mem.sliceTo(decl.name, 0),
756 vaddr,756 vaddr,
757 std.fmt.fmtIntSizeDec(code.len),757 std.fmt.fmtIntSizeDec(code.len),
758 });758 });
src/link/Elf.zig+4-4
...@@ -429,7 +429,7 @@ fn makeDebugString(self: *Elf, bytes: []const u8) !u32 {...@@ -429,7 +429,7 @@ fn makeDebugString(self: *Elf, bytes: []const u8) !u32 {
429429
430fn getString(self: *Elf, str_off: u32) []const u8 {430fn getString(self: *Elf, str_off: u32) []const u8 {
431 assert(str_off < self.shstrtab.items.len);431 assert(str_off < self.shstrtab.items.len);
432 return mem.spanZ(@ptrCast([*:0]const u8, self.shstrtab.items.ptr + str_off));432 return mem.sliceTo(@ptrCast([*:0]const u8, self.shstrtab.items.ptr + str_off), 0);
433}433}
434434
435fn updateString(self: *Elf, old_str_off: u32, new_name: []const u8) !u32 {435fn updateString(self: *Elf, old_str_off: u32, new_name: []const u8) !u32 {
...@@ -2236,14 +2236,14 @@ fn updateDeclCode(self: *Elf, decl: *Module.Decl, code: []const u8, stt_bits: u8...@@ -2236,14 +2236,14 @@ fn updateDeclCode(self: *Elf, decl: *Module.Decl, code: []const u8, stt_bits: u8
2236 self.shrinkTextBlock(&decl.link.elf, code.len);2236 self.shrinkTextBlock(&decl.link.elf, code.len);
2237 }2237 }
2238 local_sym.st_size = code.len;2238 local_sym.st_size = code.len;
2239 local_sym.st_name = try self.updateString(local_sym.st_name, mem.spanZ(decl.name));2239 local_sym.st_name = try self.updateString(local_sym.st_name, mem.sliceTo(decl.name, 0));
2240 local_sym.st_info = (elf.STB_LOCAL << 4) | stt_bits;2240 local_sym.st_info = (elf.STB_LOCAL << 4) | stt_bits;
2241 local_sym.st_other = 0;2241 local_sym.st_other = 0;
2242 local_sym.st_shndx = self.text_section_index.?;2242 local_sym.st_shndx = self.text_section_index.?;
2243 // TODO this write could be avoided if no fields of the symbol were changed.2243 // TODO this write could be avoided if no fields of the symbol were changed.
2244 try self.writeSymbol(decl.link.elf.local_sym_index);2244 try self.writeSymbol(decl.link.elf.local_sym_index);
2245 } else {2245 } else {
2246 const decl_name = mem.spanZ(decl.name);2246 const decl_name = mem.sliceTo(decl.name, 0);
2247 const name_str_index = try self.makeString(decl_name);2247 const name_str_index = try self.makeString(decl_name);
2248 const vaddr = try self.allocateTextBlock(&decl.link.elf, code.len, required_alignment);2248 const vaddr = try self.allocateTextBlock(&decl.link.elf, code.len, required_alignment);
2249 log.debug("allocated text block for {s} at 0x{x}", .{ decl_name, vaddr });2249 log.debug("allocated text block for {s} at 0x{x}", .{ decl_name, vaddr });
...@@ -2371,7 +2371,7 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven...@@ -2371,7 +2371,7 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven
2371 dbg_line_buffer.appendAssumeCapacity(DW.LNS.copy);2371 dbg_line_buffer.appendAssumeCapacity(DW.LNS.copy);
23722372
2373 // .debug_info subprogram2373 // .debug_info subprogram
2374 const decl_name_with_null = decl.name[0 .. mem.lenZ(decl.name) + 1];2374 const decl_name_with_null = decl.name[0 .. mem.sliceTo(decl.name, 0).len + 1];
2375 try dbg_info_buffer.ensureUnusedCapacity(25 + decl_name_with_null.len);2375 try dbg_info_buffer.ensureUnusedCapacity(25 + decl_name_with_null.len);
23762376
2377 const fn_ret_type = decl.ty.fnReturnType();2377 const fn_ret_type = decl.ty.fnReturnType();
src/link/MachO.zig+9-5
...@@ -3439,7 +3439,9 @@ fn placeDecl(self: *MachO, decl: *Module.Decl, code_len: usize) !*macho.nlist_64...@@ -3439,7 +3439,9 @@ fn placeDecl(self: *MachO, decl: *Module.Decl, code_len: usize) !*macho.nlist_64
3439 decl.link.macho.size = code_len;3439 decl.link.macho.size = code_len;
3440 decl.link.macho.dirty = true;3440 decl.link.macho.dirty = true;
34413441
3442 const new_name = try std.fmt.allocPrint(self.base.allocator, "_{s}", .{mem.spanZ(decl.name)});3442 const new_name = try std.fmt.allocPrint(self.base.allocator, "_{s}", .{
3443 mem.sliceTo(decl.name, 0),
3444 });
3443 defer self.base.allocator.free(new_name);3445 defer self.base.allocator.free(new_name);
34443446
3445 symbol.n_strx = try self.makeString(new_name);3447 symbol.n_strx = try self.makeString(new_name);
...@@ -3447,7 +3449,9 @@ fn placeDecl(self: *MachO, decl: *Module.Decl, code_len: usize) !*macho.nlist_64...@@ -3447,7 +3449,9 @@ fn placeDecl(self: *MachO, decl: *Module.Decl, code_len: usize) !*macho.nlist_64
3447 symbol.n_sect = @intCast(u8, self.text_section_index.?) + 1;3449 symbol.n_sect = @intCast(u8, self.text_section_index.?) + 1;
3448 symbol.n_desc = 0;3450 symbol.n_desc = 0;
3449 } else {3451 } else {
3450 const decl_name = try std.fmt.allocPrint(self.base.allocator, "_{s}", .{mem.spanZ(decl.name)});3452 const decl_name = try std.fmt.allocPrint(self.base.allocator, "_{s}", .{
3453 mem.sliceTo(decl.name, 0),
3454 });
3451 defer self.base.allocator.free(decl_name);3455 defer self.base.allocator.free(decl_name);
34523456
3453 const name_str_index = try self.makeString(decl_name);3457 const name_str_index = try self.makeString(decl_name);
...@@ -4045,7 +4049,7 @@ pub fn populateMissingMetadata(self: *MachO) !void {...@@ -4045,7 +4049,7 @@ pub fn populateMissingMetadata(self: *MachO) !void {
4045 self.dylinker_cmd_index = @intCast(u16, self.load_commands.items.len);4049 self.dylinker_cmd_index = @intCast(u16, self.load_commands.items.len);
4046 const cmdsize = @intCast(u32, mem.alignForwardGeneric(4050 const cmdsize = @intCast(u32, mem.alignForwardGeneric(
4047 u64,4051 u64,
4048 @sizeOf(macho.dylinker_command) + mem.lenZ(default_dyld_path),4052 @sizeOf(macho.dylinker_command) + mem.sliceTo(default_dyld_path, 0).len,
4049 @sizeOf(u64),4053 @sizeOf(u64),
4050 ));4054 ));
4051 var dylinker_cmd = commands.emptyGenericCommandWithData(macho.dylinker_command{4055 var dylinker_cmd = commands.emptyGenericCommandWithData(macho.dylinker_command{
...@@ -4055,7 +4059,7 @@ pub fn populateMissingMetadata(self: *MachO) !void {...@@ -4055,7 +4059,7 @@ pub fn populateMissingMetadata(self: *MachO) !void {
4055 });4059 });
4056 dylinker_cmd.data = try self.base.allocator.alloc(u8, cmdsize - dylinker_cmd.inner.name);4060 dylinker_cmd.data = try self.base.allocator.alloc(u8, cmdsize - dylinker_cmd.inner.name);
4057 mem.set(u8, dylinker_cmd.data, 0);4061 mem.set(u8, dylinker_cmd.data, 0);
4058 mem.copy(u8, dylinker_cmd.data, mem.spanZ(default_dyld_path));4062 mem.copy(u8, dylinker_cmd.data, mem.sliceTo(default_dyld_path, 0));
4059 try self.load_commands.append(self.base.allocator, .{ .Dylinker = dylinker_cmd });4063 try self.load_commands.append(self.base.allocator, .{ .Dylinker = dylinker_cmd });
4060 self.load_commands_dirty = true;4064 self.load_commands_dirty = true;
4061 }4065 }
...@@ -5292,7 +5296,7 @@ pub fn makeString(self: *MachO, string: []const u8) !u32 {...@@ -5292,7 +5296,7 @@ pub fn makeString(self: *MachO, string: []const u8) !u32 {
52925296
5293pub fn getString(self: *MachO, off: u32) []const u8 {5297pub fn getString(self: *MachO, off: u32) []const u8 {
5294 assert(off < self.strtab.items.len);5298 assert(off < self.strtab.items.len);
5295 return mem.spanZ(@ptrCast([*:0]const u8, self.strtab.items.ptr + off));5299 return mem.sliceTo(@ptrCast([*:0]const u8, self.strtab.items.ptr + off), 0);
5296}5300}
52975301
5298pub fn symbolIsStab(sym: macho.nlist_64) bool {5302pub fn symbolIsStab(sym: macho.nlist_64) bool {
src/link/MachO/Archive.zig+1-1
...@@ -175,7 +175,7 @@ fn parseTableOfContents(self: *Archive, allocator: *Allocator, reader: anytype)...@@ -175,7 +175,7 @@ fn parseTableOfContents(self: *Archive, allocator: *Allocator, reader: anytype)
175 };175 };
176 const object_offset = try symtab_reader.readIntLittle(u32);176 const object_offset = try symtab_reader.readIntLittle(u32);
177177
178 const sym_name = mem.spanZ(@ptrCast([*:0]const u8, strtab.ptr + n_strx));178 const sym_name = mem.sliceTo(@ptrCast([*:0]const u8, strtab.ptr + n_strx), 0);
179 const owned_name = try allocator.dupe(u8, sym_name);179 const owned_name = try allocator.dupe(u8, sym_name);
180 const res = try self.toc.getOrPut(allocator, owned_name);180 const res = try self.toc.getOrPut(allocator, owned_name);
181 defer if (res.found_existing) allocator.free(owned_name);181 defer if (res.found_existing) allocator.free(owned_name);
src/link/MachO/DebugSymbols.zig+1-1
...@@ -884,7 +884,7 @@ pub fn initDeclDebugBuffers(...@@ -884,7 +884,7 @@ pub fn initDeclDebugBuffers(
884 dbg_line_buffer.appendAssumeCapacity(DW.LNS.copy);884 dbg_line_buffer.appendAssumeCapacity(DW.LNS.copy);
885885
886 // .debug_info subprogram886 // .debug_info subprogram
887 const decl_name_with_null = decl.name[0 .. mem.lenZ(decl.name) + 1];887 const decl_name_with_null = decl.name[0 .. mem.sliceTo(decl.name, 0).len + 1];
888 try dbg_info_buffer.ensureUnusedCapacity(27 + decl_name_with_null.len);888 try dbg_info_buffer.ensureUnusedCapacity(27 + decl_name_with_null.len);
889889
890 const fn_ret_type = decl.ty.fnReturnType();890 const fn_ret_type = decl.ty.fnReturnType();
src/link/MachO/Dylib.zig+2-2
...@@ -56,7 +56,7 @@ pub const Id = struct {...@@ -56,7 +56,7 @@ pub const Id = struct {
56 pub fn fromLoadCommand(allocator: *Allocator, lc: commands.GenericCommandWithData(macho.dylib_command)) !Id {56 pub fn fromLoadCommand(allocator: *Allocator, lc: commands.GenericCommandWithData(macho.dylib_command)) !Id {
57 const dylib = lc.inner.dylib;57 const dylib = lc.inner.dylib;
58 const dylib_name = @ptrCast([*:0]const u8, lc.data[dylib.name - @sizeOf(macho.dylib_command) ..]);58 const dylib_name = @ptrCast([*:0]const u8, lc.data[dylib.name - @sizeOf(macho.dylib_command) ..]);
59 const name = try allocator.dupe(u8, mem.spanZ(dylib_name));59 const name = try allocator.dupe(u8, mem.sliceTo(dylib_name, 0));
6060
61 return Id{61 return Id{
62 .name = name,62 .name = name,
...@@ -230,7 +230,7 @@ fn parseSymbols(self: *Dylib, allocator: *Allocator) !void {...@@ -230,7 +230,7 @@ fn parseSymbols(self: *Dylib, allocator: *Allocator) !void {
230230
231 if (!add_to_symtab) continue;231 if (!add_to_symtab) continue;
232232
233 const sym_name = mem.spanZ(@ptrCast([*:0]const u8, strtab.ptr + sym.n_strx));233 const sym_name = mem.sliceTo(@ptrCast([*:0]const u8, strtab.ptr + sym.n_strx), 0);
234 const name = try allocator.dupe(u8, sym_name);234 const name = try allocator.dupe(u8, sym_name);
235 try self.symbols.putNoClobber(allocator, name, {});235 try self.symbols.putNoClobber(allocator, name, {});
236 }236 }
src/link/MachO/Object.zig+1-1
...@@ -633,5 +633,5 @@ fn readSection(self: Object, allocator: *Allocator, index: u16) ![]u8 {...@@ -633,5 +633,5 @@ fn readSection(self: Object, allocator: *Allocator, index: u16) ![]u8 {
633633
634pub fn getString(self: Object, off: u32) []const u8 {634pub fn getString(self: Object, off: u32) []const u8 {
635 assert(off < self.strtab.items.len);635 assert(off < self.strtab.items.len);
636 return mem.spanZ(@ptrCast([*:0]const u8, self.strtab.items.ptr + off));636 return mem.sliceTo(@ptrCast([*:0]const u8, self.strtab.items.ptr + off), 0);
637}637}
src/link/Plan9.zig+1-1
...@@ -299,7 +299,7 @@ pub fn updateDecl(self: *Plan9, module: *Module, decl: *Module.Decl) !void {...@@ -299,7 +299,7 @@ pub fn updateDecl(self: *Plan9, module: *Module, decl: *Module.Decl) !void {
299 return;299 return;
300 },300 },
301 };301 };
302 var duped_code = try std.mem.dupe(self.base.allocator, u8, code);302 var duped_code = try self.base.allocator.dupe(u8, code);
303 errdefer self.base.allocator.free(duped_code);303 errdefer self.base.allocator.free(duped_code);
304 try self.data_decl_table.put(self.base.allocator, decl, duped_code);304 try self.data_decl_table.put(self.base.allocator, decl, duped_code);
305 return self.updateFinish(decl);305 return self.updateFinish(decl);
src/main.zig+2-2
...@@ -1282,7 +1282,7 @@ fn buildOutputType(...@@ -1282,7 +1282,7 @@ fn buildOutputType(
1282 try clang_argv.appendSlice(it.other_args);1282 try clang_argv.appendSlice(it.other_args);
1283 },1283 },
1284 .positional => {1284 .positional => {
1285 const file_ext = Compilation.classifyFileExt(mem.spanZ(it.only_arg));1285 const file_ext = Compilation.classifyFileExt(mem.sliceTo(it.only_arg, 0));
1286 switch (file_ext) {1286 switch (file_ext) {
1287 .assembly, .c, .cpp, .ll, .bc, .h, .m, .mm => try c_source_files.append(.{ .src_path = it.only_arg }),1287 .assembly, .c, .cpp, .ll, .bc, .h, .m, .mm => try c_source_files.append(.{ .src_path = it.only_arg }),
1288 .unknown, .shared_library, .object, .static_library => {1288 .unknown, .shared_library, .object, .static_library => {
...@@ -4117,7 +4117,7 @@ pub const ClangArgIterator = struct {...@@ -4117,7 +4117,7 @@ pub const ClangArgIterator = struct {
4117 }4117 }
4118 }4118 }
4119 while (it.next()) |token| {4119 while (it.next()) |token| {
4120 const dupe_token = try mem.dupeZ(allocator, u8, token);4120 const dupe_token = try allocator.dupeZ(u8, token);
4121 errdefer allocator.free(dupe_token);4121 errdefer allocator.free(dupe_token);
4122 try resp_arg_list.append(dupe_token);4122 try resp_arg_list.append(dupe_token);
4123 }4123 }
src/stage1.zig+3-3
...@@ -42,7 +42,7 @@ pub fn main(argc: c_int, argv: [*][*:0]u8) callconv(.C) c_int {...@@ -42,7 +42,7 @@ pub fn main(argc: c_int, argv: [*][*:0]u8) callconv(.C) c_int {
4242
43 const args = arena.alloc([]const u8, @intCast(usize, argc)) catch fatal("{s}", .{"OutOfMemory"});43 const args = arena.alloc([]const u8, @intCast(usize, argc)) catch fatal("{s}", .{"OutOfMemory"});
44 for (args) |*arg, i| {44 for (args) |*arg, i| {
45 arg.* = mem.spanZ(argv[i]);45 arg.* = mem.sliceTo(argv[i], 0);
46 }46 }
47 if (builtin.mode == .Debug) {47 if (builtin.mode == .Debug) {
48 stage2.mainArgs(gpa, arena, args) catch unreachable;48 stage2.mainArgs(gpa, arena, args) catch unreachable;
...@@ -434,14 +434,14 @@ export fn stage2_add_link_lib(...@@ -434,14 +434,14 @@ export fn stage2_add_link_lib(
434 return null;434 return null;
435 }435 }
436 if (!target.isWasm() and !comp.bin_file.options.pic) {436 if (!target.isWasm() and !comp.bin_file.options.pic) {
437 return std.fmt.allocPrint0(437 return std.fmt.allocPrintZ(
438 comp.gpa,438 comp.gpa,
439 "dependency on dynamic library '{s}' requires enabling Position Independent Code. Fixed by `-l{s}` or `-fPIC`.",439 "dependency on dynamic library '{s}' requires enabling Position Independent Code. Fixed by `-l{s}` or `-fPIC`.",
440 .{ lib_name, lib_name },440 .{ lib_name, lib_name },
441 ) catch "out of memory";441 ) catch "out of memory";
442 }442 }
443 comp.stage1AddLinkLib(lib_name) catch |err| {443 comp.stage1AddLinkLib(lib_name) catch |err| {
444 return std.fmt.allocPrint0(comp.gpa, "unable to add link lib '{s}': {s}", .{444 return std.fmt.allocPrintZ(comp.gpa, "unable to add link lib '{s}': {s}", .{
445 lib_name, @errorName(err),445 lib_name, @errorName(err),
446 }) catch "out of memory";446 }) catch "out of memory";
447 };447 };
src/translate_c.zig+3-3
...@@ -335,7 +335,7 @@ pub const Context = struct {...@@ -335,7 +335,7 @@ pub const Context = struct {
335335
336 /// Convert a null-terminated C string to a slice allocated in the arena336 /// Convert a null-terminated C string to a slice allocated in the arena
337 fn str(c: *Context, s: [*:0]const u8) ![]u8 {337 fn str(c: *Context, s: [*:0]const u8) ![]u8 {
338 return mem.dupe(c.arena, u8, mem.spanZ(s));338 return c.arena.dupe(u8, mem.sliceTo(s, 0));
339 }339 }
340340
341 /// Convert a clang source location to a file:line:column string341 /// Convert a clang source location to a file:line:column string
...@@ -2553,7 +2553,7 @@ fn transInitListExprRecord(...@@ -2553,7 +2553,7 @@ fn transInitListExprRecord(
2553 var raw_name = try c.str(@ptrCast(*const clang.NamedDecl, field_decl).getName_bytes_begin());2553 var raw_name = try c.str(@ptrCast(*const clang.NamedDecl, field_decl).getName_bytes_begin());
2554 if (field_decl.isAnonymousStructOrUnion()) {2554 if (field_decl.isAnonymousStructOrUnion()) {
2555 const name = c.decl_table.get(@ptrToInt(field_decl.getCanonicalDecl())).?;2555 const name = c.decl_table.get(@ptrToInt(field_decl.getCanonicalDecl())).?;
2556 raw_name = try mem.dupe(c.arena, u8, name);2556 raw_name = try c.arena.dupe(u8, name);
2557 }2557 }
25582558
2559 var init_expr = try transExpr(c, scope, elem_expr, .used);2559 var init_expr = try transExpr(c, scope, elem_expr, .used);
...@@ -3318,7 +3318,7 @@ fn transMemberExpr(c: *Context, scope: *Scope, stmt: *const clang.MemberExpr, re...@@ -3318,7 +3318,7 @@ fn transMemberExpr(c: *Context, scope: *Scope, stmt: *const clang.MemberExpr, re
3318 const field_decl = @ptrCast(*const clang.FieldDecl, member_decl);3318 const field_decl = @ptrCast(*const clang.FieldDecl, member_decl);
3319 if (field_decl.isAnonymousStructOrUnion()) {3319 if (field_decl.isAnonymousStructOrUnion()) {
3320 const name = c.decl_table.get(@ptrToInt(field_decl.getCanonicalDecl())).?;3320 const name = c.decl_table.get(@ptrToInt(field_decl.getCanonicalDecl())).?;
3321 break :blk try mem.dupe(c.arena, u8, name);3321 break :blk try c.arena.dupe(u8, name);
3322 }3322 }
3323 }3323 }
3324 const decl = @ptrCast(*const clang.NamedDecl, member_decl);3324 const decl = @ptrCast(*const clang.NamedDecl, member_decl);
src/type.zig+1-1
...@@ -1179,7 +1179,7 @@ pub const Type = extern union {...@@ -1179,7 +1179,7 @@ pub const Type = extern union {
1179 },1179 },
1180 .error_set => {1180 .error_set => {
1181 const error_set = ty.castTag(.error_set).?.data;1181 const error_set = ty.castTag(.error_set).?.data;
1182 return writer.writeAll(std.mem.spanZ(error_set.owner_decl.name));1182 return writer.writeAll(std.mem.sliceTo(error_set.owner_decl.name, 0));
1183 },1183 },
1184 .error_set_inferred => {1184 .error_set_inferred => {
1185 const func = ty.castTag(.error_set_inferred).?.data.func;1185 const func = ty.castTag(.error_set_inferred).?.data.func;
src/value.zig+2-2
...@@ -753,9 +753,9 @@ pub const Value = extern union {...@@ -753,9 +753,9 @@ pub const Value = extern union {
753 const bytes = val.castTag(.bytes).?.data;753 const bytes = val.castTag(.bytes).?.data;
754 const adjusted_len = bytes.len - @boolToInt(ty.sentinel() != null);754 const adjusted_len = bytes.len - @boolToInt(ty.sentinel() != null);
755 const adjusted_bytes = bytes[0..adjusted_len];755 const adjusted_bytes = bytes[0..adjusted_len];
756 return std.mem.dupe(allocator, u8, adjusted_bytes);756 return allocator.dupe(u8, adjusted_bytes);
757 },757 },
758 .enum_literal => return std.mem.dupe(allocator, u8, val.castTag(.enum_literal).?.data),758 .enum_literal => return allocator.dupe(u8, val.castTag(.enum_literal).?.data),
759 .repeated => @panic("TODO implement toAllocatedBytes for this Value tag"),759 .repeated => @panic("TODO implement toAllocatedBytes for this Value tag"),
760 .decl_ref => {760 .decl_ref => {
761 const decl = val.castTag(.decl_ref).?.data;761 const decl = val.castTag(.decl_ref).?.data;
test/behavior/async_fn.zig+2-2
...@@ -715,7 +715,7 @@ fn testAsyncAwaitTypicalUsage(...@@ -715,7 +715,7 @@ fn testAsyncAwaitTypicalUsage(
715 var global_download_frame: anyframe = undefined;715 var global_download_frame: anyframe = undefined;
716 fn fetchUrl(allocator: *std.mem.Allocator, url: []const u8) anyerror![]u8 {716 fn fetchUrl(allocator: *std.mem.Allocator, url: []const u8) anyerror![]u8 {
717 _ = url;717 _ = url;
718 const result = try std.mem.dupe(allocator, u8, "expected download text");718 const result = try allocator.dupe(u8, "expected download text");
719 errdefer allocator.free(result);719 errdefer allocator.free(result);
720 if (suspend_download) {720 if (suspend_download) {
721 suspend {721 suspend {
...@@ -729,7 +729,7 @@ fn testAsyncAwaitTypicalUsage(...@@ -729,7 +729,7 @@ fn testAsyncAwaitTypicalUsage(
729 var global_file_frame: anyframe = undefined;729 var global_file_frame: anyframe = undefined;
730 fn readFile(allocator: *std.mem.Allocator, filename: []const u8) anyerror![]u8 {730 fn readFile(allocator: *std.mem.Allocator, filename: []const u8) anyerror![]u8 {
731 _ = filename;731 _ = filename;
732 const result = try std.mem.dupe(allocator, u8, "expected file text");732 const result = try allocator.dupe(u8, "expected file text");
733 errdefer allocator.free(result);733 errdefer allocator.free(result);
734 if (suspend_file) {734 if (suspend_file) {
735 suspend {735 suspend {
test/behavior/cast_stage1.zig+1-1
...@@ -171,7 +171,7 @@ fn testCastPtrOfArrayToSliceAndPtr() !void {...@@ -171,7 +171,7 @@ fn testCastPtrOfArrayToSliceAndPtr() !void {
171test "cast *[1][*]const u8 to [*]const ?[*]const u8" {171test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
172 const window_name = [1][*]const u8{"window name"};172 const window_name = [1][*]const u8{"window name"};
173 const x: [*]const ?[*]const u8 = &window_name;173 const x: [*]const ?[*]const u8 = &window_name;
174 try expect(mem.eql(u8, std.mem.spanZ(@ptrCast([*:0]const u8, x[0].?)), "window name"));174 try expect(mem.eql(u8, std.mem.sliceTo(@ptrCast([*:0]const u8, x[0].?), 0), "window name"));
175}175}
176176
177test "cast f16 to wider types" {177test "cast f16 to wider types" {
test/behavior/pointers_stage1.zig+1-1
...@@ -142,7 +142,7 @@ test "null terminated pointer" {...@@ -142,7 +142,7 @@ test "null terminated pointer" {
142 var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero);142 var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero);
143 var no_zero_ptr: [*]const u8 = zero_ptr;143 var no_zero_ptr: [*]const u8 = zero_ptr;
144 var zero_ptr_again = @ptrCast([*:0]const u8, no_zero_ptr);144 var zero_ptr_again = @ptrCast([*:0]const u8, no_zero_ptr);
145 try expect(std.mem.eql(u8, std.mem.spanZ(zero_ptr_again), "hello"));145 try expect(std.mem.eql(u8, std.mem.sliceTo(zero_ptr_again, 0), "hello"));
146 }146 }
147 };147 };
148 try S.doTheTest();148 try S.doTheTest();
test/cli.zig+10-10
...@@ -19,11 +19,11 @@ pub fn main() !void {...@@ -19,11 +19,11 @@ pub fn main() !void {
19 a = &arena.allocator;19 a = &arena.allocator;
2020
21 const zig_exe_rel = try (arg_it.next(a) orelse {21 const zig_exe_rel = try (arg_it.next(a) orelse {
22 std.debug.warn("Expected first argument to be path to zig compiler\n", .{});22 std.debug.print("Expected first argument to be path to zig compiler\n", .{});
23 return error.InvalidArgs;23 return error.InvalidArgs;
24 });24 });
25 const cache_root = try (arg_it.next(a) orelse {25 const cache_root = try (arg_it.next(a) orelse {
26 std.debug.warn("Expected second argument to be cache root directory path\n", .{});26 std.debug.print("Expected second argument to be cache root directory path\n", .{});
27 return error.InvalidArgs;27 return error.InvalidArgs;
28 });28 });
29 const zig_exe = try fs.path.resolve(a, &[_][]const u8{zig_exe_rel});29 const zig_exe = try fs.path.resolve(a, &[_][]const u8{zig_exe_rel});
...@@ -47,11 +47,11 @@ pub fn main() !void {...@@ -47,11 +47,11 @@ pub fn main() !void {
47}47}
4848
49fn printCmd(cwd: []const u8, argv: []const []const u8) void {49fn printCmd(cwd: []const u8, argv: []const []const u8) void {
50 std.debug.warn("cd {s} && ", .{cwd});50 std.debug.print("cd {s} && ", .{cwd});
51 for (argv) |arg| {51 for (argv) |arg| {
52 std.debug.warn("{s} ", .{arg});52 std.debug.print("{s} ", .{arg});
53 }53 }
54 std.debug.warn("\n", .{});54 std.debug.print("\n", .{});
55}55}
5656
57fn exec(cwd: []const u8, expect_0: bool, argv: []const []const u8) !ChildProcess.ExecResult {57fn exec(cwd: []const u8, expect_0: bool, argv: []const []const u8) !ChildProcess.ExecResult {
...@@ -62,23 +62,23 @@ fn exec(cwd: []const u8, expect_0: bool, argv: []const []const u8) !ChildProcess...@@ -62,23 +62,23 @@ fn exec(cwd: []const u8, expect_0: bool, argv: []const []const u8) !ChildProcess
62 .cwd = cwd,62 .cwd = cwd,
63 .max_output_bytes = max_output_size,63 .max_output_bytes = max_output_size,
64 }) catch |err| {64 }) catch |err| {
65 std.debug.warn("The following command failed:\n", .{});65 std.debug.print("The following command failed:\n", .{});
66 printCmd(cwd, argv);66 printCmd(cwd, argv);
67 return err;67 return err;
68 };68 };
69 switch (result.term) {69 switch (result.term) {
70 .Exited => |code| {70 .Exited => |code| {
71 if ((code != 0) == expect_0) {71 if ((code != 0) == expect_0) {
72 std.debug.warn("The following command exited with error code {}:\n", .{code});72 std.debug.print("The following command exited with error code {}:\n", .{code});
73 printCmd(cwd, argv);73 printCmd(cwd, argv);
74 std.debug.warn("stderr:\n{s}\n", .{result.stderr});74 std.debug.print("stderr:\n{s}\n", .{result.stderr});
75 return error.CommandFailed;75 return error.CommandFailed;
76 }76 }
77 },77 },
78 else => {78 else => {
79 std.debug.warn("The following command terminated unexpectedly:\n", .{});79 std.debug.print("The following command terminated unexpectedly:\n", .{});
80 printCmd(cwd, argv);80 printCmd(cwd, argv);
81 std.debug.warn("stderr:\n{s}\n", .{result.stderr});81 std.debug.print("stderr:\n{s}\n", .{result.stderr});
82 return error.CommandFailed;82 return error.CommandFailed;
83 },83 },
84 }84 }
test/src/compare_output.zig-1
...@@ -6,7 +6,6 @@ const ArrayList = std.ArrayList;...@@ -6,7 +6,6 @@ const ArrayList = std.ArrayList;
6const fmt = std.fmt;6const fmt = std.fmt;
7const mem = std.mem;7const mem = std.mem;
8const fs = std.fs;8const fs = std.fs;
9const warn = std.debug.warn;
10const Mode = std.builtin.Mode;9const Mode = std.builtin.Mode;
1110
12pub const CompareOutputContext = struct {11pub const CompareOutputContext = struct {
test/src/run_translated_c.zig-1
...@@ -6,7 +6,6 @@ const ArrayList = std.ArrayList;...@@ -6,7 +6,6 @@ const ArrayList = std.ArrayList;
6const fmt = std.fmt;6const fmt = std.fmt;
7const mem = std.mem;7const mem = std.mem;
8const fs = std.fs;8const fs = std.fs;
9const warn = std.debug.warn;
109
11pub const RunTranslatedCContext = struct {10pub const RunTranslatedCContext = struct {
12 b: *build.Builder,11 b: *build.Builder,
test/src/translate_c.zig-1
...@@ -6,7 +6,6 @@ const ArrayList = std.ArrayList;...@@ -6,7 +6,6 @@ const ArrayList = std.ArrayList;
6const fmt = std.fmt;6const fmt = std.fmt;
7const mem = std.mem;7const mem = std.mem;
8const fs = std.fs;8const fs = std.fs;
9const warn = std.debug.warn;
10const CrossTarget = std.zig.CrossTarget;9const CrossTarget = std.zig.CrossTarget;
1110
12pub const TranslateCContext = struct {11pub const TranslateCContext = struct {
test/tests.zig+12-13
...@@ -1,7 +1,6 @@...@@ -1,7 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const debug = std.debug;3const debug = std.debug;
4const warn = debug.warn;
5const build = std.build;4const build = std.build;
6const CrossTarget = std.zig.CrossTarget;5const CrossTarget = std.zig.CrossTarget;
7const io = std.io;6const io = std.io;
...@@ -716,7 +715,7 @@ pub const StackTracesContext = struct {...@@ -716,7 +715,7 @@ pub const StackTracesContext = struct {
716 defer args.deinit();715 defer args.deinit();
717 args.append(full_exe_path) catch unreachable;716 args.append(full_exe_path) catch unreachable;
718717
719 warn("Test {d}/{d} {s}...", .{ self.test_index + 1, self.context.test_index, self.name });718 std.debug.print("Test {d}/{d} {s}...", .{ self.test_index + 1, self.context.test_index, self.name });
720719
721 const child = std.ChildProcess.init(args.items, b.allocator) catch unreachable;720 const child = std.ChildProcess.init(args.items, b.allocator) catch unreachable;
722 defer child.deinit();721 defer child.deinit();
...@@ -745,7 +744,7 @@ pub const StackTracesContext = struct {...@@ -745,7 +744,7 @@ pub const StackTracesContext = struct {
745 .Exited => |code| {744 .Exited => |code| {
746 const expect_code: u32 = 1;745 const expect_code: u32 = 1;
747 if (code != expect_code) {746 if (code != expect_code) {
748 warn("Process {s} exited with error code {d} but expected code {d}\n", .{747 std.debug.print("Process {s} exited with error code {d} but expected code {d}\n", .{
749 full_exe_path,748 full_exe_path,
750 code,749 code,
751 expect_code,750 expect_code,
...@@ -755,17 +754,17 @@ pub const StackTracesContext = struct {...@@ -755,17 +754,17 @@ pub const StackTracesContext = struct {
755 }754 }
756 },755 },
757 .Signal => |signum| {756 .Signal => |signum| {
758 warn("Process {s} terminated on signal {d}\n", .{ full_exe_path, signum });757 std.debug.print("Process {s} terminated on signal {d}\n", .{ full_exe_path, signum });
759 printInvocation(args.items);758 printInvocation(args.items);
760 return error.TestFailed;759 return error.TestFailed;
761 },760 },
762 .Stopped => |signum| {761 .Stopped => |signum| {
763 warn("Process {s} stopped on signal {d}\n", .{ full_exe_path, signum });762 std.debug.print("Process {s} stopped on signal {d}\n", .{ full_exe_path, signum });
764 printInvocation(args.items);763 printInvocation(args.items);
765 return error.TestFailed;764 return error.TestFailed;
766 },765 },
767 .Unknown => |code| {766 .Unknown => |code| {
768 warn("Process {s} terminated unexpectedly with error code {d}\n", .{ full_exe_path, code });767 std.debug.print("Process {s} terminated unexpectedly with error code {d}\n", .{ full_exe_path, code });
769 printInvocation(args.items);768 printInvocation(args.items);
770 return error.TestFailed;769 return error.TestFailed;
771 },770 },
...@@ -829,7 +828,7 @@ pub const StackTracesContext = struct {...@@ -829,7 +828,7 @@ pub const StackTracesContext = struct {
829 };828 };
830829
831 if (!mem.eql(u8, self.expect_output, got)) {830 if (!mem.eql(u8, self.expect_output, got)) {
832 warn(831 std.debug.print(
833 \\832 \\
834 \\========= Expected this output: =========833 \\========= Expected this output: =========
835 \\{s}834 \\{s}
...@@ -839,7 +838,7 @@ pub const StackTracesContext = struct {...@@ -839,7 +838,7 @@ pub const StackTracesContext = struct {
839 , .{ self.expect_output, got });838 , .{ self.expect_output, got });
840 return error.TestFailed;839 return error.TestFailed;
841 }840 }
842 warn("OK\n", .{});841 std.debug.print("OK\n", .{});
843 }842 }
844 };843 };
845};844};
...@@ -1003,14 +1002,14 @@ pub const GenHContext = struct {...@@ -1003,14 +1002,14 @@ pub const GenHContext = struct {
1003 const self = @fieldParentPtr(GenHCmpOutputStep, "step", step);1002 const self = @fieldParentPtr(GenHCmpOutputStep, "step", step);
1004 const b = self.context.b;1003 const b = self.context.b;
10051004
1006 warn("Test {d}/{d} {s}...", .{ self.test_index + 1, self.context.test_index, self.name });1005 std.debug.print("Test {d}/{d} {s}...", .{ self.test_index + 1, self.context.test_index, self.name });
10071006
1008 const full_h_path = self.obj.getOutputHPath();1007 const full_h_path = self.obj.getOutputHPath();
1009 const actual_h = try io.readFileAlloc(b.allocator, full_h_path);1008 const actual_h = try io.readFileAlloc(b.allocator, full_h_path);
10101009
1011 for (self.case.expected_lines.items) |expected_line| {1010 for (self.case.expected_lines.items) |expected_line| {
1012 if (mem.indexOf(u8, actual_h, expected_line) == null) {1011 if (mem.indexOf(u8, actual_h, expected_line) == null) {
1013 warn(1012 std.debug.print(
1014 \\1013 \\
1015 \\========= Expected this output: ================1014 \\========= Expected this output: ================
1016 \\{s}1015 \\{s}
...@@ -1021,7 +1020,7 @@ pub const GenHContext = struct {...@@ -1021,7 +1020,7 @@ pub const GenHContext = struct {
1021 return error.TestFailed;1020 return error.TestFailed;
1022 }1021 }
1023 }1022 }
1024 warn("OK\n", .{});1023 std.debug.print("OK\n", .{});
1025 }1024 }
1026 };1025 };
10271026
...@@ -1077,7 +1076,7 @@ pub const GenHContext = struct {...@@ -1077,7 +1076,7 @@ pub const GenHContext = struct {
10771076
1078fn printInvocation(args: []const []const u8) void {1077fn printInvocation(args: []const []const u8) void {
1079 for (args) |arg| {1078 for (args) |arg| {
1080 warn("{s} ", .{arg});1079 std.debug.print("{s} ", .{arg});
1081 }1080 }
1082 warn("\n", .{});1081 std.debug.print("\n", .{});
1083}1082}
tools/process_headers.zig+13-13
...@@ -295,7 +295,7 @@ pub fn main() !void {...@@ -295,7 +295,7 @@ pub fn main() !void {
295 if (std.mem.eql(u8, args[arg_i], "--help"))295 if (std.mem.eql(u8, args[arg_i], "--help"))
296 usageAndExit(args[0]);296 usageAndExit(args[0]);
297 if (arg_i + 1 >= args.len) {297 if (arg_i + 1 >= args.len) {
298 std.debug.warn("expected argument after '{s}'\n", .{args[arg_i]});298 std.debug.print("expected argument after '{s}'\n", .{args[arg_i]});
299 usageAndExit(args[0]);299 usageAndExit(args[0]);
300 }300 }
301301
...@@ -308,7 +308,7 @@ pub fn main() !void {...@@ -308,7 +308,7 @@ pub fn main() !void {
308 assert(opt_abi == null);308 assert(opt_abi == null);
309 opt_abi = args[arg_i + 1];309 opt_abi = args[arg_i + 1];
310 } else {310 } else {
311 std.debug.warn("unrecognized argument: {s}\n", .{args[arg_i]});311 std.debug.print("unrecognized argument: {s}\n", .{args[arg_i]});
312 usageAndExit(args[0]);312 usageAndExit(args[0]);
313 }313 }
314314
...@@ -322,7 +322,7 @@ pub fn main() !void {...@@ -322,7 +322,7 @@ pub fn main() !void {
322 else if (std.mem.eql(u8, abi_name, "glibc"))322 else if (std.mem.eql(u8, abi_name, "glibc"))
323 LibCVendor.glibc323 LibCVendor.glibc
324 else {324 else {
325 std.debug.warn("unrecognized C ABI: {s}\n", .{abi_name});325 std.debug.print("unrecognized C ABI: {s}\n", .{abi_name});
326 usageAndExit(args[0]);326 usageAndExit(args[0]);
327 };327 };
328 const generic_name = try std.fmt.allocPrint(allocator, "generic-{s}", .{abi_name});328 const generic_name = try std.fmt.allocPrint(allocator, "generic-{s}", .{abi_name});
...@@ -393,7 +393,7 @@ pub fn main() !void {...@@ -393,7 +393,7 @@ pub fn main() !void {
393 if (gop.found_existing) {393 if (gop.found_existing) {
394 max_bytes_saved += raw_bytes.len;394 max_bytes_saved += raw_bytes.len;
395 gop.value_ptr.hit_count += 1;395 gop.value_ptr.hit_count += 1;
396 std.debug.warn("duplicate: {s} {s} ({:2})\n", .{396 std.debug.print("duplicate: {s} {s} ({:2})\n", .{
397 libc_target.name,397 libc_target.name,
398 rel_path,398 rel_path,
399 std.fmt.fmtIntSizeDec(raw_bytes.len),399 std.fmt.fmtIntSizeDec(raw_bytes.len),
...@@ -415,16 +415,16 @@ pub fn main() !void {...@@ -415,16 +415,16 @@ pub fn main() !void {
415 };415 };
416 try target_to_hash.putNoClobber(dest_target, hash);416 try target_to_hash.putNoClobber(dest_target, hash);
417 },417 },
418 else => std.debug.warn("warning: weird file: {s}\n", .{full_path}),418 else => std.debug.print("warning: weird file: {s}\n", .{full_path}),
419 }419 }
420 }420 }
421 }421 }
422 break;422 break;
423 } else {423 } else {
424 std.debug.warn("warning: libc target not found: {s}\n", .{libc_target.name});424 std.debug.print("warning: libc target not found: {s}\n", .{libc_target.name});
425 }425 }
426 }426 }
427 std.debug.warn("summary: {:2} could be reduced to {:2}\n", .{427 std.debug.print("summary: {:2} could be reduced to {:2}\n", .{
428 std.fmt.fmtIntSizeDec(total_bytes),428 std.fmt.fmtIntSizeDec(total_bytes),
429 std.fmt.fmtIntSizeDec(total_bytes - max_bytes_saved),429 std.fmt.fmtIntSizeDec(total_bytes - max_bytes_saved),
430 });430 });
...@@ -456,7 +456,7 @@ pub fn main() !void {...@@ -456,7 +456,7 @@ pub fn main() !void {
456 if (contender.hit_count > 1) {456 if (contender.hit_count > 1) {
457 const this_missed_bytes = contender.hit_count * contender.bytes.len;457 const this_missed_bytes = contender.hit_count * contender.bytes.len;
458 missed_opportunity_bytes += this_missed_bytes;458 missed_opportunity_bytes += this_missed_bytes;
459 std.debug.warn("Missed opportunity ({:2}): {s}\n", .{459 std.debug.print("Missed opportunity ({:2}): {s}\n", .{
460 std.fmt.fmtIntSizeDec(this_missed_bytes),460 std.fmt.fmtIntSizeDec(this_missed_bytes),
461 path_kv.key_ptr.*,461 path_kv.key_ptr.*,
462 });462 });
...@@ -486,10 +486,10 @@ pub fn main() !void {...@@ -486,10 +486,10 @@ pub fn main() !void {
486}486}
487487
488fn usageAndExit(arg0: []const u8) noreturn {488fn usageAndExit(arg0: []const u8) noreturn {
489 std.debug.warn("Usage: {s} [--search-path <dir>] --out <dir> --abi <name>\n", .{arg0});489 std.debug.print("Usage: {s} [--search-path <dir>] --out <dir> --abi <name>\n", .{arg0});
490 std.debug.warn("--search-path can be used any number of times.\n", .{});490 std.debug.print("--search-path can be used any number of times.\n", .{});
491 std.debug.warn(" subdirectories of search paths look like, e.g. x86_64-linux-gnu\n", .{});491 std.debug.print(" subdirectories of search paths look like, e.g. x86_64-linux-gnu\n", .{});
492 std.debug.warn("--out is a dir that will be created, and populated with the results\n", .{});492 std.debug.print("--out is a dir that will be created, and populated with the results\n", .{});
493 std.debug.warn("--abi is either musl or glibc\n", .{});493 std.debug.print("--abi is either musl or glibc\n", .{});
494 std.process.exit(1);494 std.process.exit(1);
495}495}
tools/update-linux-headers.zig+11-11
...@@ -141,7 +141,7 @@ pub fn main() !void {...@@ -141,7 +141,7 @@ pub fn main() !void {
141 if (std.mem.eql(u8, args[arg_i], "--help"))141 if (std.mem.eql(u8, args[arg_i], "--help"))
142 usageAndExit(args[0]);142 usageAndExit(args[0]);
143 if (arg_i + 1 >= args.len) {143 if (arg_i + 1 >= args.len) {
144 std.debug.warn("expected argument after '{s}'\n", .{args[arg_i]});144 std.debug.print("expected argument after '{s}'\n", .{args[arg_i]});
145 usageAndExit(args[0]);145 usageAndExit(args[0]);
146 }146 }
147147
...@@ -151,7 +151,7 @@ pub fn main() !void {...@@ -151,7 +151,7 @@ pub fn main() !void {
151 assert(opt_out_dir == null);151 assert(opt_out_dir == null);
152 opt_out_dir = args[arg_i + 1];152 opt_out_dir = args[arg_i + 1];
153 } else {153 } else {
154 std.debug.warn("unrecognized argument: {s}\n", .{args[arg_i]});154 std.debug.print("unrecognized argument: {s}\n", .{args[arg_i]});
155 usageAndExit(args[0]);155 usageAndExit(args[0]);
156 }156 }
157157
...@@ -208,7 +208,7 @@ pub fn main() !void {...@@ -208,7 +208,7 @@ pub fn main() !void {
208 if (gop.found_existing) {208 if (gop.found_existing) {
209 max_bytes_saved += raw_bytes.len;209 max_bytes_saved += raw_bytes.len;
210 gop.value_ptr.hit_count += 1;210 gop.value_ptr.hit_count += 1;
211 std.debug.warn("duplicate: {s} {s} ({:2})\n", .{211 std.debug.print("duplicate: {s} {s} ({:2})\n", .{
212 linux_target.name,212 linux_target.name,
213 rel_path,213 rel_path,
214 std.fmt.fmtIntSizeDec(raw_bytes.len),214 std.fmt.fmtIntSizeDec(raw_bytes.len),
...@@ -230,16 +230,16 @@ pub fn main() !void {...@@ -230,16 +230,16 @@ pub fn main() !void {
230 };230 };
231 try target_to_hash.putNoClobber(dest_target, hash);231 try target_to_hash.putNoClobber(dest_target, hash);
232 },232 },
233 else => std.debug.warn("warning: weird file: {s}\n", .{full_path}),233 else => std.debug.print("warning: weird file: {s}\n", .{full_path}),
234 }234 }
235 }235 }
236 }236 }
237 break;237 break;
238 } else {238 } else {
239 std.debug.warn("warning: libc target not found: {s}\n", .{linux_target.name});239 std.debug.print("warning: libc target not found: {s}\n", .{linux_target.name});
240 }240 }
241 }241 }
242 std.debug.warn("summary: {:2} could be reduced to {:2}\n", .{242 std.debug.print("summary: {:2} could be reduced to {:2}\n", .{
243 std.fmt.fmtIntSizeDec(total_bytes),243 std.fmt.fmtIntSizeDec(total_bytes),
244 std.fmt.fmtIntSizeDec(total_bytes - max_bytes_saved),244 std.fmt.fmtIntSizeDec(total_bytes - max_bytes_saved),
245 });245 });
...@@ -271,7 +271,7 @@ pub fn main() !void {...@@ -271,7 +271,7 @@ pub fn main() !void {
271 if (contender.hit_count > 1) {271 if (contender.hit_count > 1) {
272 const this_missed_bytes = contender.hit_count * contender.bytes.len;272 const this_missed_bytes = contender.hit_count * contender.bytes.len;
273 missed_opportunity_bytes += this_missed_bytes;273 missed_opportunity_bytes += this_missed_bytes;
274 std.debug.warn("Missed opportunity ({:2}): {s}\n", .{274 std.debug.print("Missed opportunity ({:2}): {s}\n", .{
275 std.fmt.fmtIntSizeDec(this_missed_bytes),275 std.fmt.fmtIntSizeDec(this_missed_bytes),
276 path_kv.key_ptr.*,276 path_kv.key_ptr.*,
277 });277 });
...@@ -297,9 +297,9 @@ pub fn main() !void {...@@ -297,9 +297,9 @@ pub fn main() !void {
297}297}
298298
299fn usageAndExit(arg0: []const u8) noreturn {299fn usageAndExit(arg0: []const u8) noreturn {
300 std.debug.warn("Usage: {s} [--search-path <dir>] --out <dir> --abi <name>\n", .{arg0});300 std.debug.print("Usage: {s} [--search-path <dir>] --out <dir> --abi <name>\n", .{arg0});
301 std.debug.warn("--search-path can be used any number of times.\n", .{});301 std.debug.print("--search-path can be used any number of times.\n", .{});
302 std.debug.warn(" subdirectories of search paths look like, e.g. x86_64-linux-gnu\n", .{});302 std.debug.print(" subdirectories of search paths look like, e.g. x86_64-linux-gnu\n", .{});
303 std.debug.warn("--out is a dir that will be created, and populated with the results\n", .{});303 std.debug.print("--out is a dir that will be created, and populated with the results\n", .{});
304 std.process.exit(1);304 std.process.exit(1);
305}305}
tools/update_cpu_features.zig+3-3
...@@ -875,16 +875,16 @@ fn processOneTarget(job: Job) anyerror!void {...@@ -875,16 +875,16 @@ fn processOneTarget(job: Job) anyerror!void {
875 });875 });
876 tblgen_progress.end();876 tblgen_progress.end();
877 if (child_result.stderr.len != 0) {877 if (child_result.stderr.len != 0) {
878 std.debug.warn("{s}\n", .{child_result.stderr});878 std.debug.print("{s}\n", .{child_result.stderr});
879 }879 }
880880
881 const json_text = switch (child_result.term) {881 const json_text = switch (child_result.term) {
882 .Exited => |code| if (code == 0) child_result.stdout else {882 .Exited => |code| if (code == 0) child_result.stdout else {
883 std.debug.warn("llvm-tblgen exited with code {d}\n", .{code});883 std.debug.print("llvm-tblgen exited with code {d}\n", .{code});
884 std.process.exit(1);884 std.process.exit(1);
885 },885 },
886 else => {886 else => {
887 std.debug.warn("llvm-tblgen crashed\n", .{});887 std.debug.print("llvm-tblgen crashed\n", .{});
888 std.process.exit(1);888 std.process.exit(1);
889 },889 },
890 };890 };
tools/update_glibc.zig+1-1
...@@ -185,7 +185,7 @@ pub fn main() !void {...@@ -185,7 +185,7 @@ pub fn main() !void {
185 };185 };
186 const max_bytes = 10 * 1024 * 1024;186 const max_bytes = 10 * 1024 * 1024;
187 const contents = std.fs.cwd().readFileAlloc(allocator, abi_list_filename, max_bytes) catch |err| {187 const contents = std.fs.cwd().readFileAlloc(allocator, abi_list_filename, max_bytes) catch |err| {
188 std.debug.warn("unable to open {s}: {}\n", .{ abi_list_filename, err });188 std.debug.print("unable to open {s}: {}\n", .{ abi_list_filename, err });
189 std.process.exit(1);189 std.process.exit(1);
190 };190 };
191 var lines_it = std.mem.tokenize(u8, contents, "\n");191 var lines_it = std.mem.tokenize(u8, contents, "\n");