Commit graph

331 commits

Author SHA1 Message Date
Luna Schwalbe
63ab0c0302
Reenable vector tests for armeb/thumbeb
https://github.com/ziglang/zig/issues/22060 has been fixed by upstream.
2025-09-04 16:23:18 +02:00
Luna Schwalbe
a9f06d16fd
Reenable std.fmt.test.vector for riscv64
The vector codegen issue as described in
https://github.com/ziglang/zig/issues/4486 has been fixed upstream.
2025-09-04 16:15:00 +02:00
Andrew Kelley
150169f1e0 std.fmt: delete deprecated APIs
std.fmt.Formatter -> std.fmt.Alt
std.fmt.format -> std.Io.Writer.print
2025-08-31 12:49:18 -07:00
Andrew Kelley
79f267f6b9 std.Io: delete GenericReader
and delete deprecated alias std.io
2025-08-29 17:14:26 -07:00
Andrew Kelley
045bb14897 zig std: fix build failures 2025-08-08 17:17:53 -07:00
mlugg
08f1d63be1
disable more failing tests
Wow, *lots* of backends were reliant on Sema doing the heavy lifting for
them. CBE, Wasm, and SPIR-V have all regressed in places now that they
actually need to, like, initialize unions and such.
2025-07-29 22:44:01 +01:00
Andrew Kelley
93ac76594a std: fmt.format to io.Writer.print
allows reverting format -> deprecatedFormat, plus I think this is a
nicer place for the function.
2025-07-09 15:31:02 -07:00
Andrew Kelley
4d93545ded chicken out and allow ascii string alignment 2025-07-09 15:17:07 -07:00
Andrew Kelley
51a9a6aab6 std: replace formatInteger with formatNumber 2025-07-09 14:54:54 -07:00
Andrew Kelley
bc2cf0c173 eliminate all uses of std.io.Writer.count except for CBE 2025-07-09 09:32:07 -07:00
Andrew Kelley
1dcb20d27e std.fmt: refactor to remove cacheString
when this kind of trick is needed, do it inline
2025-07-08 11:07:23 -07:00
Andrew Kelley
7e2a26c0c4 std.io.Writer.printValue: rework logic
Alignment and fill options only apply to numbers.

Rework the implementation to mainly branch on the format string rather
than the type information. This is more straightforward to maintain and
more straightforward for comptime evaluation.

Enums support being printed as decimal, hexadecimal, octal, and binary.

`formatInteger` is another possible format method that is
unconditionally called when the value type is struct and one of the
integer-printing format specifiers are used.
2025-07-07 22:43:53 -07:00
Andrew Kelley
5378fdb153 std.fmt: fully remove format string from format methods
Introduces `std.fmt.alt` which is a helper for calling alternate format
methods besides one named "format".
2025-07-07 22:43:53 -07:00
Andrew Kelley
9c8aef55b4 std.fmt.format: use {t} for tag name rather than {s}
prevents footgun when formatted type changes from string to enum
2025-07-07 22:43:52 -07:00
Andrew Kelley
fac5fe57be std.io.Writer.Allocating: rename interface to writer 2025-07-07 22:43:52 -07:00
Andrew Kelley
1d763c8b29 std: formatted printing no longer prints type names
for structs, enums, and unions.

auto untagged unions are no longer printed as pointers; instead they are
printed as "{ ... }".

extern and packed untagged unions have each field printed, similar to
what gdb does.

also fix bugs in delimiter based reading
2025-07-07 22:43:51 -07:00
Andrew Kelley
0e37ff0d59 std.fmt: breaking API changes
added adapter to AnyWriter and GenericWriter to help bridge the gap
between old and new API

make std.testing.expectFmt work at compile-time

std.fmt no longer has a dependency on std.unicode. Formatted printing
was never properly unicode-aware. Now it no longer pretends to be.

Breakage/deprecations:
* std.fs.File.reader -> std.fs.File.deprecatedReader
* std.fs.File.writer -> std.fs.File.deprecatedWriter
* std.io.GenericReader -> std.io.Reader
* std.io.GenericWriter -> std.io.Writer
* std.io.AnyReader -> std.io.Reader
* std.io.AnyWriter -> std.io.Writer
* std.fmt.format -> std.fmt.deprecatedFormat
* std.fmt.fmtSliceEscapeLower -> std.ascii.hexEscape
* std.fmt.fmtSliceEscapeUpper -> std.ascii.hexEscape
* std.fmt.fmtSliceHexLower -> {x}
* std.fmt.fmtSliceHexUpper -> {X}
* std.fmt.fmtIntSizeDec -> {B}
* std.fmt.fmtIntSizeBin -> {Bi}
* std.fmt.fmtDuration -> {D}
* std.fmt.fmtDurationSigned -> {D}
* {} -> {f} when there is a format method
* format method signature
  - anytype -> *std.io.Writer
  - inferred error set -> error{WriteFailed}
  - options -> (deleted)
* std.fmt.Formatted
  - now takes context type explicitly
  - no fmt string
2025-07-07 22:43:51 -07:00
Shun Sakai
5fc4448e45 chore(std.mem): Rename trimLeft and trimRight
Rename `trimLeft` to `trimStart`, and `trimRight` to `trimEnd`.
`trimLeft` and `trimRight` functions remain as deprecated aliases for
these new names.
2025-04-27 18:03:59 +09:00
GasInfinity
dfe0fb675d fix(std/fmt.zig): fix overflow in fmtDurationSigned
fixes #23315
2025-03-24 11:40:19 +00:00
wooster0
5b9b5e45cb std.fmt.digits2: optimize for ReleaseSmall
Difference:
```
$ cat x.zig
const std = @import("std");

pub const std_options = std.Options{ .keep_sigpipe = true };

pub fn main() void {
    std.io.getStdOut().writer().print("{d}\n", .{@intFromPtr(std.os.argv.ptr)}) catch {};
}
$ zig build-exe x.zig -OReleaseSmall -fsingle-threaded -fno-unwind-tables && wc -c x
2576 x
$ zig build-exe x.zig -OReleaseSmall -fsingle-threaded -fno-unwind-tables --zig-lib-dir ../zig/lib && wc -c x
2424 x
```
2025-02-12 14:45:38 -08:00
saurabh
4162f401cb
std.fmt: Add unit tests for all methods in the Parser struct 2025-02-11 13:34:56 +02:00
rpkak
34644511bb std.fmt: remove placeholders from binary 2025-02-10 22:52:17 +01:00
thejohnny5
5b3eaff80d std: check max depth for vector type in formatType 2025-01-26 18:53:11 +01: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
Alex Rønne Petersen
03ac40d570
std: Disable some tests affected by #22060 for thumbeb too. 2025-01-06 16:47:40 +01:00
Alex Rønne Petersen
499ad89b41
std: Disable some vector-related tests on armeb.
https://github.com/ziglang/zig/issues/22060
2024-12-13 03:13:14 +01:00
Andrew Barchuk
1f37b70344
Remove unused buf field from std.fmt.Parser (#21994)
And make the initialization less error prone by removing a default for
iter, which is required for a functional parser

std: Add a brief doc comment for `std.fmt.Parser`
2024-11-24 15:09:36 -08:00
gooncreeper
73f2671c7b
std.format: properly handle vectors of pointers 2024-11-18 13:48:54 +02:00
Simon Ekström
17a87d7341
std.fmt: Fix compile error in Parser.peek() (#20532) 2024-10-30 07:45:23 +00:00
Andrew Kelley
4f8d244e7e remove formatted panics
implements #17969
2024-09-26 12:35:14 -07:00
Linus Groh
54b668f8a3 std.fmt: Update casing of a few functions to match naming style guide 2024-09-08 11:30:20 -07:00
fdfdjfk3
a670f55195
std.fmt.fmtIntSize*: document when precision is ignored 2024-09-02 14:21:59 +03: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
Andrew Kelley
397c9174cb fix std.fmt.hex 2024-07-20 01:06:29 -07:00
Andrew Kelley
eb4028bf30 add std.fmt.hex
converts an unsigned integer into an array
2024-07-20 01:06:29 -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
Jacob Young
d77f5e7aaa Progress: fix compile errors on windows
Works for `zig build-exe`, IPC still not implemented yet.
2024-05-27 20:56:48 -07:00
orvit
ae44e199a8
use constant in formatType 2024-05-21 14:41:49 +00:00
Sean
f6f7a47aad Update fmt.zig tests
Changed uses of `std.testing.expect` to `std.testing.expectEqual`, `std.testing.expectError`, and `std.testing.expectEqualStrings` where appropriate
2024-04-23 17:57:56 -07:00
mlugg
9c3670fc93
compiler: implement analysis-local comptime-mutable memory
This commit changes how we represent comptime-mutable memory
(`comptime var`) in the compiler in order to implement the intended
behavior that references to such memory can only exist at comptime.

It does *not* clean up the representation of mutable values, improve the
representation of comptime-known pointers, or fix the many bugs in the
comptime pointer access code. These will be future enhancements.

Comptime memory lives for the duration of a single Sema, and is not
permitted to escape that one analysis, either by becoming runtime-known
or by becoming comptime-known to other analyses. These restrictions mean
that we can represent comptime allocations not via Decl, but with state
local to Sema - specifically, the new `Sema.comptime_allocs` field. All
comptime-mutable allocations, as well as any comptime-known const allocs
containing references to such memory, live in here. This allows for
relatively fast checking of whether a value references any
comptime-mtuable memory, since we need only traverse values up to
pointers: pointers to Decls can never reference comptime-mutable memory,
and pointers into `Sema.comptime_allocs` always do.

This change exposed some faulty pointer access logic in `Value.zig`.
I've fixed the important cases, but there are some TODOs I've put in
which are definitely possible to hit with sufficiently esoteric code. I
plan to resolve these by auditing all direct accesses to pointers (most
of them ought to use Sema to perform the pointer access!), but for now
this is sufficient for all realistic code and to get tests passing.

This change eliminates `Zcu.tmp_hack_arena`, instead using the Sema
arena for comptime memory mutations, which is possible since comptime
memory is now local to the current Sema.

This change should allow `Decl` to store only an `InternPool.Index`
rather than a full-blown `ty: Type, val: Value`. This commit does not
perform this refactor.
2024-03-25 14:49:41 +00:00
Marc Tiehuis
091aa54a3e fix comptime float formatting
Closes #19379
Closes #18046
2024-03-24 10:23:48 +02:00
Ben Sinclair
e90583f5d1 std.fmt.fmtIntSize{Bin,Dec}: Don't add .0... to bytes
These are the fundamental units so they can't have decimal places.
2024-03-24 01:15:22 +02:00
Andrew Kelley
12191c8a22 std: promote tests to doctests
Now these show up as "example usage" in generated documentation.
2024-03-21 14:11:46 -07:00
Marc Tiehuis
31791ae15b rename ryu128 -> format_float
Symmetry with parse_float and to hide the implementation from the user.
Additionally, we expose the entire namespace and provide some aliases so
everything is available to a user.

Closes #19366
2024-03-21 17:10:41 +02:00
Andrew Kelley
bd24e66379
Merge pull request #19229 from tiehuis/ryu-128
std.fmt: add ryu floating-point formatting implementation
2024-03-11 18:46:26 -07:00
Andrew Kelley
aa852f737b improve documentation in std
A lot of these "shorthand" doc comments were redundant, low quality
filler content. Better to let the actual modules speak for themselves
with top level doc comments rather than trying to document their
aliases.
2024-03-10 18:13:30 -07:00
Marc Tiehuis
da4acf9a48 std.fmt: fix std-cases and perform round-trip check in ryu unit tests 2024-03-09 22:23:14 +13:00
Marc Tiehuis
c6ad551cd2 std.fmt: add ryu floating-point formatting
This replaces the errol backend with one based on ryu. The 128-bit
backend only is implemented. This supports all floating-point types and
does not use fp logic to print.

Closes #1181.
Closes #1299.
Closes #3612.
2024-03-09 15:57:25 +13:00
Jacob Young
7c9a96111c x86_64: fix assert location 2024-02-12 05:25:07 +01:00