8053 Commits

Author SHA1 Message Date
David Rubin
069a079ddc complete todo 2023-11-26 14:27:39 -05:00
Andrew Kelley
7103088e4a
Merge pull request #18105 from Vexu/translate-c
Use Aro's tokenizer in `translate-c`
2023-11-26 02:22:51 -05:00
Bogdan Romanyuk
2ff707be78
AstGen: check allowed non-function builtins with declarative field (#18120) 2023-11-26 02:21:58 -05:00
Veikka Tuominen
74010fecc7 translate-c: use Aro's tokenizer 2023-11-25 12:28:19 +02:00
Andrew Kelley
648f592db1
Merge pull request #18109 from nektro/std-compiler
compiler: move BuiltinFn and AstRlAnnotate to std.zig namespace
2023-11-25 04:11:46 -05:00
Andrew Kelley
e834e95d71 Revert "std.SinglyLinkedList: add sort function"
This reverts commit 8b10970836480a43a3bbb1276cb258c2a8b613f2.

This implementation has the following problems:

* It does not provide context to the less than function. This will be an
  API break in order to fix.
* It uses recursion, causing unbounded stack memory usage - likely
  depending on user input, which is extra problematic.
* Sorting linked lists is generally an inefficient operation;
  encouraging it by having a standard library function for it may
  lead to suboptimal software being written in Zig.

Furthermore, there is almost no benefit to providing a sort function as
a method, when a third party implementation can easily be passed a
linked list to then be sorted.
2023-11-24 22:33:50 -07:00
Meghan Denny
121d995fcb frontend: move AstRlAnnotate to std.zig namespace 2023-11-24 17:09:08 -08:00
Meghan Denny
84d58aaa1f frontend: move BuiltinFn to std.zig namespace 2023-11-24 17:04:52 -08:00
Justus Klausecker
8b10970836
std.SinglyLinkedList: add sort function 2023-11-24 23:49:12 +00:00
Luca Ivaldi
3acb0e30a0
std.fmt: fix overflow when formatting comptime_float 2023-11-24 18:31:12 +02:00
John Benediktsson
54f4abae2f
Deprecate math.doNotOptimizeAway, use mem.doNotOptimizeAway (#18011) 2023-11-23 15:06:32 -05:00
Andrew Kelley
464ce8ac67
Merge pull request #18091 from squeek502/no-shell32-no-ole32
Remove Zig's internal depedency on `shell32.dll` and `ole32.dll`
2023-11-23 14:49:56 -05:00
Ryan Liptak
0bc4ee1792 Remove std.os.windows.ole32/shell32 2023-11-23 03:06:47 -08:00
Andrew Kelley
2bffd81015
Merge pull request #18085 from ziglang/std-atomics
rework std.atomic
2023-11-23 04:55:28 -05:00
Ryan Liptak
2c326d4390 std.os.windows: Add HKEY_CLASSES_ROOT 2023-11-23 01:11:53 -08:00
Ryan Liptak
d42418d614 Replace shell32.SHGetKnownFolderPath usage with LOCALAPPDATA env var
Removes the dependency on shell32.dll. This is a stop gap solution until a proper SHGetKnownFolderPath Zig implementation is written
2023-11-23 01:11:53 -08:00
Ryan Liptak
fcc071c9bd Remove unnecessary branch on absolute path
Also remove the TODO--it was added in fd067fbe8b14c445ed764da15fff5163156126df, but the current code no longer used that workaround, so this TODO didn't seem relevant anymore.
2023-11-23 03:45:17 -05:00
Andrew Kelley
f4e426a06c
Merge pull request #18076 from ziglang/revert-iterable-dir
std.fs: Absorb `IterableDir` into `Dir`
2023-11-23 01:44:07 -05:00
Andrew Kelley
6fc20b3b09 std.os.windows: remove volatile from inline asm
This inline assembly has no side effects.
2023-11-23 00:52:35 -05:00
Andrew Kelley
70931dbdea rework std.atomic
* move std.atomic.Atomic to std.atomic.Value
* fix incorrect argument order passed to testing.expectEqual
* make the functions be a thin wrapper over the atomic builtins and
  stick to the naming conventions.
* remove pointless functions loadUnchecked and storeUnchecked. Instead,
  name the field `raw` instead of `value` (which is redundant with the
  type name).
* simplify the tests by not passing every possible combination. Many
  cases were iterating over every possible combinations but then not
  even using the for loop element value!
* remove the redundant compile errors which are already implemented by
  the language itself.
* remove dead x86 inline assembly. this should be implemented in the
  language if at all.
2023-11-22 19:08:55 -07:00
Andrew Kelley
edb2f72988 std: remove atomic.Queue
This was originally supposed to be a lock-free queue, but I gave up on
that and made it be a thread-safe queue instead.

Putting the mutex directly inside the queue data structure makes it
non-composeable. Instead, the recommendation is to use a normal queue
protected by an external mutex.
2023-11-22 16:39:37 -07:00
Andrew Kelley
6bd97ab640 std: remove atomic.Stack
This was originally supposed to be a lock-free stack, but I gave up on
that and made it be a thread-safe stack which is implemented poorly
using spin locks. Nobody should use this data structure.

The alternative is a normal stack protected by a mutex.
2023-11-22 16:38:26 -07:00
Andrew Kelley
0a536a7c90 std.fs.File: flatten struct 2023-11-22 15:24:57 -07:00
Andrew Kelley
e00e9c0fbf std.fs: extract AtomicFile to separate file 2023-11-22 15:24:57 -07:00
Andrew Kelley
c95e2e65fa std.fs: extract Dir into separate file 2023-11-22 15:24:57 -07:00
Andrew Kelley
e357550610 update for the std.fs.Dir changes 2023-11-22 15:24:57 -07:00
Andrew Kelley
1fa2e911d9 std.atomic: remove some APIs
* remove `std.atomic.Ordering`
  - it is provided by the language with `std.builtin.AtomicOrder`.
* remove `std.atomic.fence`
  - it is provided by the language with `@fence`.
* remove `std.atomic.compilerFence`
  - if this is desired, it should be a language feature, not a standard
    library function with inline asm.
2023-11-22 14:27:49 -07:00
Andrew Kelley
519ba9bb65 Revert "Merge pull request #12060 from Vexu/IterableDir"
This reverts commit da94227f783ec3c92859c4713b80a668f1183f96, reversing
changes made to 8f943b3d33432a26b7e242c1181e4220ed400501.

I was against this change originally, but decided to approve it to keep
an open mind. After a year of trying it in practice, I firmly believe
that the previous way of doing it was better.
2023-11-22 12:35:33 -07:00
Andrew Kelley
49d6dd3ecb std.crypto.ff: simplify implementation
* Take advantage of multi-object for loops.
* Remove use of BoundedArray since it had no meaningful impact on safety
  or readability.
* Simplify some complex expressions, such as using `!` to invert a
  boolean value.
2023-11-22 11:32:14 -07:00
Andrew Kelley
7b3556a8cf std.fs: make deleteTree use ArrayList instead of BoundedArray
We definitely want ArrayList in the standard library. Do we want
BoundedArray? Maybe, maybe not. But that makes ArrayList a more stable
dependency for std.fs.
2023-11-22 11:32:14 -07:00
Andrew Kelley
f6549a956d std.ArrayList: add initBuffer to the unmanaged array list
This is useful when you want to have an array list backed by a fixed
slice of memory and no Allocator will be used.

It's an alternative to BoundedArray as you will see in the following
commit.
2023-11-22 11:32:14 -07:00
Andrew Kelley
d5e21a4f1a std: remove meta.trait
In general, I don't like the idea of std.meta.trait, and so I am
providing some guidance by deleting the entire namespace from the
standard library and compiler codebase.

My main criticism is that it's overcomplicated machinery that bloats
compile times and is ultimately unnecessary given the existence of Zig's
strong type system and reference traces.

Users who want this can create a third party package that provides this
functionality.

closes #18051
2023-11-22 13:24:27 -05:00
Hong Shick Pak
994e191643
std.Uri: fix parsing edge case panic 2023-11-22 07:40:30 +00:00
Mikko Kaihlavirta
ea4a07701e add missing timeval struct 2023-11-22 01:15:11 +02:00
Andrew Kelley
be6f76655f
Merge pull request #18055 from ziglang/zig-init 2023-11-21 11:59:24 -05:00
Jan Philipp Hafer
27b34a5b77 std.net: enable forcing non-blocking mode for accept
Justification: It is common for non-CPU bound short routines to do
non-blocking accept to eliminate unnecessary delays before subscribing
to data, for example in hardware integration tests.
2023-11-21 18:04:33 +02:00
Michael Pfaff
478c89b46f
std.heap: Use @alignOf(T) rather than 0 if not manually overridden for alignment of MemoryPool items 2023-11-21 13:23:53 +00:00
salo-dea
a58ecf7b09 Do not assume that FILE_BOTH_DIR_INFORMATION is correctly aligned 2023-11-21 15:21:41 +02:00
Wooster
5d241a1478 std.debug: detect general protection faults on x86_64-linux
```zig
const std = @import("std");

pub fn main() !void {
	var addr: *u8 = @ptrFromInt(0xaaaaaaaaaaaaaaaa);
	addr.* = 1;
}
```

On x86_64-linux:

Before:
```
$ zig run x.zig
Segmentation fault at address 0x0
/home/wooster/Desktop/zig/x.zig:5:5: 0x21d887 in main (x)
    addr.* = 1;
    ^
/home/wooster/Desktop/zig-linux-x86_64/lib/std/start.zig:583:37: 0x21d847 in posixCallMainAndExit (x)
            const result = root.main() catch |err| {
                                    ^
/home/wooster/Desktop/zig-linux-x86_64/lib/std/start.zig:251:5: 0x21d371 in _start (x)
    asm volatile (switch (native_arch) {
    ^
???:?:?: 0x0 in ??? (???)
Aborted (core dumped)
```

After:
```
$ zig run x.zig --zig-lib-dir lib
General protection exception
/home/wooster/Desktop/zig/x.zig:5:5: 0x21d907 in main (x)
    addr.* = 1;
    ^
/home/wooster/Desktop/zig/lib/std/start.zig:583:37: 0x21d8c7 in posixCallMainAndExit (x)
            const result = root.main() catch |err| {
                                    ^
/home/wooster/Desktop/zig/lib/std/start.zig:251:5: 0x21d3f1 in _start (x)
    asm volatile (switch (native_arch) {
    ^
???:?:?: 0x0 in ??? (???)
Aborted (core dumped)
```

As @IntegratedQuantum pointed out in <https://github.com/ziglang/zig/issues/17745#issuecomment-1783815386>,
it seems that if `code` of the `siginfo_t` instance is a certain value (128), you are able to distinguish between
a general protection exception and a segmentation fault.

This does not seem to be documented on `man sigaction`:
```
The following values can be placed in si_code for a SIGSEGV signal:

           SEGV_MAPERR
                  Address not mapped to object.

           SEGV_ACCERR
                  Invalid permissions for mapped object.

           SEGV_BNDERR (since Linux 3.19)
                  Failed address bound checks.

           SEGV_PKUERR (since Linux 4.6)
                  Access was denied by memory protection keys.  See pkeys(7).  The protection key which applied to this access is available via si_pkey.
```
(those constants are 1, 2, 3, and 4; none of them are the 128)

I can't find a lot of documentation about this but it seems to work consistently for me on x86_64-linux.
Here is a gist which provides additional evidence that this is a reliable way of checking for a general protection fault:
https://gist.github.com/ytoshima/5682393 (read comment in first line)

See also: https://stackoverflow.com/questions/64309366/why-is-the-segfault-address-null-when-accessing-memory-that-has-any-of-the-16-mo

This only seems to affect x86_64 and on 32-bit x86 this does not seem to be a problem.

Helps with #17745 but doesn't close it because the issue still exists on Windows and other POSIX OSs.

I also limited this to x86_64-linux for now because that's the only platform where I tested it. Might work on more POSIX OSs.
2023-11-21 14:22:11 +02:00
expikr
40bd93e2a2 replace qpf and qpc
Update windows.zig

Update windows.zig

Update windows.zig

Update windows.zig

Update windows.zig

Update windows.zig

Update windows.zig

Update ntdll.zig

Update windows.zig

Update ntdll.zig

Update kernel32.zig
2023-11-21 14:10:25 +02:00
Naboris
c25f2fa561 std.RingBuffer.zig: Fix typo in readLastAssumeLength 2023-11-21 13:55:09 +02:00
Ryan Liptak
15a6b27957 std.unicode: Disable utf8 -> utf16 ASCII fast path on mips
Fixes a compile error when the target is mips, since std.simd.interlace does not work correctly on mips and raises a compile error if it is used.
2023-11-21 13:51:03 +02:00
Andrew Kelley
f645022d16 merge zig init-exe and zig init-lib into zig init
Instead of `zig init-lib` and `zig init-exe`, now there is only
`zig init`, which initializes any of the template files that do not
already exist, and makes a package that contains both an executable and
a static library. The idea is that the user can delete whatever they
don't want. In fact, I think even more things should be added to the
build.zig template.
2023-11-20 23:01:45 -07:00
Maciej 'vesim' Kuliński
f64f3423e4 std.tar: trim also spaces from the beginning of file size 2023-11-21 00:55:22 -05:00
Tw
8ca4a5240e linux/bpf: update helper definitions
Signed-off-by: Tw <tw19881113@gmail.com>
2023-11-19 19:01:18 +02:00
mlugg
766306793a
std: correct faulty test 2023-11-19 11:11:50 +00:00
mlugg
51595d6b75
lib: correct unnecessary uses of 'var' 2023-11-19 09:55:07 +00:00
dweiller
325e0f5f0e test: check compile errors when compilation has no errors 2023-11-19 00:12:43 +02:00
Eric Joldasov
4e212f1650 std.enums: allow non-exhaustive enums in EnumIndexer and make count comptime_int instead of usize
Seems like this restriction was actual when Ziglang had extern enums,
but now it's not neccessary and can be lifted. It was present since
original PR which introduced std.enums, https://www.github.com/ziglang/zig/pull/8171.
See also: https://ziggit.dev/t/catching-invalid-enum-value-errors/2206/11

* Make `count` comptime_int instead of usize

With previous type, creating EnumIndexer for enum(usize) and enum(isize)
would cause compile error since `count` could not store maxInt(usize) + 1.
Now it can store it and reflects len field from std.builtin.Type.Array
(most common use case of count field inside std.enums functions is creating arrays).

Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-11-18 16:25:55 +02:00
Lucas Santos
d44f822821 Faster implementation of intToEnum. 2023-11-18 11:24:13 +02:00