zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 30698b03c0420e897244441a60a8a8d1a4ade9f4 (tree)
parent 71f23402bcbb8554d5663ac5aa870abd69fda10f
Author: linus <mail@linusgroh.de>
Date:   Tue, 19 May 2026 11:41:52 +0200

Merge pull request 'std: Remove more deprecated functions' (#35253) from linus/zig:more-deprecations into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35253

Diffstat:
Mlib/compiler/aro/aro/Preprocessor.zig | 4++--
Mlib/compiler/aro/backend/Ir/x86/Renderer.zig | 6+++---
Mlib/compiler_rt/float_from_int.zig | 2+-
Mlib/compiler_rt/int_from_float.zig | 2+-
Mlib/std/Io/Threaded.zig | 2+-
Mlib/std/ascii.zig | 9---------
Mlib/std/bit_set.zig | 24------------------------
Mlib/std/enums.zig | 12------------
Mlib/std/mem.zig | 47+++++++++--------------------------------------
Msrc/Package/Fetch.zig | 4++--
Msrc/codegen/x86_64/CodeGen.zig | 4+---
11 files changed, 20 insertions(+), 96 deletions(-)

diff --git a/lib/compiler/aro/aro/Preprocessor.zig b/lib/compiler/aro/aro/Preprocessor.zig @@ -45,11 +45,11 @@ const IfContext = struct { level: u8, fn get(self: *const IfContext) Nesting { - return @enumFromInt(std.mem.readPackedIntNative(Backing, &self.kind, @as(usize, self.level) * 2)); + return @enumFromInt(std.mem.readPackedInt(Backing, &self.kind, @as(usize, self.level) * 2, .native)); } fn set(self: *IfContext, context: Nesting) void { - std.mem.writePackedIntNative(Backing, &self.kind, @as(usize, self.level) * 2, @intFromEnum(context)); + std.mem.writePackedInt(Backing, &self.kind, @as(usize, self.level) * 2, @intFromEnum(context), .native); } fn increment(self: *IfContext) bool { diff --git a/lib/compiler/aro/backend/Ir/x86/Renderer.zig b/lib/compiler/aro/backend/Ir/x86/Renderer.zig @@ -21,17 +21,17 @@ const RegisterManager = zig.RegisterManager(Renderer, Register, Ir.Ref, abi.allo const RegisterBitSet = RegisterManager.RegisterBitSet; const RegisterClass = struct { const gp: RegisterBitSet = blk: { - var set = RegisterBitSet.initEmpty(); + var set: RegisterBitSet = .empty; for (abi.allocatable_regs, 0..) |reg, index| if (reg.class() == .general_purpose) set.set(index); break :blk set; }; const x87: RegisterBitSet = blk: { - var set = RegisterBitSet.initEmpty(); + var set: RegisterBitSet = .empty; for (abi.allocatable_regs, 0..) |reg, index| if (reg.class() == .x87) set.set(index); break :blk set; }; const sse: RegisterBitSet = blk: { - var set = RegisterBitSet.initEmpty(); + var set: RegisterBitSet = .empty; for (abi.allocatable_regs, 0..) |reg, index| if (reg.class() == .sse) set.set(index); break :blk set; }; diff --git a/lib/compiler_rt/float_from_int.zig b/lib/compiler_rt/float_from_int.zig @@ -97,7 +97,7 @@ pub inline fn floatFromBigInt(comptime T: type, comptime signedness: std.builtin if (limb(x, limb_index) != 0) break true; } else limb(x, exponent_limb) & ((@as(u32, 1) << @truncate(exponent)) - 1) != 0; return math.ldexp(@as(T, @floatFromInt( - std.mem.readPackedIntNative(I, std.mem.sliceAsBytes(x), exponent) | @intFromBool(sticky), + std.mem.readPackedInt(I, std.mem.sliceAsBytes(x), exponent, .native) | @intFromBool(sticky), )), @intCast(exponent)); } diff --git a/lib/compiler_rt/int_from_float.zig b/lib/compiler_rt/int_from_float.zig @@ -141,7 +141,7 @@ pub inline fn bigIntFromFloat(comptime signedness: std.builtin.Signedness, resul }, .unsigned => @memset(result, 0), } - std.mem.writePackedIntNative(I, std.mem.sliceAsBytes(result), exponent, int); + std.mem.writePackedInt(I, std.mem.sliceAsBytes(result), exponent, int, .native); } test { diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig @@ -14401,7 +14401,7 @@ pub fn setTimestampToPosix(set_ts: File.SetTimestamp) posix.timespec { } pub fn pathToPosix(file_path: []const u8, buffer: *[posix.PATH_MAX]u8) Dir.PathNameError![:0]u8 { - if (std.mem.containsAtLeastScalar2(u8, file_path, 0, 1)) return error.BadPathName; + if (std.mem.containsAtLeastScalar(u8, file_path, 0, 1)) return error.BadPathName; // >= rather than > to make room for the null byte if (file_path.len >= buffer.len) return error.NameTooLong; @memcpy(buffer[0..file_path.len], file_path); diff --git a/lib/std/ascii.zig b/lib/std/ascii.zig @@ -378,17 +378,11 @@ test endsWithIgnoreCase { try std.testing.expect(!endsWithIgnoreCase("BoB", "Bo")); } -/// Deprecated in favor of `findIgnoreCase`. -pub const indexOfIgnoreCase = findIgnoreCase; - /// Finds `needle` in `haystack`, ignoring case, starting at index 0. pub fn findIgnoreCase(haystack: []const u8, needle: []const u8) ?usize { return findIgnoreCasePos(haystack, 0, needle); } -/// Deprecated in favor of `findIgnoreCasePos`. -pub const indexOfIgnoreCasePos = findIgnoreCasePos; - /// Finds `needle` in `haystack`, ignoring case, starting at `start_index`. /// Uses Boyer-Moore-Horspool algorithm on large inputs; `findIgnoreCasePosLinear` on small inputs. pub fn findIgnoreCasePos(haystack: []const u8, start_index: usize, needle: []const u8) ?usize { @@ -410,9 +404,6 @@ pub fn findIgnoreCasePos(haystack: []const u8, start_index: usize, needle: []con return null; } -/// Deprecated in favor of `findIgnoreCaseLinear`. -pub const indexOfIgnoreCasePosLinear = findIgnoreCasePosLinear; - /// Consider using `findIgnoreCasePos` instead of this, which will automatically use a /// more sophisticated algorithm on larger inputs. pub fn findIgnoreCasePosLinear(haystack: []const u8, start_index: usize, needle: []const u8) ?usize { diff --git a/lib/std/bit_set.zig b/lib/std/bit_set.zig @@ -73,18 +73,6 @@ pub fn Integer(comptime size: u16) type { /// The bit mask, as a single integer mask: MaskInt, - /// Deprecated: use `.empty`. - /// Creates a bit set with no elements present. - pub fn initEmpty() Self { - return .{ .mask = 0 }; - } - - /// Deprecated: use `.full`. - /// Creates a bit set with all elements present. - pub fn initFull() Self { - return .{ .mask = ~@as(MaskInt, 0) }; - } - /// A bit set with no elements present. pub const empty: Self = .{ .mask = 0 }; @@ -403,18 +391,6 @@ pub fn Array(comptime MaskIntType: type, comptime size: usize) type { /// Padding bits at the end are undefined. masks: [num_masks]MaskInt, - /// Deprecated: use `.empty`. - /// Creates a bit set with no elements present. - pub fn initEmpty() Self { - return .empty; - } - - /// Deprecated: use `.full`. - /// Creates a bit set with all elements present. - pub fn initFull() Self { - return .full; - } - /// A bit set with no elements present. pub const empty: Self = .{ .masks = @splat(0) }; diff --git a/lib/std/enums.zig b/lib/std/enums.zig @@ -284,18 +284,6 @@ pub fn EnumSet(comptime E: type) type { /// A set containing all possible keys. pub const full: Self = .{ .bits = .full }; - /// Deprecated: use `.empty`. - /// Returns a set containing no keys. - pub fn initEmpty() Self { - return .empty; - } - - /// Deprecated: use `.full`. - /// Returns a set containing all possible keys. - pub fn initFull() Self { - return .full; - } - /// Returns a set containing multiple keys. pub fn initMany(keys: []const Key) Self { var set: Self = .empty; diff --git a/lib/std/mem.zig b/lib/std/mem.zig @@ -1691,7 +1691,7 @@ test countScalar { // /// See also: `containsAtLeastScalar` pub fn containsAtLeast(comptime T: type, haystack: []const T, expected_count: usize, needle: []const T) bool { - if (needle.len == 1) return containsAtLeastScalar(T, haystack, expected_count, needle[0]); + if (needle.len == 1) return containsAtLeastScalar(T, haystack, needle[0], expected_count); assert(needle.len > 0); if (expected_count == 0) return true; @@ -1722,17 +1722,12 @@ test containsAtLeast { try testing.expect(!containsAtLeast(u8, " radar radar ", 3, "radar")); } -/// Deprecated in favor of `containsAtLeastScalar2`. -pub fn containsAtLeastScalar(comptime T: type, list: []const T, minimum: usize, element: T) bool { - return containsAtLeastScalar2(T, list, element, minimum); -} - /// Returns true if `element` appears at least `minimum` number of times in `list`. // /// Related: /// * `containsAtLeast` /// * `countScalar` -pub fn containsAtLeastScalar2(comptime T: type, list: []const T, element: T, minimum: usize) bool { +pub fn containsAtLeastScalar(comptime T: type, list: []const T, element: T, minimum: usize) bool { const n = list.len; var i: usize = 0; var found: usize = 0; @@ -1760,14 +1755,14 @@ pub fn containsAtLeastScalar2(comptime T: type, list: []const T, element: T, min return false; } -test containsAtLeastScalar2 { - try testing.expect(containsAtLeastScalar2(u8, "aa", 'a', 0)); - try testing.expect(containsAtLeastScalar2(u8, "aa", 'a', 1)); - try testing.expect(containsAtLeastScalar2(u8, "aa", 'a', 2)); - try testing.expect(!containsAtLeastScalar2(u8, "aa", 'a', 3)); +test containsAtLeastScalar { + try testing.expect(containsAtLeastScalar(u8, "aa", 'a', 0)); + try testing.expect(containsAtLeastScalar(u8, "aa", 'a', 1)); + try testing.expect(containsAtLeastScalar(u8, "aa", 'a', 2)); + try testing.expect(!containsAtLeastScalar(u8, "aa", 'a', 3)); - try testing.expect(containsAtLeastScalar2(u8, "adadda", 'd', 3)); - try testing.expect(!containsAtLeastScalar2(u8, "adadda", 'd', 4)); + try testing.expect(containsAtLeastScalar(u8, "adadda", 'd', 3)); + try testing.expect(!containsAtLeastScalar(u8, "adadda", 'd', 4)); } /// Reads an integer from memory with size equal to bytes.len. @@ -1973,18 +1968,6 @@ fn readPackedIntBig(comptime T: type, bytes: []const u8, bit_offset: usize) T { } else return @as(T, @bitCast(val)); } -/// Deprecated: use readPackedInt(T, bytes, bit_offset, value, .native) -pub const readPackedIntNative = switch (native_endian) { - .little => readPackedIntLittle, - .big => readPackedIntBig, -}; - -/// Deprecated: use readPackedInt(T, bytes, bit_offset, value, .foreign) -pub const readPackedIntForeign = switch (native_endian) { - .little => readPackedIntBig, - .big => readPackedIntLittle, -}; - /// Loads an integer from packed memory. /// Asserts that buffer contains at least bit_offset + @bitSizeOf(T) bits. pub fn readPackedInt(comptime T: type, bytes: []const u8, bit_offset: usize, endian: Endian) T { @@ -2128,18 +2111,6 @@ fn writePackedIntBig(comptime T: type, bytes: []u8, bit_offset: usize, value: T) writeInt(StoreInt, write_bytes[(byte_count - store_size)..][0..store_size], write_value, .big); } -/// Deprecated: use writePackedInt(T, bytes, bit_offset, value, .native) -pub const writePackedIntNative = switch (native_endian) { - .little => writePackedIntLittle, - .big => writePackedIntBig, -}; - -/// Deprecated: use writePackedInt(T, bytes, bit_offset, value, .foreign) -pub const writePackedIntForeign = switch (native_endian) { - .little => writePackedIntBig, - .big => writePackedIntLittle, -}; - /// Stores an integer to packed memory. /// Asserts that buffer contains at least bit_offset + @bitSizeOf(T) bits. pub fn writePackedInt(comptime T: type, bytes: []u8, bit_offset: usize, value: T, endian: Endian) void { diff --git a/src/Package/Fetch.zig b/src/Package/Fetch.zig @@ -1151,10 +1151,10 @@ const FileType = enum { /// Parameter is a content-disposition header value. fn fromContentDisposition(cd_header: []const u8) ?FileType { - const attach_end = ascii.indexOfIgnoreCase(cd_header, "attachment;") orelse + const attach_end = ascii.findIgnoreCase(cd_header, "attachment;") orelse return null; - var value_start = ascii.indexOfIgnoreCasePos(cd_header, attach_end + 1, "filename") orelse + var value_start = ascii.findIgnoreCasePos(cd_header, attach_end + 1, "filename") orelse return null; value_start += "filename".len; if (cd_header[value_start] == '*') { diff --git a/src/codegen/x86_64/CodeGen.zig b/src/codegen/x86_64/CodeGen.zig @@ -187562,9 +187562,7 @@ const Temp = struct { const max = std.math.maxInt(@typeInfo(Index).@"enum".tag_type); const Set = std.bit_set.Static(max); const SafetySet = if (std.debug.runtime_safety) Set else struct { - inline fn initEmpty() @This() { - return .{}; - } + pub const empty: @This() = .{}; inline fn isSet(_: @This(), index: usize) bool { assert(index < max);