10229 Commits

Author SHA1 Message Date
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
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
mlugg
9804cc8bc6
all: update to std.builtin.Type.{Pointer,Array,StructField} field renames 2025-01-16 12:49:58 +00:00
mlugg
89a9cabafd
std.builtin.Type: improve ergonomics of *const anyopaque fields
For representing struct field default values and array/pointer type
sentinel values, we use `*const anyopaque`, since there is no way for
`std.builtin.Type.StructField` etc to refer back to its `type` field.
However, when introspecting a type, this is quite awkward due to the
pointer casts necessary.

As such, this commit renames the `sentinel` fields to `sentinel_ptr`,
and the `default_value` field to `default_value_ptr`, and introduces
helper methods `sentinel()` and `defaultValue()` to load the values.
These methods are marked as `inline` because their return value, which
is always comptime-known, is very often required at comptime by use
sites, so this avoids having to annotate such calls with `comptime`.

This is a breaking change, although note that 0.14.0 is already a
breaking release for all users of `std.builtin.Type` due to the union
fields being renamed.
2025-01-16 12:49:58 +00:00
mlugg
d00e05f186
all: update to std.builtin.Type.Pointer.Size field renames
This was done by regex substitution with `sed`. I then manually went
over the entire diff and fixed any incorrect changes.

This diff also changes a lot of `callconv(.C)` to `callconv(.c)`, since
my regex happened to also trigger here. I opted to leave these changes
in, since they *are* a correct migration, even if they're not the one I
was trying to do!
2025-01-16 12:46:29 +00:00
mlugg
af6bad46cd
std.builtin.Type: rename Pointer.Size fields to lowercase
This matches established naming conventions. Now is an opportune time to
make this change, since we're already performing breaking changes to
`std.builtin.Type`.
2025-01-16 11:37:46 +00:00
Andrew Kelley
cf898e242a std.Build.Step.CheckObject: better EOF handling
when unexpected end of stream occurs, just add that as a token into the
text
2025-01-15 19:43:46 -08:00
Andrew Kelley
8abdebecdc wasm linker: implement @tagName for sparse enums 2025-01-15 15:11:36 -08:00
Andrew Kelley
4fccb5ae7a wasm linker: improve error messages by making source locations more lazy 2025-01-15 15:11:36 -08:00
Andrew Kelley
fbbb54bab2 std.io: remove the "temporary workaround" for stage2_aarch64 2025-01-15 15:11:36 -08:00
Andrew Kelley
3cb00c5bcd std.ArrayHashMap: allow passing empty values array
in which case the values array is set to undefined
2025-01-15 15:11:35 -08:00
Andrew Kelley
70414c1f43 std.Thread: don't export wasi_thread_start in single-threaded mode 2025-01-15 15:11:35 -08:00
Andrew Kelley
968941b535 wasm linker: finish the flush function
This branch is passing type checking now.
2025-01-15 15:11:35 -08:00