authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-08-31 02:50:11+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-09-01 17:34:07+01:00
log0b9fccf508dc85fa522947d1cf6ff84f78f2dcb4
tree7371629835c5ee935b33515395f7ad7fbd64c897
parent6e3e23a941c6c82550c41771a223afeec4accd47
signaturelock-open Commit is signed but in an unrecognized format.

std: deprecate some incorrect default initializations

In favour of newly-added decls, which can be used via decl literals.

4 files changed, 36 insertions(+), 0 deletions(-)

lib/std/array_hash_map.zig+8
......@@ -510,6 +510,8 @@ pub fn ArrayHashMap(
510510/// `store_hash` is `false` and the number of entries in the map is less than 9,
511511/// the overhead cost of using `ArrayHashMapUnmanaged` rather than `std.ArrayList` is
512512/// only a single pointer-sized integer.
513///
514/// Default initialization of this struct is deprecated; use `.empty` instead.
513515pub fn ArrayHashMapUnmanaged(
514516 comptime K: type,
515517 comptime V: type,
......@@ -538,6 +540,12 @@ pub fn ArrayHashMapUnmanaged(
538540 /// Used to detect memory safety violations.
539541 pointer_stability: std.debug.SafetyLock = .{},
540542
543 /// A map containing no keys or values.
544 pub const empty: Self = .{
545 .entries = .{},
546 .index_header = null,
547 };
548
541549 /// Modifying the key is allowed only if it does not change the hash.
542550 /// Modifying the value is allowed.
543551 /// Entry pointers become invalid whenever this ArrayHashMap is modified,
lib/std/array_list.zig+8
......@@ -618,6 +618,8 @@ pub fn ArrayListUnmanaged(comptime T: type) type {
618618/// Functions that potentially allocate memory accept an `Allocator` parameter.
619619/// Initialize directly or with `initCapacity`, and deinitialize with `deinit`
620620/// or use `toOwnedSlice`.
621///
622/// Default initialization of this struct is deprecated; use `.empty` instead.
621623pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) type {
622624 if (alignment) |a| {
623625 if (a == @alignOf(T)) {
......@@ -638,6 +640,12 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
638640 /// additional memory.
639641 capacity: usize = 0,
640642
643 /// An ArrayList containing no elements.
644 pub const empty: Self = .{
645 .items = &.{},
646 .capacity = 0,
647 };
648
641649 pub const Slice = if (alignment) |a| ([]align(a) T) else []T;
642650
643651 pub fn SentinelSlice(comptime s: T) type {
lib/std/hash_map.zig+9
......@@ -721,6 +721,8 @@ pub fn HashMap(
721721/// the price of handling size with u32, which should be reasonable enough
722722/// for almost all uses.
723723/// Deletions are achieved with tombstones.
724///
725/// Default initialization of this struct is deprecated; use `.empty` instead.
724726pub fn HashMapUnmanaged(
725727 comptime K: type,
726728 comptime V: type,
......@@ -762,6 +764,13 @@ pub fn HashMapUnmanaged(
762764 /// Capacity of the first grow when bootstrapping the hashmap.
763765 const minimal_capacity = 8;
764766
767 /// A map containing no keys or values.
768 pub const empty: Self = .{
769 .metadata = null,
770 .size = 0,
771 .available = 0,
772 };
773
765774 // This hashmap is specially designed for sizes that fit in a u32.
766775 pub const Size = u32;
767776
lib/std/heap/general_purpose_allocator.zig+11
......@@ -157,6 +157,7 @@ pub const Config = struct {
157157
158158pub const Check = enum { ok, leak };
159159
160/// Default initialization of this struct is deprecated; use `.init` instead.
160161pub fn GeneralPurposeAllocator(comptime config: Config) type {
161162 return struct {
162163 backing_allocator: Allocator = std.heap.page_allocator,
......@@ -174,6 +175,16 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
174175
175176 const Self = @This();
176177
178 /// The initial state of a `GeneralPurposeAllocator`, containing no allocations and backed by the system page allocator.
179 pub const init: Self = .{
180 .backing_allocator = std.heap.page_allocator,
181 .buckets = [1]Buckets{.{}} ** small_bucket_count,
182 .cur_buckets = [1]?*BucketHeader{null} ** small_bucket_count,
183 .large_allocations = .{},
184 .empty_buckets = if (config.retain_metadata) .{} else {},
185 .bucket_node_pool = .init(std.heap.page_allocator),
186 };
187
177188 const total_requested_bytes_init = if (config.enable_memory_limit) @as(usize, 0) else {};
178189 const requested_memory_limit_init = if (config.enable_memory_limit) @as(usize, math.maxInt(usize)) else {};
179190