7370 Commits

Author SHA1 Message Date
Alex Kladov
4620972d08 Sema: preserve extern struct field alignment
In

    extern struct { x: u32, y: u16 }

we actually know that y's alignment is `@alignOf(u32)`, and not just
`@alignOf(u16)`.

closes: #16134
2023-06-28 16:36:32 +02:00
r00ster91
2463f4df77 addrspace: small cleanups 2023-06-27 19:50:17 -04:00
r00ster91
40e002ae2b std.builtin.StackTrace: don't print extra newline after stack trace 2023-06-27 19:49:54 -04:00
r00ster91
11c32c756f fix u65529 and above overflowing in more places
See also #15537
2023-06-27 19:08:24 -04:00
Luuk de Gram
622c5f3200
Merge pull request #16207 from Luukdegram/wasi-threads
WASI: Implement experimental threading support
2023-06-27 18:28:26 +02:00
yujiri8
dae516dbdf
improve documentation of std.sort.*Context functions (#16145) 2023-06-27 00:51:06 -07:00
Jacob Young
8239d3b358 crypto: recoup storage in tls.Client.partially_read_buffer 2023-06-26 21:05:08 -04:00
Jacob Young
eb8881a538 crypto: cleanup unneeded uses of @as in tls.Client 2023-06-26 21:05:08 -04:00
Ali Chraghi
6bd5479306 std.sort.block: add safety check for lessThan return value 2023-06-26 17:50:10 -07:00
Ian Johnson
bbda053f9e Build: make InstallDirStep use a FileSource
Closes #16187
2023-06-26 15:59:53 -07:00
Luuk de Gram
87b8a0567b
default to single-threaded for WebAssembly
When targeting WebAssembly, we default to building a single-threaded build
as threads are still experimental. The user however can enable a multi-
threaded build by specifying '-fno-single-threaded'. It's a compile-error
to enable this flag, but not also enable shared-memory.
2023-06-26 20:00:58 +02:00
Luuk de Gram
e06ab1b010
std: implement detach for WASI-threads
When a thread is detached from the main thread, we automatically
cleanup any allocated memory. For this we first reset the stack-pointer
to the original stack-pointer of the main-thread so we can safely clear
the memory which also contains the thread's stack.
2023-06-26 20:00:58 +02:00
Luuk de Gram
622b7c4746
free allocated memory upon call join
When `join` detects a thread has completed, it will free the allocated
memory of the thread. For this we must first copy the allocator. This is
required as the allocated memory holds a reference to the original
allocator. If we free the memory, we would end up with UB as the
allocator would free itself.
2023-06-26 20:00:57 +02:00
Luuk de Gram
834609038c
std: implement join for WASI-threads
We now reset the Thread ID to 0 and wake up the main thread listening
for the thread to finish. We use inline assembly as we cannot use
the stack to set the thread ID as it could possibly clobber any
of the memory.

Currently, we leak the memory that was allocated for the thread.
We need to implement a way where we can clean up the memory without
using the stack (as the stack is stored inside this same memory).
2023-06-26 20:00:57 +02:00
Luuk de Gram
10bf58b2db
store allocator & remove global assembly
We now store the original allocator that was used to allocate the
memory required for the thread. This allocator can then be used
in any cleanup functionality to ensure the memory is freed correctly.

Secondly, we now use a function to set the stack pointer instead of
generating a function using global assembly. This is a lot cleaner
and more readable.
2023-06-26 20:00:57 +02:00
Luuk de Gram
a97dbdfa0b
std: implement Thread spawn for WASI
This implements a first version to spawn a WASI-thread. For a new thread
to be created, we calculate the size required to store TLS, the new stack,
and metadata. This size is then allocated using a user-provided allocator.

After a new thread is spawn, the HOST will call into our bootstrap procedure.
This bootstrap procedure will then initialize the TLS segment and set the
newly spawned thread's TID. It will also set the stack pointer to the newly
created stack to ensure we do not clobber the main thread's stack.

When bootstrapping the thread is completed, we will call the user's
function on this new thread.
2023-06-26 20:00:57 +02:00
Luuk de Gram
ea0d4c8377
std: implement Futex for WebAssembly
Implements std's `Futex` for the WebAssembly target using Wasm's
`atomics` instruction set. When the `atomics` cpu feature is disabled
we emit a compile-error.
2023-06-26 20:00:57 +02:00
Meghan Denny
7322aa1183 std.Uri: allow getting the mutable result from (un)escape 2023-06-26 15:46:04 +03:00
Jan200101
42ca357604 std.Build: omit newline from last line 2023-06-26 04:25:14 -07:00
Jobat
d5ebe3e395 Change capacity to take a non-pointer parameter
I don't believe there's a requirement for this to take a pointer, as the underlying function doesn't.
2023-06-26 02:05:28 -07:00
jacobly0
cc2daae47e
Merge pull request #15771 from jacobly0/x86_64-behavior
x86_64: behavior
2023-06-26 02:45:48 -04:00
Roman Frołow
dce1999c80 is has -> has 2023-06-25 23:30:25 -07:00
Andrew Kelley
40cf3f7ae5
Merge pull request #15995 from mlugg/fix/union-field-ptr-align
Sema: copy pointer alignment to union field pointers
2023-06-25 23:06:53 -07:00
Jacob Young
b18a72ec35 x86_64: fix crash emitting a packed undefined u128 2023-06-25 19:14:03 -04:00
Maciej 'vesim' Kuliński
d98147414d update Ascon.zig to use @min builtin 2023-06-25 15:39:17 -07:00
Eric Joldasov
0a868dacdd std.cstr: deprecate namespace
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-25 14:51:03 -07:00
David CARLIER
d07149c56d std.c: few freebsd's kinfo api fixes.
following up on 4a0508e and 3dd0afe.

- kinfo_vmentry, removing kve_ prefix.
- kinfo_getproc, returns one entry at most.
2023-06-25 12:27:45 -07:00
mlugg
b66865d059
std.pdb: fix incorrect field alignment in ptrCast 2023-06-25 14:13:52 +01:00
Josh Wolfe
3f04231600 std: re-pub new json symbols in json.zig 2023-06-25 04:56:38 -07:00
mlugg
f26dda2117 all: migrate code to new cast builtin syntax
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-24 16:56:39 -07:00
mlugg
283d650973 fmt: add rewrite for cast builtin type parameters 2023-06-24 16:47:49 -07:00
David CARLIER
72dd22f262 std.c: fix few capcisum api calls, following-up on 6ae19fa.
only variadic calls are prefixed with underscores.

ref: 59833b089e/sys/sys/capsicum.h (L326)
2023-06-24 13:05:45 -07:00
Andrew Kelley
7ad1042279 Revert "fix parseInt failing when a correct base is given"
This reverts commit fa6cea22bf9cd5ff6a9dd882166cf7e479acfd6c.

Apologies for the merge. I thought this was a bug fix, but I see that it
is implementing a proposal that I intended to reject.
2023-06-24 13:03:51 -07:00
Mikko Kaihlavirta
fa6cea22bf fix parseInt failing when a correct base is given 2023-06-24 13:02:45 -07:00
David CARLIER
ea1d64dae4 std.c: fix host_basic_info definition for darwin.
follow-up on ff59c45.

ref: a5e15eced0/lib/libc/include/any-macos-any/mach/host_info.h (L116)
2023-06-24 13:00:14 -07:00
David CARLIER
e9dd0a22f0 std.c: freebsd fix typo for PROC.PROCCTL_MD_MIN constant.
follow-up on 2e2d379.
2023-06-24 12:59:18 -07:00
r00ster91
d82ab4fd8a ErrorBundle: fix integer overflow printing caret 2023-06-23 23:58:21 -07:00
Andrew Kelley
b129f1b046
Merge pull request #16037 from Jan200101/PR/cmakedefine-fix
Correct cmakedefine implementation
2023-06-23 23:56:18 -07:00
Michael Dusan
1cf06706be openbsd: fix NativeTargetInfo semver
- supply ".0" as .Z component and satisfy semver X.Y.Z requirement
- previously only X.Y was supplied and semver parse failed
2023-06-23 23:41:29 -07:00
Zachary Raineri
148e2a5a89
Removed unnecessary return switch on void method
Removed an unnecessary "return switch" on the Atomic.store method
2023-06-24 05:12:07 +00:00
Ed Yu
8dcb4a3dc4 std.http: fix the http.Client.wait() hanging when there is 1 more byte left 2023-06-23 20:18:24 +02:00
Niles Salter
7d511d6428
[heapsort] Protect against integer overflow
(Firstly, I changed `n` to `b`, as that is less confusing. It's not a length, it's a right boundary.)

The invariant maintained is `cur < b`. In the worst case `2*cur + 1` results in a maximum of `2b`. Since `2b` is not guaranteed to be lower than `maxInt`, we have to add one overflow check to `siftDown` to make sure we avoid undefined behavior.

LLVM also seems to have a nicer time compiling this version of the function. It is about 2x faster in my tests (I think LLVM was stumped by the `child += @intFromBool` line), and adding/removing the overflow check has a negligible performance difference on my machine. Of course, we could check `2b <= maxInt` in the parent function, and dispatch to a version of the function without the overflow check in the common case, but that probably is not worth the code size just to eliminate a single instruction.
2023-06-22 17:32:28 +00:00
Andrew Kelley
93e54f2354
Merge pull request #16110 from dweiller/force-tty-color
std.io.tty: cleanup detectConfig
2023-06-22 06:54:15 -07:00
David CARLIER
64f0059cd3 std.c: update netbsd/openbsd mman constants 2023-06-22 10:21:48 +00:00
Niles Salter
82470d4f89 [priority_dequeue] Fix out-of-bounds access
This makes it so `first_child_index` will not be accessed when it is equal to `self.len`. (i.e. `self.items[self.len]` will not happen) The access itself was "safe" (as in, `self.len < self.items.len`) because we were only calling `doSiftDown` in the case where there was a stale value at `self.items[self.len]`. However, it is still technically a bug, and can manifest by an unnecessary comparison of a value to a copy of itself.
2023-06-22 02:03:53 -07:00
Niles Salter
ff5850183e [priority_deque] simplify & optimize isMinLayer
LLVM has trouble compiling the old implementation, (presumably) because `leading_zeros` is thought to be a `u7` rather than a `u6`, which means `63 - clz` is not equivalent to `63 ^ clz`, which means it can't deduce that the final condition can simply be flipped. (I am assuming `usize` is a `u64` here for ease of understanding, but it's the same for any power of 2)

https://zig.godbolt.org/z/Pbj4P7ob3

The new version is slightly better too because `isMinLayer(maxInt(usize))` is now well-defined behavior.
2023-06-22 01:57:28 -07:00
Piotr Sarna
438d680913 http: fix getting Transfer-Encoding value
The 'Content-Length' header was inspected by mistake,
which makes it effectively impossible to use chunked
Transfer-Encoding when using the http client.

Tested locally with a HTTP server - data is properly sent
with POST method and the proper encoding declared, after the fix.
2023-06-22 11:44:46 +03:00
dweiller
e45d24c0de rename ZIG_DEBUG_COLOR env variable to YES_COLOR 2023-06-22 10:29:45 +10:00
dweiller
e05412669c std.io.tty: add detectTtyConfigForce for forcing color 2023-06-22 10:29:45 +10:00
Jan200101
1864ba2ccc
std.Build: implement variable substitution 2023-06-21 21:51:07 +02:00