10296 Commits

Author SHA1 Message Date
Mason Remaley
13c6eb0d71
compiler,std: implement ZON support
This commit allows using ZON (Zig Object Notation) in a few ways.

* `@import` can be used to load ZON at comptime and convert it to a
  normal Zig value. In this case, `@import` must have a result type.
* `std.zon.parse` can be used to parse ZON at runtime, akin to the
  parsing logic in `std.json`.
* `std.zon.stringify` can be used to convert arbitrary data structures
  to ZON at runtime, again akin to `std.json`.
2025-02-03 09:14:37 +00: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
dweiller
cdc9d65b0d std.priority_queue: add useful functions from ArrayList API
The `ensureTotalCapacityPrecise`, `clearRetainingCapacity` and
`clearAndFree` functions from the ArrayList API are also useful for a
PriorityQueue.
2025-02-01 19:02:39 +01:00
mlugg
3924f173af compiler: do not propagate result type to try operand
This commit effectively reverts 9e683f0, and hence un-accepts #19777.
While nice in theory, this proposal turned out to have a few problems.

Firstly, supplying a result type implicitly coerces the operand to this
type -- that's the main point of result types! But for `try`, this is
actually a bad idea; we want a redundant `try` to be a compile error,
not to silently coerce the non-error value to an error union. In
practice, this didn't always happen, because the implementation was
buggy anyway; but when it did, it was really quite silly. For instance,
`try try ... try .{ ... }` was an accepted expression, with the inner
initializer being initially coerced to `E!E!...E!T`.

Secondly, the result type inference here didn't play nicely with
`return`. If you write `return try`, the operand would actually receive
a result type of `E!E!T`, since the `return` gave a result type of `E!T`
and the `try` wrapped it in *another* error union. More generally, the
problem here is that `try` doesn't know when it should or shouldn't
nest error unions. This occasionally broke code which looked like it
should work.

So, this commit prevents `try` from propagating result types through to
its operand. A key motivation for the original proposal here was decl
literals; so, as a special case, `try .foo(...)` is still an allowed
syntax form, caught by AstGen and specially lowered. This does open the
doors to allowing other special cases for decl literals in future, such
as `.foo(...) catch ...`, but those proposals are for another time.

Resolves: #21991
Resolves: #22633
2025-02-01 15:48:45 +00:00
Chris Boesch
58c00a829e
std.posix: Use separate clock ID enums for clock_gettime() and timerfd_create() (#22627) 2025-02-01 06:53:57 +00:00
Jacob Young
b9531f5de6 x86_64: rewrite float vector conversions 2025-01-31 23:00:34 -05:00
Michael Dusan
c44be99f1a debug: fix MemoryAccessor file leak
- patch authored by Jacob Young
- tested on alpine-aarch64, 3.21.0, qemu-system 9.2.0
- issue manifested on Alpine Linux aarch64 under qemu-system where
  zig2 fails during bootstrap: error.ProcessFdQuotaExceeded
2025-02-01 04:27:24 +01:00
Alex Kladov
4de2b1ea65 std: don't leak a process in Child.run in case of an error
Closes: #22433
2025-01-31 17:57:39 +01:00
John Benediktsson
c104e86442
std.os.linux: adding recvmmsg() (#22651) 2025-01-31 15:44:50 +00:00
John Benediktsson
53598e36e8
std.posix: adding getsockopt (#22335) 2025-01-30 16:09:29 +00:00
Rui He
c0d85cda53
std.fs.File: limit initial_cap according to max_bytes in readToEndAllocOptions 2025-01-30 16:42:15 +01:00
GalaxyShard
a3ee5215bb
std.Build: Add option to specify language of CSourceFiles
Closes: #20655
2025-01-30 14:04:47 +01:00
Guillaume Wenzek
3348478fc3
Make -freference-trace work without colors
Currently -freference-trace only works when running from a terminal.
This is annoying if you're running in another environment or if you redirect the output.
But -freference-trace also works fine without the color, so change how the build runner is interpreting this option.
2025-01-30 13:02:06 +01: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
Michael Dusan
cd365b8b82 std: fix comptime SemanticVersion expr regression
- effects FreeBSD memfd and Windows DeleteFile
- regression: e5d5a8bc4ea6b27dc3540ad4800a1231ff50b33d
2025-01-30 04:35:27 +01:00
Meghan Denny
7cef585f55 std.c: define more fields for darwin.AI 2025-01-30 01:44:45 +01:00
Alex Rønne Petersen
7d699be772 std.zig.target: Remove some library names from isLibCLibName() for MinGW.
These are system DLLs, most of which MinGW provides .def files for. It just so
happens that MinGW also has some static libraries by the same name which link in
some GUID definitions.

The remaining non-MinGW library names represent libraries that are always
statically linked, so if those are requested by the user, it makes sense to
error if libc is not linked. A future enhancement could be to compile those
independent of mingw32.lib, however.

Closes #22560.
2025-01-29 21:38:34 +01:00
Bing Sun
798bb0bc61
std.c: android bionic compatibility fixes (getrandom & getaddressinfo) (#22143)
Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2025-01-29 19:16:08 +00:00
mlugg
107b65ec5d Sema: explain why we tried to call an extern fn at comptime
I recently saw a user hit the "comptime call of extern function" error,
and get confused because they didn't know why the scope was `comptime`.
So, use `explainWhyBlockIsComptime` on this and related errors to add
all the relevant notes.

The added test case shows the motivating situation.
2025-01-29 18:43:24 +00:00
Alex Rønne Petersen
484f72311e
Merge pull request #22634 from nektro/patch-6
std.c: was missing more
2025-01-29 16:26:57 +01:00
Meghan Denny
0bf57b7114 std: mkdir(2) mode uses mode_t 2025-01-29 14:57:07 +01:00
David Rubin
898658e3a0 std.c: add msghdr and msghdr_const definitions for macos 2025-01-29 13:34:37 +01:00
Alex Rønne Petersen
7843deb16b std.zig.system.darwin: Add driverkit handling in getSdk(). 2025-01-29 09:25:06 +01:00
ThisPC
e528ab4709 std.testing.expectEqual: {any} in print and move tests 2025-01-29 09:19:07 +01:00
thejohnny5
78b7a446f0 std: add optional times pointer for futimes, futimens, utimes, utimensat 2025-01-29 09:17:20 +01:00
Meghan Denny
97ccf3504f std.c: was missing darwin.kevent64_s 2025-01-29 06:34:34 +01:00
Meghan Denny
0bbea1e848
std.c: was missing darwin.@"close$NOCANCEL" 2025-01-27 22:26:20 -08:00
Meghan Denny
1bfadc1381
std.c: was missing darwin.host_t 2025-01-27 21:40:23 -08:00
Meghan Denny
87b0e0821a
std.c: was missing darwin.natural_t 2025-01-27 21:38:25 -08:00
Alex Rønne Petersen
41e7604359
Merge pull request #22573 from sorairolake/fix-invisible-doccomments
Fix invisible doccomments at the start of source files to make them visible
2025-01-28 04:59:14 +01:00
John Benediktsson
884b1423a4 std.heap.memory_pool: make preheat() usable after init() 2025-01-28 00:06:54 +01:00
Andrew Kelley
df1fa36feb Revert "std.http.Server: add Request.getHeader() function (#21625)"
This reverts commit 21823d1b5d1ebfa27df954c2cef5d0f231fb8402.

It's a bad API that could easily lead to O(N^2) logic.
2025-01-27 11:13:56 -08:00
dbubel
21823d1b5d
std.http.Server: add Request.getHeader() function (#21625) 2025-01-27 17:58:05 +00:00
Carter Snook
2043e8ae05
main: classify empty environment variables as unset
This matches existing well-specified conventions for e.g. NO_COLOR.

Closes #22380.
2025-01-27 17:53:32 +01:00
Alex Rønne Petersen
5647dd84c1 Revert d714cf33405486d9aa707e9aee8f103a011d06e9 (#21273)
Turns out this was already fixed in #21964.

I have no idea why GitHub showed an incorrect diff in #21273, or how applying the diff to master was even possible, but here we are.
2025-01-26 20:52:29 -08:00
Shun Sakai
7599216341
std.zip: Include the last paragraph in top-level doc comments
Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2025-01-27 12:24:36 +09:00
injuly
d714cf3340
std.c.darwin: Fix EXC.MASK compile error (#21273) 2025-01-26 19:56:14 +01:00
Fri3dNstuff
9c6d728b0c
std.meta: handle comptime fields in hasUniqueRepresentation (#22132) 2025-01-26 18:23:34 +00:00
Eric Joldasov
3179961854 std.Build: add more explicit error sets to some functions
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
2025-01-26 19:03:33 +01:00
thejohnny5
5b3eaff80d std: check max depth for vector type in formatType 2025-01-26 18:53:11 +01:00
Enrique Miguel Mora Meza
24965af295
std.os.linux: Adding sigdelset (#22406) 2025-01-26 18:49:25 +01:00
Pierre Tachoire
df9fdb1861 std.net.listen: no REUSEPORT with unix socket
On Linux, set REUSEPORT option on an unix socket returns a EOPNOTSUPP error.
See 5b0af621c3
2025-01-26 18:40:34 +01:00
Meghan Denny
92b20e4216 stf: do not call xcode-select or xcrun by absolute path in darwin sdk detection 2025-01-26 09:07:39 +01:00
ziggoon
6a4986b2d6 Update LDR_DATA_TABLE_ENTRY struct 2025-01-26 03:40:17 +01:00
Matthew Lugg
3767b08039
Merge pull request #22602 from mlugg/incr-embedfile
incremental: handle `@embedFile`
2025-01-26 01:41:56 +00:00
Alex Rønne Petersen
015a5e1982 std.Build: Make ofmt part of standardTargetOptions(). 2025-01-25 20:39:10 +01: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
mlugg
5202c977d9
std: add fs.path.fmtJoin
This allows joining paths without allocating using a `Writer`.
2025-01-25 04:48:00 +00:00
Jacob Young
c7433212d1 x86_64: rewrite scalar and vector int @min and @max 2025-01-24 21:02:32 -05:00
Jacob Young
b1fa89439a x86_64: rewrite float vector @abs and equality comparisons 2025-01-24 20:56:11 -05:00