aboutsummaryrefslogtreecommitdiff
path: root/lib/std/std.zig
AgeCommit message (Collapse)Author
2022-05-11std: add http definitions for Method and Status (#10661)Meghan
2022-04-20std: bring back SegmentedListAndrew Kelley
I want to use it for the self-hosted compiler.
2022-04-15treap: initial implementationkprotty
2022-03-27std: SIMD utility functionstecanec
This file contains a collections of functions that may be useful for SIMD, such as generating a vector with a linear range of numbers starting at zero, joining two vectors together, getting the index of the first true in a vector of bools, etc.
2021-12-31tz parsing reader interface, test thicc files, and exclude tzifJens Goldberg
2021-12-30Actually expose the tz fileJens Goldberg
2021-10-04migrate from `std.Target.current` to `@import("builtin").target`Andrew Kelley
closes #9388 closes #9321
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.
2021-08-24BoundedArray: a simple way to represent small data whose max size is known ↵Frank Denis
(#9134) This is a simple structure containing an array and a length, that can be viewed as a slice. It is useful to pass-by-copy small data whose exact size is known at runtime, but whose maximum size is known at comptime. This greatly simplifies code that otherwise would require an allocator, or reimplementing what this type does.
2021-04-25x, x/os/Socket: initial work on new Socket abstractionlithdew
Kick-start initial work on new cross-platform abstraction for sockets. Adds a test for read timeouts and a test for creating a non-blocking socket pair on Linux. The new Socket abstraction is barebones and is made to support both blocking and non-blocking abstractions, alongside different socket protocols and domains. Support for platform-dependant socket options that handles unsupported platforms gracefully via. comptime checks is provided for the new Socket abstraction. This also marks the first out of many commits for introducing breaking changes to the standard library in a separate `x` folder, which was pre-approved by @andrewrk. The intent for the new `x` package is to introduce new async, event loop, networking, and operating system abstractions that would require breaking the standard library significantly. By having the `x` package, code in the standard library and compiler may then slowly be refactored to use the `x` package. Once modules in the `x` package are stabilized, they can be moved out of the `x` package, and a global 'grep' can be done to update import paths that resolve to the stabilized module in the `x` package.
2021-04-08stage2: blaze the trail for std lib integrationAndrew Kelley
This branch adds "builtin" and "std" to the import table when using the self-hosted backend. "builtin" gains one additional item: ``` pub const zig_is_stage2 = true; // false when using stage1 backend ``` This allows the std lib to do conditional compilation based on detecting which backend is being used. This will be removed from builtin as soon as self-hosted catches up to feature parity with stage1. Keep a sharp eye out - people are going to be tempted to abuse this. The general rule of thumb is do not use `builtin.zig_is_stage2`. However this commit breaks the rule so that we can gain limited start.zig support as we incrementally improve the self-hosted compiler. This commit also implements `fullyQualifiedNameHash` and related functionality, which effectively puts all Decls in their proper namespaces. `fullyQualifiedName` is not yet implemented. Stop printing "todo" log messages for test decls unless we are in test mode. Add "previous definition here" error notes for Decl name collisions. This commit does not bring us yet to a newly passing test case. Here's what I'm working towards: ```zig const std = @import("std"); export fn main() c_int { const a = std.fs.base64_alphabet[0]; return a - 'A'; } ``` Current output: ``` $ ./zig-cache/bin/zig build-exe test.zig test.zig:3:1: error: TODO implement more analyze elemptr zig-cache/lib/zig/std/start.zig:38:46: error: TODO implement structInitExpr ty ``` So the next steps are clear: * Sema: improve elemptr * AstGen: implement structInitExpr
2021-04-02Merge pull request #7792 from zanderxyz/zanderxyz/priority-dequeueAndrew Kelley
std: Add Priority Dequeue
2021-03-18Add some enum utilitiesMartin Wickham
2021-03-01Add some bit set variantsMartin Wickham
2021-02-11Merge remote-tracking branch 'origin/master' into ast-memory-layoutAndrew Kelley
Conflicts: * lib/std/zig/ast.zig * lib/std/zig/parse.zig * lib/std/zig/parser_test.zig * lib/std/zig/render.zig * src/Module.zig * src/zir.zig I resolved some of the conflicts by reverting a small portion of @tadeokondrak's stage2 logic here regarding `callconv(.Inline)`. It will need to get reworked as part of this branch.
2021-02-01Define wasm constantsLuuk de Gram
Update link.Wasm.zig to use std.wasm for its constants Make opcodes u8 and non-exhaustive Update test and rename 'spec' to 'wasm'
2021-01-30add std.MultiArrayListAndrew Kelley
Also known as "Struct-Of-Arrays" or "SOA". The purpose of this data structure is to provide a similar API to ArrayList but instead of the element type being a struct, the fields of the struct are in N different arrays, all with the same length and capacity. Having this abstraction means we can put them in the same allocation, avoiding overhead with the allocator. It also saves a tiny bit of overhead from the redundant capacity and length fields, since each struct element shares the same value. This is an alternate implementation to #7854.
2021-01-22std: Update `test ""` to `test` where it makes senseLemonBoy
2021-01-16std: Add Priority DequeueZander Khan
2021-01-14organize std lib concurrency primitives and add RwLockAndrew Kelley
* move concurrency primitives that always operate on kernel threads to the std.Thread namespace * remove std.SpinLock. Nobody should use this in a non-freestanding environment; the other primitives are always preferable. In freestanding, it will be necessary to put custom spin logic in there, so there are no use cases for a std lib version. * move some std lib files to the top level fields convention * add std.Thread.spinLoopHint * add std.Thread.Condition * add std.Thread.Semaphore * new implementation of std.Thread.Mutex for Windows and non-pthreads Linux * add std.Thread.RwLock Implementations provided by @kprotty
2021-01-06std.SpinLock: flatten and remove init/deinitAndrew Kelley
structs which are intended to be directly initialized and support static initialization should not have init/deinit methods.
2021-01-04std: skip more tests on Windows to save CI memoryAndrew Kelley
I've enabled only the tests that check things specific to Windows that are not tested by other systems.
2020-12-31Year++Frank Denis
2020-12-24Merge pull request #7531 from Vexu/orphanageVeikka Tuominen
Move ArrayListSentineled to std lib orphanage
2020-12-23rework std.ResetEvent, improve std lib Darwin integrationAndrew Kelley
* split std.ResetEvent into: - ResetEvent - requires init() at runtime and it can fail. Also requires deinit(). - StaticResetEvent - can be statically initialized and requires no deinitialization. Initialization cannot fail. * the POSIX sem_t implementation can in fact fail on initialization because it is allowed to be implemented as a file descriptor. * Completely define, clarify, and explain in detail the semantics of these APIs. Remove the `isSet` function. * `ResetEvent.timedWait` returns an enum instead of a possible error. * `ResetEvent.init` takes a pointer to the ResetEvent instead of returning a copy. * On Darwin, `ResetEvent` is implemented using Grand Central Dispatch, which is exposed by libSystem. stage2 changes: * ThreadPool: use a single, pre-initialized `ResetEvent` per worker. * WaitGroup: now requires init() and deinit() and init() can fail. - Add a `reset` function. - Compilation initializes one for the work queue in creation and re-uses it for every update. - Rename `stop` to `finish`. - Simplify the implementation based on the usage pattern.
2020-12-23move ArrayListSentineled to std lib orphanageVeikka Tuominen
2020-12-20std.Progress: make the API thread-safeAndrew Kelley
We generally get away with atomic primitives, however a lock is required around the refresh function since it traverses the Node graph, and we need to be sure no references to Nodes remain after end() is called.
2020-11-30move std.SegmentedList to the std-lib-orphanageAndrew Kelley
I spent a long time working on this data structure, and I still think it's a neat idea, but it has no business being in the std lib. I'm aware of the few remaining references to SegmentedList that exist in the std lib, but they are dead code, and so I'm leaving the dead references as a clue that the code is dead. Cleaning up dead code will be a separate effort that involves code coverage tools to make sure we find it all. std-lib-orphanage commit: 2c36a7894c689ecbaf63d5f489bb0c68773410c4 closes #7190
2020-11-16Move leb128 and remove trivial *mem functions as discussed in #5588 (#6876)tgschultz
* Move leb128 out of debug and remove trivial *mem functions as discussed in #5588 * Turns out one of the *Mem functions was used by MachO. Replaced with trivial use of FixedBufferStream.
2020-11-06std: Introduce SemanticVersion data structureJay Petacat
This will parse, format, and compare version strings following the SemVer 2 specification. See: https://semver.org Updates #6466
2020-10-15std: move std.meta.refAllDecls to std.testingTadeo Kondrak
2020-10-11AutoResetEventkprotty
2020-09-30Merge pull request #6250 from ziglang/stage2-zig-ccAndrew Kelley
move `zig cc`, `zig translate-c`, `zig libc`, main(), and linking from stage1 to stage2
2020-09-29move std.http to the standard library orphanageAndrew Kelley
I want to take the design of this in a different direction. I think this abstraction is too high level. I want to start bottom-up. std-lib-orphanage commit 179ae67d61455758d71037434704fd4a17a635a9
2020-09-29Merge remote-tracking branch 'origin/master' into stage2-zig-ccAndrew Kelley
This merges in the revert that fixes the broken Windows build of master branch.
2020-09-29move std.BloomFilter to the standard library orphanageAndrew Kelley
2020-09-29move std.rb to the standard library orphanageAndrew Kelley
https://github.com/ziglang/std-lib-orphanage/ This code is not used by anything else in the standard library or by the compiler or any of its tools and therefore it's a great candidate to be maintained by a third party.
2020-09-14move std.cache_hash from std to stage2Andrew Kelley
The API is pretty specific to the implementationt details of the self-hosted compiler. I don't want to have to independently support and maintain this as part of the standard library, and be obligated to not make breaking changes to it with changes to the implementation of stage2.
2020-09-07std: Add DEFLATE and zlib decompressorsLemonBoy
2020-09-02hash_map: rename to ArrayHashMap and add new HashMap implementationSahnvour
2020-08-20add license header to all std lib filesAndrew Kelley
add SPDX license identifier copyright ownership is zig contributors
2020-08-07improvements & fixes for general purpose allocator integrationAndrew Kelley
* std.Mutex API is improved to not have init() deinit(). This API is designed to support static initialization and does not require any resource cleanup. This also happens to work around some kind of stage1 behavior that wasn't letting the new allocator mutex code get compiled. * the general purpose allocator now returns a bool from deinit() which tells if there were any leaks. This value is used by the test runner to fail the tests if there are any. * self-hosted compiler is updated to use the general purpose allocator when not linking against libc.
2020-07-13std: add StringHashMapUnmanageddaurnimator
2020-07-06std: expose unmanaged hash mapsAndrew Kelley
These are useful when you have many of them in memory, and already have the allocator stored elsewhere.
2020-06-17Introduce std.logIsaac Freund
std.log provides 8 log levels and corresponding logging functions. It allows the user to override the logging "backend" by defining root.log and to override the default log level by defining root.log_level. Logging functions accept a scope parameter which allows the implementer of the logging "backend" to filter logging by library as well as level. Using the standardized syslog [1] log levels ensures that std.log will be flexible enough to work for as many use-cases as possible. If we were to stick with only 3/4 log levels, std.log would be insufficient for large and/or complex projects such as a kernel or display server. [1]: https://tools.ietf.org/html/rfc5424#section-6.2.1
2020-05-26Add std.ComptimeStringMapRyan Liptak
2020-05-25Partially implement cache hash API in zigLeRoyce Pearson
2020-05-10rework self-hosted compiler for incremental buildsAndrew Kelley
* introduce std.ArrayListUnmanaged for when you have the allocator stored elsewhere * move std.heap.ArenaAllocator implementation to its own file. extract the main state into std.heap.ArenaAllocator.State, which can be stored as an alternative to storing the entire ArenaAllocator, saving 24 bytes per ArenaAllocator on 64 bit targets. * std.LinkedList.Node pointer field now defaults to being null initialized. * Rework self-hosted compiler Package API * Delete almost all the bitrotted self-hosted compiler code. The only bit rotted code left is in main.zig and compilation.zig * Add call instruction to ZIR * self-hosted compiler ir API and link API are reworked to support a long-running compiler that incrementally updates declarations * Introduce the concept of scopes to ZIR semantic analysis * ZIR text format supports referencing named decls that are declared later in the file * Figure out how memory management works for the long-running compiler and incremental compilation. The main roots are top level declarations. There is a table of decls. The key is a cryptographic hash of the fully qualified decl name. Each decl has an arena allocator where all of the memory related to that decl is stored. Each code block has its own arena allocator for the lifetime of the block. Values that want to survive when going out of scope in a block must get copied into the outer block. Finally, values must get copied into the Decl arena to be long-lived. * Delete the unused MemoryCell struct. Instead, comptime pointers are based on references to Decl structs. * Figure out how caching works. Each Decl will store a set of other Decls which must be recompiled when it changes. This branch is still work-in-progress; this commit breaks the build.
2020-04-21Remove std.lazyInitHaze Booth
2020-04-18std: Introduce the Once synchronization primitiveLemonBoy
The Once object allows the user to execute a function just once in a thread-safe way.