9219 Commits

Author SHA1 Message Date
Andrew Kelley
eb4028bf30 add std.fmt.hex
converts an unsigned integer into an array
2024-07-20 01:06:29 -07:00
Andrew Kelley
9d00f69be5 move std.zig.fatal to std.process.fatal 2024-07-20 01:06:28 -07:00
YANG Xudong
b7e48c6bcd
std: Add loongarch support for elf. (#20678) 2024-07-19 16:32:20 -07:00
Andrew Kelley
0d1db794d5
Merge pull request #20679 from ziglang/std.c-reorg
std.c reorganization
2024-07-19 16:30:21 -07:00
kcbanner
647a0c9b82 mem: handle Float and Bool cases in byteSwapAllFields 2024-07-19 14:09:51 -07:00
Andrew Kelley
01337e2093 fix regression of flock being called on wasi targets
* common symbols are now public from std.c even if they live in
  std.posix
* LOCK is now one of the common symbols since it is the same on 100% of
  operating systems.
* flock is now void value on wasi and windows
* std.fs.Dir now uses flock being void as feature detection, avoiding
  trying to call it on wasi and windows
2024-07-19 11:35:22 -07:00
Techatrix
ebd9efa850 fix fanotify_mark on 32-bit 2024-07-19 01:40:16 -07:00
Andrew Kelley
7157189143 macos doesn't have pipe2 2024-07-19 00:40:00 -07:00
Andrew Kelley
8c4a2dc1df move non-libc stuff out of std.c 2024-07-19 00:30:32 -07:00
Andrew Kelley
e8c4e79499 std.c reorganization
It is now composed of these main sections:
* Declarations that are shared among all operating systems.
* Declarations that have the same name, but different type signatures
  depending on the operating system. Often multiple operating systems
  share the same type signatures however.
* Declarations that are specific to a single operating system.
  - These are imported one per line so you can see where they come from,
    protected by a comptime block to prevent accessing the wrong one.

Closes #19352 by changing the convention to making types `void` and
functions `{}`, so that it becomes possible to update `@hasDecl` sites
to use `@TypeOf(f) != void` or `T != void`. Happily, this ended up
removing some duplicate logic and update some bitrotted feature
detection checks.

A handful of types have been modified to gain namespacing and type
safety. This is a breaking change.

Oh, and the last usage of `usingnamespace` site is eliminated.
2024-07-19 00:30:32 -07:00
Andrew Kelley
e4f5dada61
Merge pull request #19641 from The-King-of-Toasters/windows-api-refactor
Windows: Rework kernel32 apis
2024-07-18 11:44:32 -07:00
eric-saintetienne
c3faae6bf1
format: do not force user to provide an alignment field when it's not necessary (#19049)
* format: fix default character when no alignment

When no alignment is specified, the character that should be used is the
fill character that is otherwise provided, not space.

This is closer to the default that C programmers (and other languages)
use: "04x" fills with zeroes (in zig as of today x:04 fills with spaces)

Test:

    const std = @import("std");
    const expectFmt = std.testing.expectFmt;

    test "fmt.defaultchar.no-alignment" {

        // as of today the following test passes:
        try expectFmt("0x00ff", "0x{x:0>4}", .{255});

        // as of today the following test fails (returns "0x  ff" instead)
        try expectFmt("0x00ff", "0x{x:04}", .{255});
    }

* non breaking improvement of string formatting

* improved comment

* simplify the code a little

* small improvement around how  characters identified as valid are consumed
2024-07-17 19:02:10 +00:00
Stephen Gregoratto
3095e83d11 Windows: Rework kernel32 apis
To facilitate #1840, this commit slims `std.windows.kernel32` to only
have the functions needed by the standard library. Since this will break
projects that relied on these, I offer two solutions:

- Make an argument as to why certain functions should be added back in.
  Note that they may just be wrappers around `ntdll` APIs, which would
  go against #1840.
  If necessary I'll add them back in *and* make wrappers in
  `std.windows` for it.
- Maintain your own list of APIs. This is the option taken by bun[1],
  where they wrap functions with tracing.
- Use `zigwin32`.

I've also added TODO comments that specify which functions can be
reimplemented using `ntdll` APIs in the future.

Other changes:
- Group functions into groups (I/O, process management etc.).
- Synchronize definitions against Microsoft documentation to use the
  proper parameter types/names.
- Break all functions with parameters over multiple lines.
2024-07-17 23:11:23 +10:00
Stephen Gregoratto
1735455099 QueryObjectName: Add error union 2024-07-17 23:05:31 +10:00
Jakub Konka
9d9b5a11e8
Merge pull request #20474 from Rexicon226/riscv
more RISC-V backend progress
2024-07-17 08:39:44 +02:00
Jacob Young
88bb0fd288
Merge pull request #20632 from jacobly0/codegen-thread
InternPool: enable separate codegen/linking thread
2024-07-16 14:49:49 -04:00
mlugg
5093a5cd19
std.Zir: some declaration traversal fixes 2024-07-16 19:44:15 +01:00
Andrew Kelley
a58ceb3d55
Merge pull request #20646 from ziglang/fix-updateZirRefs
frontend: fix updateZirRefs
2024-07-16 10:47:42 -07:00
Jacob Young
e32454796c indexOfSentinel: fix ub 2024-07-16 05:14:38 -04:00
Jacob Young
14caccb477 Progress: avoid race on global_progress.draw_buffer 2024-07-16 05:14:38 -04:00
Andrew Kelley
ba623b160e Zir: fix wrong union field access for declaration 2024-07-15 18:57:36 -07:00
Eric Joldasov
5af68a651c
std.c.LC: mark enum as non-exhaustive
They are implementation-defined and can have values other than
hard-coded here. Also, standard permits other values not mentioned
there:

> Additional macro definitions, beginning with the characters LC_
> and an uppercase letter, may also be specified by the implementation.

Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
2024-07-16 00:32:29 +05:00
Eric Joldasov
ece8480fc2
std.c.setlocale: fix return type to nullable pointer
According to https://en.cppreference.com/mwiki/index.php?title=c/locale/setlocale&oldid=171500 ,
`setlocale` "returns null value on failure":

> Return value
> pointer to a narrow null-terminated string identifying the C locale
> after applying the changes, if any, or null pointer on failure.

Example program:
```zig
const std = @import("std");

pub fn main() void {
    const ptr = std.c.setlocale(.ALL, "non_existent");
    std.debug.print("ptr = {d}\n", .{@intFromPtr(ptr)});
}
```

Output:
```console
ptr = 0
```

Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
2024-07-16 00:27:56 +05:00
Lucas Santos
89942ebd03
Better implementation of GetLastError. (#20623)
Instead of calling the dynamically loaded kernel32.GetLastError, we can extract it from the TEB.
As shown by [Wine](34b1606019/include/winternl.h (L439)), the last error lives at offset 0x34 of the TEB in 32-bit Windows and at offset 0x68 in 64-bit Windows.
2024-07-15 10:49:51 -07:00
Vesim
e5c974fa5c
std.os.linux: export getauxval only when building executable or root has main function 2024-07-15 15:48:40 +03:00
gooncreeper
9002977051
start: refactor callMain return type checking 2024-07-15 12:29:07 +03:00
Veikka Tuominen
5675553aed
Merge pull request #20622 from squeek502/windows-arg-iterator-cleanup
`ArgIteratorWindows`: Cleanup and some optimizations
2024-07-15 12:03:25 +03:00
gooncreeper
c50f300387 Tokenizer bug fixes and improvements
Fixes many error messages corresponding to invalid bytes displaying the
wrong byte. Additionaly improves handling of UTF-8 in some places.
2024-07-15 11:31:19 +03:00
David Rubin
5a2c547fc1
riscv: vectors part 3 2024-07-14 23:02:35 -07:00
David Rubin
f2301ba896
simd: correct suggestVectorLength
* the file's doc-comment was misleading and did not focus on the correct aspect of SIMD

* added cpu flag awareness to `suggestVectorLengthForCpu` in order to provide a more accurate vector length
2024-07-14 23:02:33 -07:00
Andrew Kelley
445bd7a06f build runner: update watch caption to include subprocesses 2024-07-14 22:27:51 -07:00
Andrew Kelley
987f63208e build runner: handle compiler subprocess failures gracefully
Compilation errors now report a failure on rebuilds triggered by file
system watches.

Compiler crashes now report failure correctly on rebuilds triggered by
file system watches.

The compiler subprocess is restarted if a broken pipe is encountered on
a rebuild.
2024-07-14 22:17:29 -07:00
Andrew Kelley
f6c1b71c22 build system: update std.Progress.Node for long-lived children 2024-07-14 21:38:55 -07:00
Andrew Kelley
f33395ce6a std.Progress: add getIpcFd and have_ipc API
This makes advanced use cases possible such as a long-lived child
process whose progress node gets re-attached to a different parent.
2024-07-14 21:38:16 -07:00
Andrew Kelley
716b128a24 frontend: add -fincremental, -fno-incremental flag
Remove --debug-incremental

This flag is also added to the build system. Importantly, this tells
Compile step whether or not to keep the compiler running between
rebuilds. It defaults off because it is currently crashing
zirUpdateRefs.
2024-07-14 21:18:09 -07:00
Andrew Kelley
abf8955951 make zig compiler processes live across rebuilds
Changes the `make` function signature to take an options struct, which
additionally includes `watch: bool`. I intentionally am not exposing
this information to configure phase logic.

Also adds global zig cache to the compiler cache prefixes.

Closes #20600
2024-07-14 19:51:16 -07:00
bing
464537db62
std.crypto.ff: fix typo in montgomery boolean documentation (#20624) 2024-07-14 15:34:02 +02:00
Andrew Kelley
bd7b2cc4b4
Merge pull request #20620 from kcbanner/fixup_msvc_bootstrap
Fixes for bootrapping with MSVC
2024-07-13 22:42:04 -07:00
Ryan Liptak
d48251d0f0 ArgIteratorWindows.init: Take []const u16 slice instead of multi-item pointer
Now that we use the PEB to get the precise length of the command line string, there's no need for a multi-item pointer/sliceTo call. This provides a minor speedup:

    Benchmark 1 (153 runs): benchargv-before.exe
      measurement          mean ± σ            min … max           outliers         delta
      wall_time          32.7ms ±  429us    32.1ms … 36.9ms          1 ( 1%)        0%
      peak_rss           6.49MB ± 5.62KB    6.46MB … 6.49MB         14 ( 9%)        0%
    Benchmark 2 (157 runs): benchargv-after.exe
      measurement          mean ± σ            min … max           outliers         delta
      wall_time          31.9ms ±  236us    31.4ms … 32.7ms          4 ( 3%)        -  2.4% ±  0.2%
      peak_rss           6.49MB ± 4.77KB    6.46MB … 6.49MB         14 ( 9%)          +  0.0% ±  0.0%
2024-07-13 18:37:49 -07:00
Ryan Liptak
1a62cfffa7 Replace GetCommandLineW with PEB access, delete GetCommandLine bindings 2024-07-13 18:19:19 -07:00
Ryan Liptak
1418c8a5d4 ArgIteratorWindows: Store last emitted code unit instead of checking the last 6 emitted bytes
Previously, to ensure args were encoded as well-formed WTF-8 (i.e. no encoded surrogate pairs), the code unit would be encoded and then the last 6 emitted bytes would be checked to see if they were a surrogate pair, and this was done for any emitted code unit (although this was not necessary, it should have only been done when emitting a low surrogate).

After this commit, we still want to ensure well-formed WTF-8, but, to do so, the last emitted code point is stored, meaning we can just directly check that the last code unit is a high surrogate and the current code unit is a low surrogate to determine if we have a surrogate pair.

This provides some performance benefit over and above a "use the same strategy as before but only check when we're emitting a low surrogate" implementation:

    Benchmark 1 (111 runs): benchargv-master.exe
      measurement          mean ± σ            min … max           outliers         delta
      wall_time          45.2ms ±  532us    44.5ms … 49.4ms          2 ( 2%)        0%
      peak_rss           6.49MB ± 3.94KB    6.46MB … 6.49MB         10 ( 9%)        0%
    Benchmark 2 (154 runs): benchargv-storelast.exe
      measurement          mean ± σ            min … max           outliers         delta
      wall_time          32.6ms ±  293us    32.2ms … 34.2ms          8 ( 5%)        - 27.8% ±  0.2%
      peak_rss           6.49MB ± 5.15KB    6.46MB … 6.49MB         15 (10%)          -  0.0% ±  0.0%
    Benchmark 3 (131 runs): benchargv-onlylow.exe
      measurement          mean ± σ            min … max           outliers         delta
      wall_time          38.4ms ±  257us    37.9ms … 39.6ms          5 ( 4%)        - 15.1% ±  0.2%
      peak_rss           6.49MB ± 5.70KB    6.46MB … 6.49MB          9 ( 7%)          -  0.0% ±  0.0%
2024-07-13 18:19:19 -07:00
gooncreeper
ee6a52b40f
std.ArrayList.unusedCapacitySlice: Return unaligned slice (#20490) 2024-07-14 00:56:29 +00:00
Ryan Liptak
10914dc310 ArgIteratorWindows: Clarify buffer length comment 2024-07-13 17:48:08 -07:00
Marc Tiehuis
944c6d40ce std.fmt.formatFloat: skip f80 round-trip tests on x86_64 windows 2024-07-14 11:19:34 +12:00
Harrison McCarty
8ff01f78f3 std.fmt.parseFloat: add f80 formatFloat support 2024-07-14 11:19:34 +12:00
kcbanner
373e53d7c5 Compile: Pass the default --zig-lib-dir along to child processes
main: print the self_exe_path when `findZigLibDirFromSelfExe` fails in all cases
2024-07-13 19:04:55 -04:00
Ryan Liptak
959d227d13 ArgIteratorWindows: Reduce allocated memory by parsing the WTF-16 string directly
Before this commit, the WTF-16 command line string would be converted to WTF-8 in `init`, and then a second buffer of the WTF-8 size + 1 would be allocated to store the parsed arguments. The converted WTF-8 command line would then be parsed and the relevant bytes would be copied into the argument buffer before being returned.

After this commit, only the WTF-8 size of the WTF-16 string is calculated (without conversion) which is then used to allocate the buffer for the parsed arguments. Parsing is then done on the WTF-16 slice directly, with the arguments being converted to WTF-8 on-the-fly.

This has a few (minor) benefits:

- Cuts the amount of memory allocated by ArgIteratorWindows in half (or better)
- Makes the total amount of memory allocated by ArgIteratorWindows predictable, since, before, the upfront `wtf16LeToWtf8Alloc` call could end up allocating more-memory-than-necessary temporarily due to its internal use of an ArrayList. Now, the amount of memory allocated is always exactly `calcWtf8Len(cmd_line) + 1`.
2024-07-13 14:48:17 -07:00
Andrew Kelley
1d20ff11d7
Merge pull request #20580 from ziglang/watch
introduce file system watching features to the zig build system
2024-07-12 16:56:17 -07:00
Andrew Kelley
5efcc2e9e7 build runner: refactor fs watch logic for OS abstraction
Makes the build runner compile successfully for non-linux targets;
printing an error if you ask for --watch rather than making build
scripts fail to compile.
2024-07-12 14:20:20 -07:00
Andrew Kelley
4f9a8b6843 update build system unit test
need to add another field to initialize now
2024-07-12 11:00:52 -07:00