0
Fork 0
mirror of https://codeberg.org/ziglang/zig synced 2026-11-18 07:05:05 +00:00
Commit graph

177 commits

Author SHA1 Message Date
Andrew Kelley
11d3e2515d std.ArrayList: add "see also" doc comment 2026-09-16 13:12:46 -07:00
Scott Redig
e90365cd51 Remove deprecation notice for already removed deprecation 2026-09-12 00:07:10 +02:00
Jay Petacat
d7148f7d05 std.debug.SafetyLock: add support for shared locking
The existing `lock` and `unlock` methods continue to act exclusively.
They should be used when data may be mutated. New methods, `lockShared`
and `unlockShared`, may be used for shared locking in situations where
multiple independent users are reading but not mutating data.
2026-09-09 02:18:52 +02:00
Andrew Kelley
d26018b0f4 Merge pull request 'feat: add pointer stability to ArrayList' (#36239) from robbielyman/zig:push-tuqlrxoruyww into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/36239
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-08-27 21:33:23 +02:00
Matthias Portzel
18e38104ce Re-add deprecated getLast and getLastOrNull 2026-08-25 22:14:36 +02:00
Robbie Lyman
cad75a7106 fix(ArrayList): clarify pointer stability rules
This commit also makes `pointer_stability` a non default init.
This was done initially to verify that methods like `toManaged` behave
properly with respect to pointer stability, but does require changes
outside of `array_list.zig`. Initialization with `init()` or
`.empty` appears to be preferred enough that this is minimally breaking.
2026-08-09 13:02:43 -04:00
Saurabh Mishra
21f2381438 std.ArrayListUnmanaged: last and lastPtr methods (#36318)
ArrayList:

- `getLastOrNull` has been deprecated and renamed to `last`
- `getLast` has been removed in favor of `last` combined with `.?`
- `lastPtr` has been added which returns `?*T`

Upgrade guide:

```zig
if (list.getLastOrNull()) |foo| {
    // ...
}
const foo = list.getLast();
```
⬇️
```zig
if (list.last()) |foo| {
    // ...
}
const foo = list.last().?;
```

Co-authored-by: Ryan Liptak <squeek502@hotmail.com>
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/36318
Reviewed-by: Ryan Liptak <squeek502@noreply.codeberg.org>
2026-08-07 07:30:10 +02:00
K4
4e5ce9909a std: add test for ArrayList(u0).toOwnedSlice()
Closes https://github.com/ziglang/zig/issues/22483
2026-07-28 21:00:28 +02:00
Robbie Lyman
ccbfd60e32 feat: add pointer_stability field to ArrayList 2026-07-19 20:46:22 -04:00
Andrew Kelley
c678f94daa std.array_list: add last method, deprecated getLast 2026-05-25 18:54:36 -07:00
Andrew Kelley
a06f23c8ea std.array_list: fix doc comment references
allows autodoc to make these hyperlinks
2026-05-22 22:27:35 -07:00
Saurabh Mishra
d02d0b879c std:ArrayList: Merge getLastOrNull into getLast (#32008)
This PR merges the functionality of the `getLastOrNull` method into `getLast`, which improves consistency as its
based on methods like `front`, `back`, and `peek` in the `Deque` and `PriorityQueue` containers.

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/32008
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-05-02 02:26:15 +02:00
Hila Friedman
746dd51faf Simplify std.ArrayList.replaceRange and std.ArrayList.replaceRangeAssumeCapacity (#31710)
The implementations of `std.ArrayList.replaceRange` and `std.ArrayList.replaceRangeAssumeCapacity` were needlessly complicated, called `@memcpy` too many times, and left the structure in a semi-modified state in OOM conditions. This commit fixes that.

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31710
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: Hila Friedman <red.black.liquorice@gmail.com>
Co-committed-by: Hila Friedman <red.black.liquorice@gmail.com>
2026-04-02 15:11:24 +02:00
andrew.kraevskiii
47597a6d7c std.ArrayList: add toOwnedSliceAssert, shrinkToLen. (#30769)
Adds a set of new APIs to ArrayList with goal of making it easier to avoid toOwnedSlice foot gun:

```zig
fn wrongUsageOfCurrentApi(gpa: std.mem.Allocator) ![2][]const u8 {
    var a: std.ArrayList(u8) = .empty;
    defer a.deinit(gpa);
    var b: std.ArrayList(u8) = .empty;
    defer b.deinit(gpa);

    // ...

    return .{
        try a.toOwnedSlice(gpa),
        try b.toOwnedSlice(gpa), // oom here causes leak :(
    };
}

fn correctUsageOfCurrentApi(gpa: std.mem.Allocator) ![2][]const u8 {
    var a: std.ArrayList(u8) = .empty;
    defer a.deinit(gpa);
    var b: std.ArrayList(u8) = .empty;
    defer b.deinit(gpa);

    // ...

    const a_slice = try a.toOwnedSlice(gpa);
    errdefer gpa.free(a_slice);
    const b_slice = try b.toOwnedSlice(gpa);
    // may be omited but good if error appear bellow later in development.
    errdefer gpa.free(b_slice);

    return .{
        a_slice,
        b_slice,
    };
}

fn proposedApi(gpa: std.mem.Allocator) ![2][]const u8 {
    var a: std.ArrayList(u8) = .empty;
    defer a.deinit(gpa);
    var b: std.ArrayList(u8) = .empty;
    defer b.deinit(gpa);

    // ...

    try a.shrinkToLen(gpa);
    try b.shrinkToLen(gpa);
    return .{
        a.toOwnedSliceAssert(),
        b.toOwnedSliceAssert(),
    };
}
```

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30769
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: andrew.kraevskiii <andrew.kraevskii@gmail.com>
Co-committed-by: andrew.kraevskiii <andrew.kraevskii@gmail.com>
2026-03-12 20:50:27 +01:00
Matthew Lugg
8eefe86939
std: remove default values from ArrayList
These were deprecated in the 0.14.0 release cycle almost a year ago, so
they can definitely be deleted now.
2026-03-10 10:26:08 +00:00
Nils Koch
6473dc22fc std.ArrayList: Fix compile error when @sizeOf(T) == 0 2026-02-09 19:59:09 +01:00
Rue04
86a9a9048e std.MultiArrayList: add *Bounded variants and initCapacity
Because I accidentially squished two commit and can't figure out how to separate them
again, this also
- standardizes some doc-comments
- makes a slight change to `std.ArrayList`'s `initCapacity`'s doc-comment
2026-01-04 03:05:34 +01:00
Mateusz Poliwczak
b2895f356f std.ArrayList: actaully memset to undefined in shrinkRetainingCapacity and clearRetainingCapacity
See #25810
2025-11-06 05:30:41 -08:00
Mateusz Poliwczak
416bf1de47 std.ArrayList: memset to undefined in shrinkRetainingCapacity and clearRetainingCapacity
Fixes #25796
2025-11-05 19:31:19 -08:00
Fri3dNstuff
87c18945c2
std.ArrayList: swapRemove set removed element to undefined (#25514) 2025-10-11 19:04:32 -07:00
Andrew Kelley
0c1fbc4ea6 std: remove loop from growCapacity
I measured this against master branch and found no statistical
difference. Since this code is simpler and logically superior due to
always leaving sufficient unused capacity when growing, it is preferred
over status quo.
2025-09-20 14:34:18 -07:00
Andrew Kelley
fadd268a60 upgrade more old API uses 2025-08-30 00:48:50 -07:00
Andrew Kelley
9a0970a12b rework std.Io.Writer.Allocating to support runtime-known alignment
Also, breaking API changes to:
* std.fs.Dir.readFileAlloc
* std.fs.Dir.readFileAllocOptions
2025-08-30 00:48:50 -07:00
Andrew Kelley
79f267f6b9 std.Io: delete GenericReader
and delete deprecated alias std.io
2025-08-29 17:14:26 -07:00
Andrew Kelley
9860dd475a std: delete most remaining uses of GenericWriter 2025-08-28 18:30:57 -07:00
Andrew Kelley
57dbc9e74a std.Io: delete GenericWriter 2025-08-28 18:30:57 -07:00
Rue
d57b1e3552
std.ArrayList: add insertSliceAssumeCapacity() and insertSliceBounded() (#24978)
closes #24929
2025-08-26 00:25:25 -07:00
Andrew Kelley
30b41dc510 std.compress.zstd.Decompress fixes
* std.Io.Reader: appendRemaining no longer supports alignment and has
  different rules about how exceeding limit. Fixed bug where it would
  return success instead of error.StreamTooLong like it was supposed to.

* std.Io.Reader: simplify appendRemaining and appendRemainingUnlimited
  to be implemented based on std.Io.Writer.Allocating

* std.Io.Writer: introduce unreachableRebase

* std.Io.Writer: remove minimum_unused_capacity from Allocating. maybe
  that flexibility could have been handy, but let's see if anyone
  actually needs it. The field is redundant with the superlinear growth
  of ArrayList capacity.

* std.Io.Writer: growingRebase also ensures total capacity on the
  preserve parameter, making it no longer necessary to do
  ensureTotalCapacity at the usage site of decompression streams.

* std.compress.flate.Decompress: fix rebase not taking into account seek

* std.compress.zstd.Decompress: split into "direct" and "indirect" usage
  patterns depending on whether a buffer is provided to init, matching
  how flate works. Remove some overzealous asserts that prevented buffer
  expansion from within rebase implementation.

* std.zig: fix readSourceFileToAlloc returning an overaligned slice
  which was difficult to free correctly.

fixes #24608
2025-08-15 10:44:35 -07:00
Andrew Kelley
749f10af49 std.ArrayList: make unmanaged the default 2025-08-11 15:52:49 -07:00
Andrew Kelley
59de7e3a57 std: introduce orderedRemoveMany
This algorithm is non-trivial and makes sense for any data structure
that acts as an array list, so I thought it would make sense as a
method.

I have a real world case for this in a music player application
(deleting queue items).

Adds the method to:
* ArrayList
* ArrayHashMap
* MultiArrayList
2025-08-11 13:32:12 -07:00
Andrew Kelley
196e36bbb2 std: remove BoundedArray
This use case is handled by ArrayListUnmanaged via the "...Bounded"
method variants, and it's more optimal to share machine code, versus
generating multiple versions of each function for differing array
lengths.
2025-08-05 09:56:02 -07:00
Andrew Kelley
c47ec4f3d7 std.array_list: add bounded methods 2025-08-05 09:56:02 -07:00
Andrew Kelley
6f545683f3 std: replace various mem copies with @memmove 2025-08-05 09:56:02 -07:00
Andrew Kelley
fac5fe57be std.io.Writer.Allocating: rename interface to writer 2025-07-07 22:43:52 -07:00
Andrew Kelley
9f27d770a1 std.io: deprecated Reader/Writer; introduce new API 2025-07-07 22:43:51 -07:00
Leonid Emar-Kar
c52d9c6c89 add array list pointer stability 2025-05-26 16:54:39 +01:00
Andrew Kelley
f32a5d349d std: eradicate u29 and embrace std.mem.Alignment 2025-04-13 02:20:32 -04:00
remeh
02f63fdee9 std/containers: improve consistency using gpa parameter name for allocator. 2025-03-09 07:39:20 +01:00
Andrew Kelley
e0129b387f std.ArrayList: delete unit test
tests should use the API, not only verify compilation succeeds.
2025-02-26 11:42:03 -08:00
Andrew Kelley
d12123a88c std.ArrayList: initial capacity based on cache line size
also std.MultiArrayList
2025-02-13 00:19:03 -08:00
Meghan Denny
9142482372
std.ArrayList: popOrNull() -> pop() [v2] (#22720) 2025-02-10 04:21:31 +00:00
Andrew Kelley
7eeef5fb2b std.mem.Allocator: introduce remap function to the interface
This one changes the size of an allocation, allowing it to be relocated.
However, the implementation will still return `null` if it would be
equivalent to

new = alloc
memcpy(new, old)
free(old)

Mainly this prepares for taking advantage of `mremap` which I thought
would be a bigger deal but apparently is only available on Linux. Still,
we should use it on Linux.
2025-02-06 14:23:23 -08:00
Andrew Kelley
b9355edfb1 std.array_list: tiny refactor for pleasure 2025-01-15 15:11:35 -08:00
mlugg
d11bbde5f9
compiler: remove anonymous struct types, unify all tuples
This commit reworks how anonymous struct literals and tuples work.

Previously, an untyped anonymous struct literal
(e.g. `const x = .{ .a = 123 }`) was given an "anonymous struct type",
which is a special kind of struct which coerces using structural
equivalence. This mechanism was a holdover from before we used
RLS / result types as the primary mechanism of type inference. This
commit changes the language so that the type assigned here is a "normal"
struct type. It uses a form of equivalence based on the AST node and the
type's structure, much like a reified (`@Type`) type.

Additionally, tuples have been simplified. The distinction between
"simple" and "complex" tuple types is eliminated. All tuples, even those
explicitly declared using `struct { ... }` syntax, use structural
equivalence, and do not undergo staged type resolution. Tuples are very
restricted: they cannot have non-`auto` layouts, cannot have aligned
fields, and cannot have default values with the exception of `comptime`
fields. Tuples currently do not have optimized layout, but this can be
changed in the future.

This change simplifies the language, and fixes some problematic
coercions through pointers which led to unintuitive behavior.

Resolves: #16865
2024-10-31 20:42:53 +00:00
Linus Groh
8588964972 Replace deprecated default initializations with decl literals 2024-09-12 16:01:23 +01:00
mlugg
0b9fccf508
std: deprecate some incorrect default initializations
In favour of newly-added decls, which can be used via decl literals.
2024-09-01 17:34:07 +01:00
Jacob Young
ef11bc9899 Dwarf: rework self-hosted debug info from scratch
This is in preparation for incremental and actually being able to debug
executables built by the x86_64 backend.
2024-08-16 15:22:55 -04:00
gooncreeper
ee6a52b40f
std.ArrayList.unusedCapacitySlice: Return unaligned slice (#20490) 2024-07-14 00:56:29 +00:00
Jora Troosh
13070448f5
std: fix typos (#20560) 2024-07-09 14:25:42 -07:00
Michael Lynch
2a7cedfeb9 Refactor ArrayList replaceRange tests 2024-04-02 13:46:51 -07:00