Commit Graph
100 Commits
Author SHA1 Message Date
Andrew Kelley eb3c7f5706 zig build fmt 2025-02-22 17:09:20 -08:00
Andrew Kelley c0c911bfa7 zig fmt: fix invalid alignment on frees 2025-02-22 17:09:20 -08:00
Andrew Kelley ed55b2ef17 update to new pop API 2025-02-22 17:09:20 -08:00
Andrew Kelley 813312f0e8 Merge pull request #22714 from mlugg/langref
langref improvements
2025-02-22 18:41:35 -05:00
Andrew Kelley 61b69a418d Merge pull request #22659 from ifreund/linker-script-fix
link: fix ambiguous names in linker scripts
2025-02-22 18:18:24 -05:00
Andrew Kelley 61ee9f9415 Merge pull request #22606 from dweiller/memmove-opt
compiler-rt: memmove optimisation
2025-02-22 17:14:06 -05:00
Andrew Kelley 42438ce8b2 Merge pull request #22929 from schtvn/type_fn_docs_improvements
Autodoc: Improve documentation for common types declared as type functions
2025-02-22 17:10:45 -05:00
Andrew Kelley 0dcba03b67 Merge pull request #22902 from ianprime0509/autodoc-error-reporting
Autodoc: improve error reporting
2025-02-22 17:03:52 -05:00
Andrew Kelley 6fe1993d80 fix ArrayHashMap setKey when store_hash=true 2025-02-22 00:44:35 -05:00
Andrew Kelley a7467b9bb2 Merge pull request #22941 from Techatrix/config-header
std.Build.Step.ConfigHeader: improve handling of autoconf style headers
2025-02-22 00:25:09 -05:00
Andrew Kelley bd237bced4 Merge pull request #22932 from jacobly0/x86_64-rewrite
x86_64: start rewriting bit counting operations
2025-02-19 11:37:40 -08:00
Andrew Kelley d2e70ef84a Merge pull request #22913 from jacobly0/x86_64-rewrite
x86_64: rewrite unsafe int vector multiplication
2025-02-17 16:13:22 -08:00
Andrew Kelley e5174c7441 Merge pull request #22876 from jacobly0/x86_64-rewrite
x86_64: implement error set and enum safety
2025-02-15 12:33:09 -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
Andrew Kelley de8741271f Merge pull request #22873 from jacobly0/x86_64-rewrite
x86_64: implement conversions between float and int vectors
2025-02-12 13:54:03 -08:00
Andrew Kelley 53216d2f22 std.ArrayHashMap: base linear_scan_max on cache line size 2025-02-12 01:55:26 -08:00
Andrew Kelley 58f928814d Merge pull request #22862 from ziglang/fuzz
fuzzer: write inputs to shared memory before running
2025-02-11 23:36:53 -08:00
Andrew Kelley c2a3d8cbb9 std.ArrayHashMap: introduce setKey
Only available in the "unmanaged" variant since the other one is
deprecated.
2025-02-11 17:24:59 -08:00
Andrew Kelley d789f1e5cf fuzzer: write inputs to shared memory before running
breaking change to the fuzz testing API; it now passes a type-safe
context parameter to the fuzz function.

libfuzzer is reworked to select inputs from the entire corpus.

I tested that it's roughly as good as it was before in that it can find
the panics in the simple examples, as well as achieve decent coverage on
the tokenizer fuzz test.

however I think the next step here will be figuring out why so many
points of interest are missing from the tokenizer in both Debug and
ReleaseSafe modes.

does not quite close #20803 yet since there are some more important
things to be done, such as opening the previous corpus, continuing
fuzzing after finding bugs, storing the length of the inputs, etc.
2025-02-11 13:39:20 -08:00
Andrew Kelley 5c39ccddda Compilation: disable error return tracing in rt libs 2025-02-11 12:42:17 -08:00
Andrew Kelley 31c1320818 ZigLLVMTargetMachineEmitToFile: schedule sancov pass depending on mode
In debug mode, schedule it early. In release modes, schedule it late.
2025-02-11 11:13:41 -08:00
Andrew Kelley 8d914ea734 compiler_rt memcpy: avoid infinite recursion
when compiled in debug mode (--debug-rt)
2025-02-10 22:58:49 -08:00
Andrew Kelley 1d8857bbe3 Merge pull request #22695 from alexrp/glibc-2-41
glibc 2.41
2025-02-10 17:32:55 -08:00
Andrew Kelley c0448a6c7c CI: remove aarch64-windows checks for now
The devkit is a pain in the ass to keep online, I'll add this back
later.
2025-02-09 20:21:42 -08:00
Andrew Kelley 604ed5281c Merge pull request #22823 from ziglang/SmpAllocator-freelist-accounting
std.heap.SmpAllocator: back to simple free implementation
2025-02-08 21:27:22 -08:00
Andrew Kelley 42dbd35d3e std.heap.SmpAllocator: back to simple free
In practice this is fine because eventually alloc wins the race and
grabs that massive freelist.
2025-02-08 16:46:56 -08:00
Andrew Kelley b09e3efad4 std.heap.SmpAllocator: alternate freelist accounting
Freelist length accounting in alloc had a negative impact, especially
with the integer type bumped up to u16, so I changed the system to be
based on counting slabs rather than total allocations.
2025-02-08 16:20:51 -08:00
Andrew Kelley bb5a4036e8 std.heap.SmpAllocator; fix freelist accounting 2025-02-08 15:07:03 -08:00
Andrew Kelley ea1ce2df9b Merge pull request #22808 from ziglang/fast-gpa
introduce std.heap.SmpAllocator
2025-02-08 04:54:38 -08:00
Andrew Kelley 8453fb09a2 build: bump max_rss of std lib tests to 5G 2025-02-07 23:35:31 -08:00
Andrew Kelley bfabb703e3 don't try to test SmpAllocator in single threaded mode 2025-02-07 15:36:00 -08:00
Andrew Kelley 1754e014f5 std.heap.SmpAllocator: rotate on free sometimes
* slab length reduced to 64K
* track freelist length with u8s
* on free(), rotate if freelist length exceeds max_freelist_len

Prevents memory leakage in the scenario where one thread only allocates
and another thread only frees.
2025-02-07 14:41:49 -08:00
Andrew Kelley a9d3005616 std.heap.SmpAllocator: fix detection of slab end 2025-02-07 14:41:49 -08:00
Andrew Kelley 3246150d45 std.heap.SmpAllocator: fix getCpuCount logic
it was always returning max_cpu_count
2025-02-07 14:41:49 -08:00
Andrew Kelley 88e2e60e88 std.heap.SmpAllocator: simplify by putting freelist node at start 2025-02-07 14:41:49 -08:00
Andrew Kelley 1ffae59fec std.heap.SmpAllocator: fix using wrong size class indices 2025-02-07 14:41:49 -08:00
Andrew Kelley 839c453d88 std.heap.SmpAllocator: eliminate the global mutex 2025-02-07 14:41:49 -08:00
Andrew Kelley 60765a9ee2 std.heap.SmpAllocator: implement searching on alloc
rotate a couple times before resorting to mapping more memory.
2025-02-07 14:41:49 -08:00
Andrew Kelley 7360be19a4 compiler: use std.heap.smp_allocator
In main, now this allocator is chosen by default when compiling without
libc in ReleaseFast or ReleaseSmall, and not targeting WebAssembly.
2025-02-07 14:41:49 -08:00
Andrew Kelley 84bf7a6701 std.heap.SmpAllocator: 256K slab_len
and no need for special handling of wasi and windows since we don't ask
for anything more than page-aligned.
2025-02-07 12:20:12 -08:00
Andrew Kelley 3d7c5cf64a std.heap: test smp_allocator 2025-02-07 12:20:12 -08:00
Andrew Kelley 51c4ffa410 add std.heap.SmpAllocator
An allocator intended to be used in -OReleaseFast mode when
multi-threading is enabled.
2025-02-07 12:20:12 -08:00
Andrew Kelley 6a6e72fff8 Merge pull request #20511 from archbirdplus
runtime page size detection
rework GeneralPurposeAllocator to reduce active mapping count
Allocator VTable API update
2025-02-07 06:21:51 -08:00
Andrew Kelley 2d4954ad63 Merge pull request #22717 from jacobly0/x86_64-rewrite
x86_64: rewrite `@truncate`
2025-02-07 04:06:50 -08:00
Andrew Kelley b8f5cfed45 std.heap.SbrkAllocator: fix typo 2025-02-06 14:50:55 -08:00
Andrew Kelley e630b20c62 std.mem.Allocator.VTable: improve doc comment wording 2025-02-06 14:50:20 -08:00
Andrew Kelley 1bb8b4ad61 std.heap: fix wrong deprecation date 2025-02-06 14:47:22 -08:00
Andrew Kelley ff8e759705 std.testing: don't ask wasm to stack trace 2025-02-06 14:46:16 -08:00
Andrew Kelley d0e1a6a23d std.heap.DebugAllocator: update unit tests for new impl
No longer need this windows-specific behavior.
2025-02-06 14:23:23 -08:00
Andrew Kelley 960190643a std.heap.DebugAllocator: make page size configurable 2025-02-06 14:23:23 -08:00
Andrew Kelley cd99ab3229 std.heap: rename GeneralPurposeAllocator to DebugAllocator 2025-02-06 14:23:23 -08:00
Andrew Kelley 5e9b8c38d3 std.heap: remove HeapAllocator
Windows-only, depends on kernel32 in violation of zig std lib policy,
and redundant with other cross-platform APIs that perform the same
functionality.
2025-02-06 14:23:23 -08:00
Andrew Kelley f82ec3f02a std.testing.allocator: different canary + enable resize traces
Accept a slight performance degradation when unit testing for better
debuggability when a leak or double-free is detected.
2025-02-06 14:23:23 -08:00
Andrew Kelley 8282565ce5 std.heap.GeneralPurposeAllocator: fix UAF in resizeLarge
There was an ensureUnusedCapacity() call that invalidated a looked-up
hash table entry. Move it earlier.
2025-02-06 14:23:23 -08:00
Andrew Kelley 6aab1ea256 std.heap: update Windows HeapAllocator 2025-02-06 14:23:23 -08:00
Andrew Kelley 8626191549 std.heap.GeneralPurposeAllocator: fix slot_counts calculation
In larger small buckets, the comptime logic that computed slot count did
not verify that the number it produced was valid. Now it verifies it,
which made this bug into a compile error. Then I fixed the bug by
introducing a "minimum slots per bucket" declaration.
2025-02-06 14:23:23 -08:00
Andrew Kelley 7320e8b3cd std.testing: make some things not pub
this looks like it was an accident to expose these
2025-02-06 14:23:23 -08:00
Andrew Kelley d20d934a8a std: fix compilation under -lc 2025-02-06 14:23:23 -08:00
Andrew Kelley def36f2e44 std.heap.GeneralPurposeAllocator: usize for used_bits
improves leak checking performance.
2025-02-06 14:23:23 -08:00
Andrew Kelley c8e807c44e std.heap.GeneralPurposeAllocator: use for loops in leak check 2025-02-06 14:23:23 -08:00
Andrew Kelley b14a350430 std.heap.GeneralPurposeAllocator: reduce page size to 512K
and fix compilation on 32-bit targets
2025-02-06 14:23:23 -08:00
Andrew Kelley 00b723dc9d std.heap.WasmAllocator: update to new Allocator API 2025-02-06 14:23:23 -08:00
Andrew Kelley 82b5a1d313 std.heap.GeneralPurposeAllocator: implement resize and remap 2025-02-06 14:23:23 -08:00
Andrew Kelley 0e0f0c9625 std.heap.GeneralPurposeAllocator: check canary in free 2025-02-06 14:23:23 -08:00
Andrew Kelley 8ff7481e82 std.heap.GeneralPurposeAllocator: inline small allocation metadata
Put the small allocation metadata directly into the (large) pages
allocated.
2025-02-06 14:23:23 -08:00
Andrew Kelley 1a6d87d699 std.heap.ThreadSafeAllocator: update to new Allocator API 2025-02-06 14:23:23 -08:00
Andrew Kelley 36e9b0f026 std.mem.Allocator: keep the undefined memset
Reversal on the decision: the Allocator interface is the correct place
for the memset to undefined because it allows Allocator implementations
to bypass the interface and use a backing allocator directly, skipping
the performance penalty of memsetting the entire allocation, which may
be very large, as well as having valuable zeroes on them.

closes #4298
2025-02-06 14:23:23 -08:00
Andrew Kelley 2c5113f6d1 std.os.linux.mmap: remove logic that does not belong here 2025-02-06 14:23:23 -08:00
Andrew Kelley 601f632c27 std.heap.GeneralPurposeAllocator: fix large alloc accounting
when mremap relocates an allocation
2025-02-06 14:23:23 -08:00
Andrew Kelley becd16859d std.hash_map: placeholder for doc comments 2025-02-06 14:23:23 -08:00
Andrew Kelley f1717777a2 std.heap: delete LoggingAllocator and friends
I don't think these belong in std, at least not in their current form.

If someone wants to add these back I'd like to review the patch before
it lands.

Reverts 629e2e7844
2025-02-06 14:23:23 -08:00
Andrew Kelley 0d8166be3f std: update to new Allocator API 2025-02-06 14:23:23 -08:00
Andrew Kelley a4d4e086c5 introduce std.posix.mremap and use it
in std.heap.page_allocator
2025-02-06 14:23:23 -08:00
Andrew Kelley a0b2a18648 std.testing.FailingAllocator: flatten namespace 2025-02-06 14:23:23 -08: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 dd2fa4f75d std.heap.GeneralPurposeAllocator: runtime-known page size
no longer causes compilation failure.

This also addresses the problem of high map count causing OOM by
choosing a page size of 2MiB for most targets when the page_size_max is
smaller than this number.
2025-02-06 14:23:23 -08:00
Andrew Kelley b23662feeb std.heap.WasmAllocator: use @splat syntax
preferred over array multiplication where possible.
2025-02-06 14:23:23 -08:00
Andrew Kelley 91f41bdc70 std.heap.PageAllocator: restore high alignment functionality
This allocator now supports alignments greater than page size, with the
same implementation as it used before.

This is a partial revert of ceb0a632cf.

It looks like VirtualAlloc2 has better solutions to this problem,
including features such as MEM_RESERVE_PLACEHOLDER and MEM_LARGE_PAGES.
This possibility can be investigated as a follow-up task.
2025-02-06 14:23:23 -08:00
Andrew Kelley 5c63884539 add std.mem.Alignment API 2025-02-06 14:23:23 -08:00
Andrew Kelley 4913de3c88 GeneralPurposeAllocator: minimal fix
This keeps the implementation matching master branch, however,
introduces a compile error that applications can work around by
explicitly setting page_size_max and page_size_min to match their
computer's settings, in the case that those values are not already
equal.

I plan to rework this allocator in a follow-up enhancement with the goal
of reducing total active memory mappings.
2025-02-06 14:23:23 -08:00
Andrew Kelley 95a0474dc6 revert GPA to before this branch 2025-02-06 14:23:23 -08:00
Andrew Kelley 284de7d957 adjust runtime page size APIs
* fix merge conflicts
* rename the declarations
* reword documentation
* extract FixedBufferAllocator to separate file
* take advantage of locals
* remove the assertion about max alignment in Allocator API, leaving it
  Allocator implementation defined
* fix non-inline function call in start logic

The GeneralPurposeAllocator implementation is totally broken because it
uses global state but I didn't address that in this commit.
2025-02-06 14:23:23 -08:00
Andrew Kelley d72f3d353f Merge pull request #22691 from squeek502/child-internal-array-list
Document that the `ptr` field of Allocator/Random should not be compared and remove existing comparison
2025-02-04 13:35:59 -08:00
Andrew Kelley 963651bbf2 Merge pull request #22672 from jacobly0/x86_64-rewrite
x86_64: rewrite float conversions
2025-02-01 14:32:43 -08:00
Andrew Kelley fecdc53a48 delete std.heap.WasmPageAllocator
This allocator has no purpose since it cannot truly fulfill the role of
page allocation, and std.heap.wasm_allocator is better both in terms of
performance and code size.

This commit redefines `std.heap.page_allocator` to be less strict:

"On operating systems that support memory mapping, this allocator makes
a syscall directly for every allocation and free. Otherwise, it falls
back to the preferred singleton for the target. Thread-safe."

This now matches how it was actually being implemented, and matches its
use sites - which are mainly as the backing allocator for
`std.heap.ArenaAllocator`.
2025-01-29 21:10:20 -08:00
Andrew Kelley 37037b269e frontend: use main Compilation code_model when building libxx
as well as libtsan, libunwind, and libc files
2025-01-27 17:07:56 -08:00
Andrew Kelley eed3b9567d Merge pull request #22610 from jacobly0/x86_64-rewrite
x86_64: rewrite `@min`/`@max` for scalar floats
2025-01-27 11:47:52 -08:00
Andrew Kelley df1fa36feb Revert "std.http.Server: add Request.getHeader() function (#21625)"
This reverts commit 21823d1b5d.

It's a bad API that could easily lead to O(N^2) logic.
2025-01-27 11:13:56 -08:00
Andrew Kelley 8fa47bb904 Merge pull request #22230 from alexrp/lto-stuff
Disable LTO by default + some LTO fixes
2025-01-25 13:17:25 -08:00
Andrew Kelley d0d5ca2b6c Merge pull request #22581 from jacobly0/x86_64-rewrite
x86_64: rewrite `@abs` on floats
2025-01-25 07:30:45 -08:00
Andrew Kelley 921725427e Merge pull request #22596 from ziglang/pipeline
Compilation pipeline: repeat failed prelink tasks
2025-01-24 19:52:09 -05:00
Andrew Kelley 3e174ee1ac frontend: fix data race with mingw crt files 2025-01-24 12:22:00 -08:00
Andrew Kelley d3f4e9d4ac Compilation pipeline: repeat failed prelink tasks
and remove faulty assertion. When a prelink task fails, the
completed_prelink_tasks counter will not decrement.

A future improvement will be needed to make the pipeline fully robust
and handle failed prelink tasks, followed by updates in which those
tasks succeed, and compilation proceeds like normal.

Currently if a prelink task fails, the Compilation will be left in a
state unrecoverable by an incremental update.
2025-01-24 12:22:00 -08:00
Andrew Kelley f07bea20da Merge pull request #21447 from Szwagi/fix-lzma-memcpy-alias
Fix memcpy alias bug in std.compress.lzma
2025-01-21 18:37:28 -05:00
Andrew Kelley b31a2c9555 Merge pull request #22541 from ziglang/pipeline
Compilation pipeline: spawn Jobs earlier that produce linker inputs
2025-01-21 14:27:05 -05:00
Andrew Kelley 0bacb79c09 Revert "Merge pull request #21540 from BratishkaErik/search-env-in-path"
It caused an assertion failure when building Zig from source.

This reverts commit 0595feb341, reversing
changes made to 744771d330.

closes #22566
closes #22568
2025-01-21 11:22:28 -08:00
Andrew Kelley 18fcb3b5e8 Merge pull request #18912 from dweiller/memcpy-opt
optimized memcpy
2025-01-21 13:05:14 -05:00
Andrew Kelley 09d021c908 add test coverage for previous commit 2025-01-20 21:41:30 -08:00
Andrew Kelley 0595feb341 Merge pull request #21540 from BratishkaErik/search-env-in-path
std.zig.system: use both PATH and hardcoded locations to find `env`
2025-01-21 00:16:19 -05:00
Andrew Kelley 744771d330 Merge pull request #22536 from BryceVandegrift/access-er13
std.posix: Fix errno 13 when writing to file
2025-01-21 00:10:05 -05:00