Commit graph

10511 commits

Author SHA1 Message Date
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
Archbirdplus
439667be04 runtime page size detection
heap.zig: define new default page sizes
heap.zig: add min/max_page_size and their options
lib/std/c: add miscellaneous declarations
heap.zig: add pageSize() and its options
switch to new page sizes, especially in GPA/stdlib
mem.zig: remove page_size
2025-02-06 14:23:23 -08:00
Matthew Lugg
43e52ec5c5
Merge pull request #22777 from mlugg/some-bugs
Fix a bunch of frontend bugs
2025-02-06 22:19:25 +00:00
Jacob Young
c58e60a042 x86_64: rewrite scalar @truncate 2025-02-06 16:14:53 -05:00
Frank Denis
b0ed602d5d
crypto/phc-encoding: forbid parameters named 'v' (#22569)
The spec is ambiguous, and it's too late to change it.

So the most reasonable thing to do in order to avoid generating
strings that could be parsed differently by other implementations
is to forbid parameters named "v" at compile-time.

See https://github.com/P-H-C/phc-string-format/issues/8
2025-02-06 16:37:42 +01:00
John Benediktsson
1c07eacc7f std.process: adding hasNonEmptyEnvVar() and using for NO_COLOR 2025-02-06 15:00:48 +01:00
David Rubin
eb72f26e28
std.c: add HINT to macos MAP 2025-02-06 01:17:49 -08:00
mlugg
0f38558435
compiler: provide result type to sentinel expression in slice operation
Resolves: #21867
2025-02-05 19:36:14 +00:00
Scott Redig
ff551374a0 fix typo of anytype to type
This seems like a simple typo.  The values are immediately used in a struct as types, so there's no reason to use anytype here, afaik.
2025-02-05 13:58:15 +01:00
Matthew Lugg
f01f1e33c9
Merge pull request #22754 from mlugg/files-and-stuff
ZON and incremental bits
2025-02-05 12:17:13 +00:00
Will Lillis
cf059ee087
AstGen: improve error for invalid bytes in strings and comments 2025-02-05 11:10:11 +02: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
mlugg
55a2e535fd
compiler: integrate ZON with the ZIR caching system
This came with a big cleanup to `Zcu.PerThread.updateFile` (formerly
`astGenFile`).

Also, change how the cache manifest works for files in the import table.
Instead of being added to the manifest when we call `semaFile` on them,
we iterate the import table after running the AstGen workers and add all
the files to the cache manifest then.

The downside is that this is a bit more eager to include files in the
manifest; in particular, files which are imported but not actually
referenced are now included in analysis. So, for instance, modifying any
standard library file will invalidate all Zig compilations using that
standard library, even if they don't use that file.

The original motivation here was simply that the old logic in `semaFile`
didn't translate nicely to ZON. However, it turns out to actually be
necessary for correctness. Because `@import("foo.zig")` is an
AstGen-level error if `foo.zig` does not exist, we need to invalidate
the cache when an imported but unreferenced file is removed to make sure
this error is triggered when it needs to be.

Resolves: #22746
2025-02-04 16:20:29 +00:00