Commit Graph

197 Commits

Author SHA1 Message Date
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
mlugg
51595d6b75
lib: correct unnecessary uses of 'var' 2023-11-19 09:55:07 +00:00
Andrew Kelley
3fc6fc6812 std.builtin.Endian: make the tags lower case
Let's take this breaking change opportunity to fix the style of this
enum.
2023-10-31 21:37:35 -04:00
Jacob Young
d890e81761 mem: fix ub in writeInt
Use inline to vastly simplify the exposed API.  This allows a
comptime-known endian parameter to be propogated, making extra functions
for a specific endianness completely unnecessary.
2023-10-31 21:37:35 -04:00
Jacob Young
f6f2708d82 x86_64: fix compiler rt test failures 2023-10-29 07:20:36 -04:00
Jacob Young
3b0dce8ebd
Merge pull request #17716 from jacobly0/x86_64
x86_64: pass more tests
2023-10-27 08:29:24 -04:00
Travis Staloch
8f48533691 GenericReader error set fixes
add error.EndOfStream to readEnum() and isBytes() so that users can
catch these errors.  this also prevents them from panicing with
'invalid error value' on EndOfStream.

test both methods.
2023-10-27 05:50:33 -04:00
Jacob Young
5e83441096 x86_64: implement @divFloor and @mod for i128 2023-10-26 21:45:57 -04:00
Jacob Young
8f69e977f1 x86_64: implement 128-bit builtins
* `@clz`
 * `@ctz`
 * `@popCount`
 * `@byteSwap`
 * `@bitReverse`
 * various encodings used by std
2023-10-23 22:42:18 -04:00
Jacob Young
27fe945a00 Revert "Revert "Merge pull request #17637 from jacobly0/x86_64-test-std""
This reverts commit 6f0198cadb.
2023-10-22 15:46:43 -04:00
Andrew Kelley
6f0198cadb Revert "Merge pull request #17637 from jacobly0/x86_64-test-std"
This reverts commit 0c99ba1eab, reversing
changes made to 5f92b070bf.

This caused a CI failure when it landed in master branch due to a
128-bit `@byteSwap` in std.mem.
2023-10-22 12:16:35 -07:00
Jacob Young
0c99ba1eab
Merge pull request #17637 from jacobly0/x86_64-test-std
x86_64: start to enable `test-std` and `test-compiler-rt` testing
2023-10-22 08:06:47 -04:00
JustinWayland
c45af2af61
Fix simple doc mistakes. (#17624)
* Add missing period in Stack's description

This looks fine in the source, but looks bad when seen on the documentation website.

* Correct documentation for attachSegfaultHandler()

The description for attachSegfaultHandler() looks pretty bad without indicating that the stuff at the end is code

* Added missing 'the's in Queue.put's documentation

* Fixed several errors in Stack's documentation

`push()` and `pop()` were not styled as code

There was no period after `pop()`, which looks bad on the documentation.

* Fix multiple problems in base64.zig

Both "invalid"s in Base64.decoder were not capitalized.

Missing period in documentation of Base64DecoderWithIgnore.calcSizeUpperBound.

* Fix capitalization typos in bit_set.zig

In DynamicBitSetUnmanaged.deinit's and DynamicBitSet.deinit's documentation, "deinitializes" was uncapitalized.

* Fix typos in fifo.zig's documentation

Added a previously missing period to the end of the first line of LinearFifo.writableSlice's documentation.
Added missing periods to both lines of LinearFifo.pump's documentation.

* Fix typos in fmt.bufPrint's documentation

The starts of both lines were not capitalized.

* Fix minor documentation problems in fs/file.zig

Missing periods in documentation for Permissions.setReadOnly, PermissionsWindows.setReadOnly, MetadataUnix.created, MetadataLinux.created, and MetadataWindows.created.

* Fix a glaring typo in enums.zig

* Correct errors in fs.zig

* Fixed documentation problems in hash_map.zig

The added empty line in verify_context's documentation is needed, otherwise autodoc for some reason assumes that the list hasn't been terminated and continues reading off the rest of the documentation as if it were part of the second list item.

* Added lines between consecutive URLs in http.zig

Makes the documentation conform closer to what was intended.

* Fix wrongfully ended sentence in Uri.zig

* Handle wrongly entered comma in valgrind.zig.

* Add missing periods in wasm.zig's documentation

* Fix odd spacing in event/loop.zig

* Add missing period in http/Headers.zig

* Added missing period in io/limited_reader.zig

This isn't in the documentation due to what I guess is a limitation of autodoc, but it's clearly supposed to be. If it was, it would look pretty bad.

* Correct documentation in math/big/int.zig

* Correct formatting in math/big/rational.zig

* Create an actual link to ZIGNOR's paper.

* Fixed grammatical issues in sort/block.zig

This will not show up in the documentation currently.

* Fix typo in hash_map.zig
2023-10-21 21:24:55 +00:00
Jacob Young
32e85d44eb x86_64: disable failing tests, enable test-std testing 2023-10-21 10:55:41 -04:00
Jacob Young
2e6e39a700 x86_64: fix bugs and disable erroring tests 2023-10-21 10:55:41 -04:00
Andrew Kelley
d8540dd708 std: add type-erased reader; base GenericReader on it
The idea here is to avoid code bloat by having only one actual io.Reader
implementation, which is type erased, and then implement a GenericReader
that preserves type information on top of that as thin glue code.

The strategy here is for that glue code to `@errSetCast` the result of
the type-erased reader functions, however, while trying to do that I
ran into #17343.
2023-10-03 14:55:17 -07:00
antlilja
bcf4a13913 Remove @fabs, fabs and absCast/Int from std lib
Replaces occurences of @fabs absCast and absInt with new @abs builtin.
Also removes the std.math.fabs alias from math.zig.
2023-09-27 11:24:28 -07:00
lockbox
9b56c7de79 Fix type mismatch for Reader.readIntoBoundedBytes (#16416)
- add unit test to verify .readIntoBoundedBytes behavior
- add unit test to verify .readBoundedBytes behavior
2023-07-24 17:32:06 -07:00
Andrew Kelley
17890f6b8a
Merge pull request #15879 from r00ster91/more_stage1_test_coverage
More stage1 test coverage
2023-07-03 15:59:54 -07:00
xdBronch
0dffab7356 check for UEFI in io.StreamSource 2023-07-03 11:00:54 -07:00
Ryan Liptak
689f3163af Fix TTY.detectConfig regression on windows
e05412669c inadvertently changed the logic on Windows and made it so that supportsAnsiEscapeCodes was never checked. This fixes that regression while keeping the logic intact for other platforms.
2023-07-02 00:07:24 -07:00
r00ster91
11c32c756f fix u65529 and above overflowing in more places
See also #15537
2023-06-27 19:08:24 -04:00
mlugg
f26dda2117 all: migrate code to new cast builtin syntax
Most of this migration was performed automatically with `zig fmt`. There
were a few exceptions which I had to manually fix:

* `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten
* `@truncate`'s fixup is incorrect for vectors
* Test cases are not formatted, and their error locations change
2023-06-24 16:56:39 -07:00
dweiller
e45d24c0de rename ZIG_DEBUG_COLOR env variable to YES_COLOR 2023-06-22 10:29:45 +10:00
dweiller
e05412669c std.io.tty: add detectTtyConfigForce for forcing color 2023-06-22 10:29:45 +10:00
Eric Joldasov
50339f595a all: zig fmt and rename "@XToY" to "@YFromX"
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-19 12:34:42 -07:00
r00ster91
2593156068 migration: std.math.{min, min3, max, max3} -> @min & @max 2023-06-16 13:44:09 -07:00
Eric Joldasov
5c6f111379 std.io.reader.Reader: add streamUntilDelimiter
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-03 13:38:23 -07:00
Cortex
6e6a61a384
std.io.Writer: add support for non-power-of-two int sizes 2023-05-29 13:01:54 +03:00
Linus Groh
93d9c9bf31 std.io.tty: Remove unused Config.writeDEC() function
For reference:
https://github.com/ziglang/zig/pull/15806#discussion_r1203377118
2023-05-24 10:15:47 +01:00
Linus Groh
5d3f3cae64 std.io.tty: Add missing colors to Color enum
Also make colors not bold by default, that's what .bold is for.
2023-05-24 10:15:02 +01:00
Linus Groh
0f6fa3f20b std: Move std.debug.{TTY.Config,detectTTYConfig} to std.io.tty
Also get rid of the TTY wrapper struct, which was exlusively used as a
namespace - this is done by the tty.zig root struct now.

detectTTYConfig has been renamed to just detectConfig, which is enough
given the new namespace. Additionally, a doc comment had been added.
2023-05-24 10:15:02 +01:00
Motiejus Jakštys
b61d0debd6 multi-writer: test with a non-comptime stream
Since #14819 this test failed with:

    $ ../../../build/stage3/bin/zig test multi_writer.zig
    multi_writer.zig:26:57: error: unable to evaluate comptime expression
                var batch = std.event.Batch(Error!void, self.streams.len, .auto_async).init();
                                                        ~~~~^~~~~~~~
    referenced by:
        Writer: multi_writer.zig:19:52
        writer: multi_writer.zig:21:36
        remaining reference traces hidden; use '-freference-trace' to see all reference traces

Thanks @jacobly for hints how to fix this on IRC.
2023-05-19 09:13:49 -07:00
Dominic
5a3eca5d4c
Disallow named test decls with duplicate names 2023-05-08 10:59:06 +03:00
Andrew Kelley
6261c13731 update codebase to use @memset and @memcpy 2023-04-28 13:24:43 -07:00
Isaac Freund
23b7d28896 std: restrict mem.span() and mem.len() to sentinel terminated pointers
These functions are currently footgunny when working with pointers to
arrays and slices. They just return the stated length of the array/slice
without iterating and looking for the first sentinel, even if the
array/slice is a sentinel terminated type.

From looking at the quite small list of places in the standard
library/compiler that this change breaks existing code, the new code
looks to be more readable in all cases.

The usage of std.mem.span/len was totally unneeded in most of the cases
affected by this breaking change.

We could remove these functions entirely in favor of other existing
functions in std.mem such as std.mem.sliceTo(), but that would be a
somewhat nasty breaking change as std.mem.span() is very widely used for
converting sentinel terminated pointers to slices. It is however not at
all widely used for anything else.

Therefore I think it is better to break these few non-standard and
potentially incorrect usages of these functions now and at some later
time, if deemed worthwhile, finally remove these functions.

If we wait for at least a full release cycle so that everyone adapts to
this change first, updating for the removal could be a simple find and
replace without needing to worry about the semantics.
2023-01-29 15:07:06 -05:00
fn ⌃ ⌥
e45b471ad3
Find system-installed root SSL certificates on macOS (#14325) 2023-01-16 22:34:04 +00:00
Andrew Kelley
4d306ebd32 fix std.io.Reader regression
oops. #14264
2023-01-11 15:39:49 -08:00
Andrew Kelley
f945c2a1c8 expose std.io.bufferedReaderSize
This allows setting a custom buffer size. In this case I wanted it
because using a buffer size large enough to fit a TLS ciphertext record
elides a memcpy().

This commit also adds `readAtLeast` to the Reader interface.
2023-01-11 15:39:48 -08:00
Veikka Tuominen
58c1d98c14 add tests for fixed stage1 bugs
Closes #4144
Closes #4255
Closes #4372
Closes #4375
Closes #4380
Closes #4417
Closes #4423
Closes #4476
Closes #4528
Closes #4562
Closes #4572
Closes #4597
Closes #4639
Closes #4672
Closes #4782
Closes #4955
Closes #4984
Closes #4997
Closes #5010
Closes #5114
Closes #5166
Closes #5173
Closes #5276
2022-12-31 20:49:02 -05:00
Walther Chen
ff1eff9979
std: stop using LinearFifo in BufferedReader (#14029)
See also commit 7287c7482a where
LinearFifo is removed from BufferedWriter

Basically, LinearFifo does extra work via copying bytes and increasing
an offset.
2022-12-28 21:44:58 -05:00
r00ster91
aac2d6b56f std.builtin: rename Type.UnionField and Type.StructField's field_type to type 2022-12-17 14:11:33 +01:00
Andrew Kelley
ceb0a632cf std.mem.Allocator: allow shrink to fail
closes #13535
2022-11-29 23:30:38 -07:00
antlilja
ae8d26a6a0 Sema: add error for non-comptime param in comptime func
Adds error for taking a non comptime parameter in a function returning a
comptime-only type but not when that type is dependent on a parameter.

Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-08-27 11:17:48 +03:00
InKryption
f1999712b0 std.io.Reader: bounded array functions
* Add readIntoBoundedBytes
 * Add readBoundedBytes
2022-08-22 14:07:22 +03:00
Andrew Kelley
6ab5219e34 std: update test cases to reflect new packed struct semantics 2022-07-12 18:38:11 -07:00
Veikka Tuominen
0a9d6956e7 Sema: add missing set_union_tag 2022-06-12 19:17:41 +03:00
Veikka Tuominen
413577c881 std: adjust for stage2 semantics 2022-06-07 21:27:07 +03:00
Veikka Tuominen
6d44c0a16c std: update tests to stage2 semantics 2022-06-03 20:21:20 +03:00
Ali Chraghi
0e6285c8fc math: make cast return optional instead of an error 2022-05-27 16:43:33 -04:00