10240 Commits

Author SHA1 Message Date
Alex Rønne Petersen
d916954bee
Merge pull request #22098 from alexrp/wasm-generic-baseline
`std.Target`: Use `lime1` as wasm baseline model and `mvp` as generic model
2025-01-23 18:41:11 +01:00
Pierre Tachoire
f3c29dcb24 std.posix.setsockopt: EOPNOTSUPP can be returned
On Linux, set REUSEPORT option on an unix socket returns a EOPNOTSUPP
error.
See 5b0af621c3
2025-01-23 14:35:57 +01:00
John Benediktsson
530335b572
adding std.c.TCP.NODELAY for macos (#22404)
closes #17260
2025-01-23 04:01:05 +00:00
Alex Rønne Petersen
ea1502974d
wasm: Add a nontrapping_bulk_memory_len0 feature.
This will mainly be used when targeting our wasm2c implementation which has no
problem with zero-length bulk memory operations, as a non-standard extension.
2025-01-22 20:56:28 +01:00
Matthew Lugg
0e815c652d
Merge pull request #22572 from jacobly0/new-error-trace
compiler: include error trace in all functions, implement for x86_64 backend
2025-01-22 16:48:27 +00:00
Matthew Lugg
61fe307d0f
Merge pull request #22571 from mlugg/various-fixes-again
compiler: a few fixes
2025-01-22 16:47:45 +00:00
mlugg
9b7b240c8e std.builtin: make returnError not take the error trace
It's now unnecessary to explicitly pass this, because it receives an
implicit error trace parameter anyway, so can just use
`@errorReturnTrace()`. The previous commit updated Sema to expect this
new interface. This saves an AIR instruction at all `returnError` call
sites.
2025-01-22 02:22:56 -05:00
mlugg
e864c38cc3
Sema: fix crash when inline loop condition is not comptime-known 2025-01-22 04:18:43 +00:00
BratishkaErik
941677e083
std.Build: add addLibrary function (#22554)
Acts as a replacement for `addSharedLibrary` and `addStaticLibrary`, but
linking mode can be changed more easily in build.zig, for example:

In library:
```zig
const linkage = b.option(std.builtin.LinkMode, "linkage", "Link mode for a foo_bar library") orelse .static; // or other default

const lib = b.addLibrary(.{
    .linkage = linkage,
    .name = "foo_bar",
    .root_module = mod,
});
```

In consumer:
```zig
const dep_foo_bar = b.dependency("foo_bar", .{
    .target = target,
    .optimize = optimize,
    .linkage = .static // or dynamic
});

mod.linkLibrary(dep_foor_bar.artifact("foo_bar"));
```

It also matches nicely with `linkLibrary` name.

Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
2025-01-22 02:29:21 +00:00
mlugg
6e7ae66871
std.debug: remove errorReturnTraceHelper
This function doesn't do what it says; it's a nop.
2025-01-22 02:02:33 +00:00
Alex Rønne Petersen
280ced66eb
std.Target: Define and use lime1 as the baseline CPU model for WebAssembly.
See: https://github.com/WebAssembly/tool-conventions/pull/235

This is not *quite* using the same features as the spec'd lime1 model because
LLVM 19 doesn't have the level of feature granularity that we need for that.
This will be fixed once we upgrade to LLVM 20.

Part of #21818.
2025-01-22 03:01:05 +01:00
Alex Rønne Petersen
206373ca61
std.Target: Use mvp as the generic CPU model for wasm32/wasm64.
As discussed in #21818, generic is a poor baseline model because that model is a
moving target in LLVM. Instead, use mvp, which has no features enabled.
2025-01-22 03:01:05 +01:00
mlugg
f244c8891a
std.mem.Allocator: remove redundant check
This check doesn't make sense with the modern Allocator API; it's left over
from when realloc could change alignment. It's statically known (but not
comptime-known) to be true always. This check was one of the things
blocking Allocator from being used at comptime (related: #1291).
2025-01-22 02:00:47 +00: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
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 0595feb34128db22fbebea843af929de3ede8190, reversing
changes made to 744771d3303e122474a72c8a94b14fe1e9fb480c.

closes #22566
closes #22568
2025-01-21 11:22:28 -08:00
andrewkraevskii
f1ce1aff11 std.debug: fix format on ConfigurableTrace 2025-01-21 10:54:14 +01:00
Andrew Kelley
09d021c908 add test coverage for previous commit 2025-01-20 21:41:30 -08:00
Kamil T
d50bae4da9 Fix memcpy alias bug in std.compress.lzma 2025-01-20 21:41:12 -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
1110950528 std.posix.WriteError: update AccessDenied docs
It can happen on POSIX too.
2025-01-20 21:08:44 -08:00
Bryce Vandegrift
e4d5706957 std.posix: Fix errno 13 when writing to file 2025-01-20 21:07:49 -08:00
Andrew Kelley
0d6b17b6a5
Merge pull request #22511 from apwadkar/master
Fix compiler errors in std.process and std.Build.Step.Compile
2025-01-20 22:02:38 -05:00
mlugg
0ec6b2dd88 compiler: simplify generic functions, fix issues with inline calls
The original motivation here was to fix regressions caused by #22414.
However, while working on this, I ended up discussing a language
simplification with Andrew, which changes things a little from how they
worked before #22414.

The main user-facing change here is that any reference to a prior
function parameter, even if potentially comptime-known at the usage
site or even not analyzed, now makes a function generic. This applies
even if the parameter being referenced is not a `comptime` parameter,
since it could still be populated when performing an inline call. This
is a breaking language change.

The detection of this is done in AstGen; when evaluating a parameter
type or return type, we track whether it referenced any prior parameter,
and if so, we mark this type as being "generic" in ZIR. This will cause
Sema to not evaluate it until the time of instantiation or inline call.

A lovely consequence of this from an implementation perspective is that
it eliminates the need for most of the "generic poison" system. In
particular, `error.GenericPoison` is now completely unnecessary, because
we identify generic expressions earlier in the pipeline; this simplifies
the compiler and avoids redundant work. This also entirely eliminates
the concept of the "generic poison value". The only remnant of this
system is the "generic poison type" (`Type.generic_poison` and
`InternPool.Index.generic_poison_type`). This type is used in two
places:

* During semantic analysis, to represent an unknown result type.
* When storing generic function types, to represent a generic parameter/return type.

It's possible that these use cases should instead use `.none`, but I
leave that investigation to a future adventurer.

One last thing. Prior to #22414, inline calls were a little inefficient,
because they re-evaluated even non-generic parameter types whenever they
were called. Changing this behavior is what ultimately led to #22538.
Well, because the new logic will mark a type expression as generic if
there is any change its resolved type could differ in an inline call,
this redundant work is unnecessary! So, this is another way in which the
new design reduces redundant work and complexity.

Resolves: #22494
Resolves: #22532
Resolves: #22538
2025-01-21 02:41:42 +00:00
Andrew Kelley
216e0f3730
Merge pull request #22548 from mlugg/fix-broken-pipe
Wait for reported spawn success or failure before trying to write to the stdio pipe in the build runner.

Hopefully fixes `error.BrokenPipe` failures
2025-01-20 21:40:04 -05:00
Adheesh Wadkar
23facb6a16 Fix dependsOnSystemLibrary compile error 2025-01-20 15:37:57 -06:00
Adheesh Wadkar
b5a2487f7a Fix chdirC compile error 2025-01-20 15:37:57 -06:00
Eric Joldasov
a79e421e59
std.zig.system: use both PATH and hardcoded locations to find env
Should help systems that have main `env` binary in different location
than hardcoded `/usr/bin/env` **during build** (not neccessarily always),
like Nix/Guix, Termux, Gentoo Prefix etc.

Related:
https://www.github.com/ziglang/zig/issues/12156
https://www.github.com/ziglang/zig/issues/14146
https://www.github.com/ziglang/zig/issues/14577
https://www.github.com/ziglang/zig/issues/15898

Source for logic: https://www.github.com/ziglang/zig/issues/14146#issuecomment-2308984936

Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
2025-01-20 14:29:04 +05:00
Eric Joldasov
5bbf3f5561
std.fs.path.joinSepMaybeZ: replace while-loops with for-loops
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
2025-01-20 14:29:01 +05:00
Alex Rønne Petersen
d5db02728c
Merge pull request #22530 from alexrp/omit-unwind-tables
Fix building the standard library without CFI directives
2025-01-20 07:24:12 +01:00
mlugg
048e85f27e
std.process.Child: add waitForSpawn
`std.Build.Step.Run` makes the very reasonable assumption that
`error.InvalidExe` will be reported on `spawn` if it will happen.
However, this property does not currently hold on POSIX targets. This
is, through a slightly convoluted series of events, partially
responsible for the sporadic `BrokenPipe` errors we've been seeing more
and more in CI runs.

Making `spawn` wait for the child to exec in the POSIX path introduces
a block of up to 400us. So, instead of doing that, we add a new API for
this particular case: `waitForSpawn`. This function is a nop on Windows,
but on POSIX it blocks until the child successfully (or otherwise) calls
`execvpe`, and reports the error if necessary. `std.Build.Step.Run`
calls this function, so that it can get `error.InvalidExe` when it wants
it.

I'm not convinced that this API is optimal. However, I think this entire
API needs to be either heavily refactored or straight-up redesigned
(related: #22504), so I'm not too worried about hitting the perfect API:
I'd rather just fix this bug for now, and figure out the long-term goal
a bit later.
2025-01-20 00:27:19 +00:00
mlugg
b8e568504e
std.Build: extend test_runner option to specify whether runner uses std.zig.Server
The previous logic here was trying to assume that custom test runners
never used `std.zig.Server` to communicate with the build runner;
however, it was flawed, because modifying the `test_runner` field on
`Step.Compile` would not update this flag. That might have been
intentional (allowing a way for the user to specify a custom test runner
which *does* use the compiler server protocol), but if so, it was a
flawed API, since it was too easy to update one field without updating
the other.

Instead, bundle these two pieces of state into a new type
`std.Build.Step.Compile.TestRunner`. When passing a custom test runner,
you are now *provided* to specify whether it is a "simple" runner, or
whether it uses the compiler server protocol.

This is a breaking change, but is unlikely to affect many people, since
custom test runners are seldom used in the wild.
2025-01-20 00:14:58 +00:00
Alex Rønne Petersen
b074fb7dda std.zig.system.x86: Update Intel/AMD model detection. 2025-01-19 23:42:39 +01:00
Jacob Young
8ee80d61f6 x86_64: add a bunch of instruction encodings
Closes #19773
2025-01-18 23:30:45 -05:00
Alex Rønne Petersen
db8ed730e7 std.Thread: Fix wasi_thread_start() export to use a pointer.
Closes #22518.
2025-01-19 03:23:00 +01:00
Alex Rønne Petersen
8a78d875cc
std.os.linux: Don't emit CFI directives if unwind tables are disabled. 2025-01-19 02:15:30 +01:00
Alex Rønne Petersen
4de661ef18
start: Don't emit CFI directives if unwind tables are disabled. 2025-01-19 02:15:30 +01:00
Andrew Kelley
a5d2aaa936
Merge pull request #22526 from alexrp/cpu-feature-hacks
`std.zig.system`: Move CPU feature hacks after ABI detection.
2025-01-18 18:22:11 -05:00
Jacob Young
128658038d debug: fix std.debug.NoPanic compile errors 2025-01-18 17:33:10 -05:00
andrewkraevskii
3dadb8c4c9 autodocs: reflow comment to prevent it from been put in blockquote 2025-01-18 15:45:03 +01:00
Alex Rønne Petersen
9758371419
std.zig.system: Move CPU feature hacks after ABI detection.
This was accidentally broken in #22434.
2025-01-18 12:59:38 +01:00
axel escalada
f9a43770c8
std.zip: Add ZIP64 support for local file header extra field
This PR adds support for handling ZIP64 format in local file headers,
when a zip file contains entries where the compressed or uncompressed
size fields are set to 0xFFFFFFFF, and the extra field contains ZIP64
extended information tag (0x0001)

The code now:

Reads the actual sizes from the ZIP64 extra field data
Validates these sizes against the entry's compressed and uncompressed sizes

Zip file format spec.: https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT

This change allows proper extraction of ZIP files that use ZIP64 format in their
local file headers.

Fixes: #22329
2025-01-17 22:55:55 +01:00
pfg
c748eb2416
std.Build: fix setLibCFile() to add step dependencies 2025-01-17 20:42:55 +01:00
Jacob Young
8c8dfb35f3 x86_64: fix crashes compiling the compiler and tests 2025-01-16 20:47:30 -05:00
Jacob Young
63730441d0 x86_64: implement union access 2025-01-16 20:47:30 -05:00
Jacob Young
e5d5a8bc4e x86_64: implement switch jump tables 2025-01-16 20:42:08 -05:00
Jacob Young
ac1a975f9b x86_64: implement clz and not 2025-01-16 20:42:08 -05:00
Jacob Young
7c713251ca x86_64: looped instructions 2025-01-16 20:42:08 -05:00
Jacob Young
beadf702b8 x86_64: rewrite arithmetic 2025-01-16 20:42:08 -05:00
Matthew Lugg
4d8c24c6c5
Merge pull request #22505 from mlugg/easier-modify-builtin
std.builtin.Type renames, and make it easier to modify std.builtin
2025-01-16 22:20:02 +00:00
max
961fc0e140
std.fs.Dir: update deleteTree doc comment to match function signature (#22509)
the actual parameter name is `sub_path` which is also referenced in other
comments describing the fuction.
2025-01-16 20:11:42 +00:00