Commit Graph

119 Commits

Author SHA1 Message Date
samy007 4595b1ee06 std.mem.bytesAsSlice: fix to support zero-bytes sized types
also added a test for json parsing of zero sized type
2025-03-24 22:08:05 +01:00
Andrew Kelley d12123a88c std.ArrayList: initial capacity based on cache line size
also std.MultiArrayList
2025-02-13 00:19:03 -08:00
Meghan Denny 9142482372 std.ArrayList: popOrNull() -> pop() [v2] (#22720) 2025-02-10 04:21:31 +00:00
mlugg 9804cc8bc6 all: update to std.builtin.Type.{Pointer,Array,StructField} field renames 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
Linus Groh 8588964972 Replace deprecated default initializations with decl literals 2024-09-12 16:01:23 +01:00
pfg c97db8e497 Support stringifying non-exhaustive enum to json (#21228) 2024-09-07 11:06:41 -04:00
mlugg 0fe3fd01dd std: update std.builtin.Type fields to follow naming conventions
The compiler actually doesn't need any functional changes for this: Sema
does reification based on the tag indices of `std.builtin.Type` already!
So, no zig1.wasm update is necessary.

This change is necessary to disallow name clashes between fields and
decls on a type, which is a prerequisite of #9938.
2024-08-28 08:39:59 +01:00
Josh Wolfe febfcbd49d std.json.WriteStream supports streaming long values directly to the underlying stream (#21155) 2024-08-22 08:26:14 -04:00
Josh Wolfe a805454dea fix partial strings getting dropped when multi-byte codepoints span input buffers 2024-08-07 06:29:34 -04:00
Josh Wolfe 8bec737ca2 fix tests actually checking string contents 2024-08-07 06:29:34 -04:00
Eugene-Dash 81a172a506 Add std.json.ParseOptions.parse_numbers to preserve float precision (#20744) 2024-07-25 20:55:06 -04:00
Techatrix 8f7b50e2c4 json: respect duplicate_field_behavior in std.json.Value.jsonParse 2024-07-03 15:34:59 -04:00
Andrew Kelley f97c2f28fd update the codebase for the new std.Progress API 2024-05-27 20:56:48 -07:00
Ryan Liptak a52f12afc9 Delete compile errors for deprecated decls 2024-05-03 13:27:30 -07:00
Josh Wolfe 05b185811e json.WriteStream.objectFieldRaw() (#19553) 2024-04-06 03:52:20 -04:00
Marc Tiehuis b6695f0542 std.json: update tests to match new floating point formatting 2024-03-09 17:03:05 +13:00
Ryan Liptak 16b3d1004e Remove redundant test name prefixes now that test names are fully qualified
Follow up to #19079, which made test names fully qualified.

This fixes tests that now-redundant information in their test names. For example here's a fully qualified test name before the changes in this commit:

"priority_queue.test.std.PriorityQueue: shrinkAndFree"

and the same test's name after the changes in this commit:

"priority_queue.test.shrinkAndFree"
2024-02-26 15:18:31 -08:00
Techatrix 556db2ca36 json: make std.json.stringifyAlloc return a mutable slice (#19013) 2024-02-20 09:03:00 -05:00
Andrew Kelley bd46410419 Revert "Merge pull request #18410 from dweiller/by-length-slice-bug"
This reverts commit d9d840a33a, reversing
changes made to a04d433094.

This is not an adequate implementation of the missing safety check, as
evidenced by the changes to std.json that are reverted in this commit.

Reopens #18382
Closes #18510
2024-01-13 23:21:44 -07:00
Bogdan Romanyuk 4a1a5ee47b AstGen: add error for redundant comptime var in comptime scope (#18242) 2024-01-09 20:09:39 -05:00
Carl Åstholm d7b36503ca Remove some @as coercions from assertions
These are some spurious fixes to help illustrate the improved ergonomics of the `expectEqual` change. It is by no means complete.
2024-01-03 21:20:48 +01:00
dweiller 41d5aa1b36 prevent by-length slice compile error in static json parsing 2023-12-31 15:36:58 +11:00
Marcius ff17b11692 refact: rectifified a typo in docs of stringify.zig 2023-12-28 00:06:30 +02: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
mlugg 51595d6b75 lib: correct unnecessary uses of 'var' 2023-11-19 09:55:07 +00:00
Linus Groh e72049bc61 std.math: Add isPositiveZero() and isNegativeZero() 2023-11-09 00:55:43 -07:00
Jacob Young a440cf6d44 x86_64: fix c abi test failures 2023-10-27 23:31:20 -04:00
Linus Groh 772636ed0d std.json: Parse -0 as a float instead of an integer (#17729)
This is consistent with `JSON.parse("-0")` in JavaScript, RFC 8259
doesn't specifically mention what to do in this case.
If a negative zero is encoded the intention is likely to preserve the
sign.
2023-10-27 18:05:51 +00:00
Jacob Young 98cd378208 x86_64: fix behavior of getValue
Old behavior renamed to `getValueIfFree`.
2023-10-26 21:45:58 -04:00
Jacob Young b55377a5ab x86_64: pass more tests
* 128-bit integer multiplication with overflow
 * more instruction encodings used by std inline asm
 * implement the `try_ptr` air instruction
 * follow correct stack frame abi
 * enable full panic handler
 * enable stack traces
2023-10-25 04:28:30 -04:00
Jacob Young fe93332ba2 x86_64: implement enough to pass unicode tests
* implement vector comparison
 * implement reduce for bool vectors
 * fix `@memcpy` bug
 * enable passing std tests
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 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
Jonathan Marler 223f62acbd std.json: add fmt function (#17055)
Adds std.json.fmt which returns a std.fmt Formatter that formats any
given value using std.json.stringify.
2023-09-13 18:24:59 -04:00
Techatrix 7827265ea8 json: respect max_value_len when parsing std.json.Value (#17107) 2023-09-11 17:00:06 -04:00
Gregory Anders cab9da35bd std: enable FailingAllocator to fail on resize
Now that allocator.resize() is allowed to fail, programs may wish to
test code paths that handle resize() failure. The simplest way to do
this now is to replace the vtable of the testing allocator with one
that uses Allocator.noResize for the 'resize' function pointer.

An alternative way to support this testing capability is to augment the
FailingAllocator (which is already useful for testing allocation failure
scenarios) to intentionally fail on calls to resize(). To do this, add a
'resize_fail_index' parameter to the FailingAllocator that causes
resize() to fail after the given number of calls.
2023-09-06 19:06:32 +03:00
Ian Johnson f3f554b9b8 std.json: avoid stale pointers when parsing Value (#16864)
Closes #16861

Using `alloc_if_needed` when parsing a `Value` allows receiving a token
which points to the buffer of the underlying `Reader`. This token will
no longer be valid after the `Reader`'s buffer is refilled, which will
happen with large values. Using `alloc_always` avoids this issue by
ensuring the returned tokens always own their data independently of the
underlying buffer.
2023-08-17 07:52:46 -04:00
Ryan Liptak a155e35850 std.json: Fix decoding of UTF-16 surrogate pairs (#16830)
* std.unicode: Add more UTF-16 decoding functions

This mostly makes parts of Utf16LeIterator reusable

* std.json: Fix decoding of UTF-16 surrogate pairs

Before this commit, there were 524,288 codepoints that would get decoded improperly. After this commit, there are 0.

Fixes #16828
2023-08-15 09:11:59 -04:00
Philipp Lühmann d34201c849 std.json: stringify enum literals (#16742) 2023-08-08 23:26:46 +00:00
Jonathan Marler 2046880de8 std.json: josh review fixes
* renamed enum_big_numbers_quoted option to enum_nonportable_numbers_as_strings
* updated stringify doc to mention the option

I also reversed the logic to determine whether an integer is nonportable,
it seemed easier to reason about.

I also took a stab at applying the new option to floats, but, I got stuck
at trying to print large floats, not sure if Zig supports that yet.
2023-08-06 09:25:21 -06:00
Jacob Young 1cce539ddc json.stringify: properly implement RFC8259 recommendation
The previous magic numbers used `1 << 52`, which did not account for the
implicit leading one in the floating point format.  The RFC is correct
when it uses an exponent of 53.  Technically these exclusive endpoints
are also representable, but everyone including the RFC seems to use them
exclusively.

Also, delete special case optimizations related to the type which have
already been implemented in the zig compiler to produce comptime values
for tautological runtime comparisons.
2023-08-06 00:35:10 -04:00
Jonathan Marler 7dacf77745 std.json: fix roundtrip stringify for large integers
std.json follows interoperability recommendations from RFC8259 to limit
JSON number values to those that fit inside an f64.  However, since Zig
supports arbitrarily large JSON numbers, this breaks roundtrip data
congruence.

To appease both use cases, I've added an option `emit_big_numbers_quoted`
to StringifyOptions.  It's disabled by default which preserves roundtrip
but can be enabled to favor interoperability.
2023-08-05 21:56:00 -06:00
Josh Wolfe 8f2af35eaa std.json: WriteStream.print instead of writePreformatted 2023-07-27 10:23:58 -07:00
Josh Wolfe c72a9feabe std.json: support parsing json at comptime using FixedBufferAllocator (#16488) 2023-07-22 18:52:26 -04:00
Josh Wolfe 2ad16248d7 std.json.WriteStream: eliminate dead memory in optimized modes (#16485) 2023-07-22 18:49:59 -04:00
Garrett 04c7b55de4 std.json: fix key allocation in HashMap for streaming json parsing (#16422) 2023-07-22 22:33:50 +00:00
Josh Wolfe 8924f81d8c std.json: Unify stringify and writeStream (#16405) 2023-07-21 19:56:46 -04:00