aboutsummaryrefslogtreecommitdiff
path: root/lib/std/enums.zig
AgeCommit message (Collapse)Author
2025-07-31std.enums: fix `EnumIndexer` branch quotamlugg
It's quite silly to have this override which nonetheless makes assumptions about the input type. Encode the actual complexity of the sort. Also, simplify the sorting logic, and fix a bug (grab min and max *after* the sort, not *before*!)
2025-05-14Revert "Work around stage1 not yet returning null-terminated `@typeInfo` ↵Isaac Freund
strings" This reverts commit c8fa767f083e610840cef688b709783c5ad66acc.
2025-05-13std.meta.intToEnum -> std.enums.fromIntwooster0
Also use an optional as the return type instead of an error code.
2025-04-15Deprecate std.enums.nameCast.Андрей Краевский
2025-03-06std.enums.tagName: preserve sentinel in return value190n
2025-01-16all: update to `std.builtin.Type.{Pointer,Array,StructField}` field renamesmlugg
2024-08-29std: avoid field/decl name conflictsmlugg
Most of these changes seem like improvements. The PDB thing had a TODO saying it used to crash; I anticipate it works now, we'll see what CI does. The `std.os.uefi` field renames are a notable breaking change.
2024-08-28std: update `std.builtin.Type` fields to follow naming conventionsmlugg
The compiler actually doesn't need any functional changes for this: Sema does reification based on the tag indices of `std.builtin.Type` already! So, no zig1.wasm update is necessary. This change is necessary to disallow name clashes between fields and decls on a type, which is a prerequisite of #9938.
2024-08-21std: update eval branch quotas after bdbc485mlugg
Also, update `std.math.Log2Int[Ceil]` to more efficient implementations that don't use up so much damn quota!
2024-05-26EnumMap: fix initJacob Young
2024-03-25compiler: implement analysis-local comptime-mutable memorymlugg
This commit changes how we represent comptime-mutable memory (`comptime var`) in the compiler in order to implement the intended behavior that references to such memory can only exist at comptime. It does *not* clean up the representation of mutable values, improve the representation of comptime-known pointers, or fix the many bugs in the comptime pointer access code. These will be future enhancements. Comptime memory lives for the duration of a single Sema, and is not permitted to escape that one analysis, either by becoming runtime-known or by becoming comptime-known to other analyses. These restrictions mean that we can represent comptime allocations not via Decl, but with state local to Sema - specifically, the new `Sema.comptime_allocs` field. All comptime-mutable allocations, as well as any comptime-known const allocs containing references to such memory, live in here. This allows for relatively fast checking of whether a value references any comptime-mtuable memory, since we need only traverse values up to pointers: pointers to Decls can never reference comptime-mutable memory, and pointers into `Sema.comptime_allocs` always do. This change exposed some faulty pointer access logic in `Value.zig`. I've fixed the important cases, but there are some TODOs I've put in which are definitely possible to hit with sufficiently esoteric code. I plan to resolve these by auditing all direct accesses to pointers (most of them ought to use Sema to perform the pointer access!), but for now this is sufficient for all realistic code and to get tests passing. This change eliminates `Zcu.tmp_hack_arena`, instead using the Sema arena for comptime memory mutations, which is possible since comptime memory is now local to the current Sema. This change should allow `Decl` to store only an `InternPool.Index` rather than a full-blown `ty: Type, val: Value`. This commit does not perform this refactor.
2024-03-24std.enums: fix EnumSet.init and EnumMap.init for non-exhaustive enumsSimon Brown
2024-03-12Avoid comptime concatenation in `EnumFieldStruct`Carl Åstholm
2024-03-12Move big enum tests to a standalone test caseCarl Åstholm
2024-03-12std.enums: Increase eval branch quotasCarl Åstholm
2024-03-11std.builtin: make container layout fields lowercaseTristan Ross
2024-03-08std.enums: remove IndexedMap, IndexedArray, IndexedSetmlugg
Searching GitHub indicated that the only use of these types in the wild is support in getty-zig, and testing for that support. This eliminates 3 more uses of usingnamespace from the standard library, and removes some unnecessarily complex generic code.
2024-02-26Change many test blocks to doctests/decltestsRyan Liptak
2024-02-26Remove redundant test name prefixes now that test names are fully qualifiedRyan Liptak
Follow up to #19079, which made test names fully qualified. This fixes tests that now-redundant information in their test names. For example here's a fully qualified test name before the changes in this commit: "priority_queue.test.std.PriorityQueue: shrinkAndFree" and the same test's name after the changes in this commit: "priority_queue.test.shrinkAndFree"
2024-01-07Work around stage1 not yet returning null-terminated `@typeInfo` stringsCarl Åstholm
These changes can be reverted the next time stage1 is updated.
2024-01-02Fix std.enums.valuesPanSashko
Current implementation fails to handle the following enum ```zig const E = enum { X, pub const X = 1; } ``` because `@field(type, name)` prefers declarations over enum fields.
2023-12-11Add `getPtrConstAssertContains(...)` for compatibility with a `const` ↵Eric Eastwood
`std.EnumMap` This way people can use `const` with a `std.EnumMap` and be able to `getPtrAssertContains(...)` like the would with a mutable `var` instance. Aligns with the existing `getPtr(...)`/`getPtrConst(...)` methods.
2023-11-22std: remove meta.traitAndrew Kelley
In general, I don't like the idea of std.meta.trait, and so I am providing some guidance by deleting the entire namespace from the standard library and compiler codebase. My main criticism is that it's overcomplicated machinery that bloats compile times and is ultimately unnecessary given the existence of Zig's strong type system and reference traces. Users who want this can create a third party package that provides this functionality. closes #18051
2023-11-19lib: correct unnecessary uses of 'var'mlugg
2023-11-18std.enums: allow non-exhaustive enums in EnumIndexer and make `count` ↵Eric Joldasov
comptime_int instead of usize Seems like this restriction was actual when Ziglang had extern enums, but now it's not neccessary and can be lifted. It was present since original PR which introduced std.enums, https://www.github.com/ziglang/zig/pull/8171. See also: https://ziggit.dev/t/catching-invalid-enum-value-errors/2206/11 * Make `count` comptime_int instead of usize With previous type, creating EnumIndexer for enum(usize) and enum(isize) would cause compile error since `count` could not store maxInt(usize) + 1. Now it can store it and reflects len field from std.builtin.Type.Array (most common use case of count field inside std.enums functions is creating arrays). Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-10-21Fix simple doc mistakes. (#17624)JustinWayland
* Add missing period in Stack's description This looks fine in the source, but looks bad when seen on the documentation website. * Correct documentation for attachSegfaultHandler() The description for attachSegfaultHandler() looks pretty bad without indicating that the stuff at the end is code * Added missing 'the's in Queue.put's documentation * Fixed several errors in Stack's documentation `push()` and `pop()` were not styled as code There was no period after `pop()`, which looks bad on the documentation. * Fix multiple problems in base64.zig Both "invalid"s in Base64.decoder were not capitalized. Missing period in documentation of Base64DecoderWithIgnore.calcSizeUpperBound. * Fix capitalization typos in bit_set.zig In DynamicBitSetUnmanaged.deinit's and DynamicBitSet.deinit's documentation, "deinitializes" was uncapitalized. * Fix typos in fifo.zig's documentation Added a previously missing period to the end of the first line of LinearFifo.writableSlice's documentation. Added missing periods to both lines of LinearFifo.pump's documentation. * Fix typos in fmt.bufPrint's documentation The starts of both lines were not capitalized. * Fix minor documentation problems in fs/file.zig Missing periods in documentation for Permissions.setReadOnly, PermissionsWindows.setReadOnly, MetadataUnix.created, MetadataLinux.created, and MetadataWindows.created. * Fix a glaring typo in enums.zig * Correct errors in fs.zig * Fixed documentation problems in hash_map.zig The added empty line in verify_context's documentation is needed, otherwise autodoc for some reason assumes that the list hasn't been terminated and continues reading off the rest of the documentation as if it were part of the second list item. * Added lines between consecutive URLs in http.zig Makes the documentation conform closer to what was intended. * Fix wrongfully ended sentence in Uri.zig * Handle wrongly entered comma in valgrind.zig. * Add missing periods in wasm.zig's documentation * Fix odd spacing in event/loop.zig * Add missing period in http/Headers.zig * Added missing period in io/limited_reader.zig This isn't in the documentation due to what I guess is a limitation of autodoc, but it's clearly supposed to be. If it was, it would look pretty bad. * Correct documentation in math/big/int.zig * Correct formatting in math/big/rational.zig * Create an actual link to ZIGNOR's paper. * Fixed grammatical issues in sort/block.zig This will not show up in the documentation currently. * Fix typo in hash_map.zig
2023-09-28Allow empty `enum` to be used in `EnumSet`/`EnumMap`Christofer Nolander
Moves the check for empty fields before any access to those fields.
2023-09-19write function types consistently with a space before `fn` keywordr00ster91
Currently, the compiler (like @typeName) writes it `fn(...) Type` but zig fmt writes it `fn (...) Type` (notice the space after `fn`). This inconsistency is now resolved and function types are consistently written the zig fmt way. Before this there were more `fn (...) Type` occurrences than `fn(...) Type` already.
2023-06-26std.sort.block: add safety check for lessThan return valueAli Chraghi
2023-06-24all: migrate code to new cast builtin syntaxmlugg
Most of this migration was performed automatically with `zig fmt`. There were a few exceptions which I had to manually fix: * `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten * `@truncate`'s fixup is incorrect for vectors * Test cases are not formatted, and their error locations change
2023-06-19all: zig fmt and rename "@XToY" to "@YFromX"Eric Joldasov
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-05-23std.sort: add pdqsort and heapsortAli Chraghi
2023-05-10std.enums: make Ext parameter optionalBogdan Romanyuk
According to #8169 optional generic functions work fine in comptime so it's possible
2023-05-10std.enums: add tagName()Travis Staloch
This is safe alternative to `@tagName()` for non-exhaustive enums that doesn't panic when given an enum value that has no tag.
2023-04-28update codebase to use `@memset` and `@memcpy`Andrew Kelley
2023-04-18std: fix uses of comptime blocks in non-inline functionsmlugg
ccf670c made using `return` from within a comptime block in a non-inline function illegal, since it is a use of runtime control flow in a comptime block. It is allowed if the function in question is `inline`, since no actual control flow occurs in this case. A few functions from std (notably `std.fmt.comptimePrint`) needed to be marked `inline` to support this change.
2023-04-12Zir: implement explicit block_comptime instructionmlugg
Resolves: #7056
2023-03-25std.enums.IndexedSet: Add initOne and initManyJay Petacat
2023-02-18update std lib and compiler sources to new for loop syntaxAndrew Kelley
2022-12-17std.builtin: rename Type.UnionField and Type.StructField's field_type to typer00ster91
2022-12-17std.IndexedSet.iterator: allow iteration on const EnumSetSteven Kabbes
2022-12-12std: implement subsetOf and supersetOf for EnumMultisetRonald Chen
2022-12-11std: add EnumMultiSetPyrolistical
2022-12-11std: added pure fns to EnumSetRonald Chen
2022-10-05fix(text): hyphenate "comptime" adjectivesr00ster91
2022-09-27use @ptrCast to assigned generic type to default_valueJacob Young
If the type happens to be a pointer, then the double pointer will not coerce implicitly.
2022-08-05std.enums: make directEnumArrayLen publicAllan Regush
2022-03-08deprecated TypeInfo in favor of TypeJonathan Marler
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-02-01stage1: avoid anytype fields for type infoAndrew Kelley
prerequisite for #10705
2021-08-24remove redundant license headers from zig standard libraryAndrew Kelley
We already have a LICENSE file that covers the Zig Standard Library. We no longer need to remind everyone that the license is MIT in every single file. Previously this was introduced to clarify the situation for a fork of Zig that made Zig's LICENSE file harder to find, and replaced it with their own license that required annual payments to their company. However that fork now appears to be dead. So there is no need to reinforce the copyright notice in every single file.