diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-17 02:38:44 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 12:15:01 -0300 |
| commit | a27c2cb3846a6e2db28250600d762d19c1006eaf (patch) | |
| tree | 01a7989f5e3c6039b471d0fb30d20efc2d8a1dce | |
| parent | 1a14192c65180397d8a2a3df898817768d371a94 (diff) | |
| download | pardes-a27c2cb3846a6e2db28250600d762d19c1006eaf.tar.gz pardes-a27c2cb3846a6e2db28250600d762d19c1006eaf.zip | |
walk: the tape's shape writes its numbers with decimal, not comptimePrint: shapeOf wrote each integer's and float's width, each enum value and each array's length with std.fmt.comptimePrint, an inline function and so never memoized, about 5e6 of the compiler's instructions a call and some 600 calls (354 integers, 220 enum values) in every compile of the core; decimal writes `n` as {d} does, memoized, in five lines; the shape is the same 10,960 bytes and wire.semantics the same 05b2cba8834b1d7c; core-test's forced full recompile (Debug, one filter) 104.95e9 to 103.41e9 instructions (-1.3 % of the base's 120.12e9), the Debug test's text unchanged; a session's byte dump, its image and a closed pane's save the same bytes (but the clock's) and each build loads the other's; test: decimal against {d} for 0 to maxInt(u128) and minInt(i128); core-test 985 of 985; the changelog says so
| -rw-r--r-- | src/CHANGELOG.md | 5 | ||||
| -rw-r--r-- | src/walk.zig | 22 |
2 files changed, 21 insertions, 6 deletions
diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index 1bece4b2..ce98a862 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -42,13 +42,14 @@ or in a window by the rule above it. - An edit to the core recompiles it about 1.5 s sooner again (`core-test`, - 13 % fewer of the compiler's instructions, 4.4 MB less code in a Debug + 14 % fewer of the compiler's instructions, 4.4 MB less code in a Debug test): a load's note on a field (another build's dump) is written from the type's and the field's names at run time, where every type and field had its own copy of the code that writes one; one byte dump's reader serves a session, a pane and the rest, where each had its own; and what tells a replica's build from another's (`wire.semantics`) - joins its two long parts on, where it formatted them, at every compile. + joins its two long parts on, and writes the tape's numbers itself, + where it formatted them, at every compile. - An edit to the core recompiles it about 3 s sooner (`core-test`, 13 s to 10 s): the build keeps each grammar's highlight patterns that pardes diff --git a/src/walk.zig b/src/walk.zig index e3738bde..8747937d 100644 --- a/src/walk.zig +++ b/src/walk.zig @@ -378,15 +378,15 @@ fn shapeOf(comptime T: type, comptime depth: u8) []const u8 { return switch (@typeInfo(T)) { .void, .null, .undefined => "v", .bool => "b", - .int => |i| std.fmt.comptimePrint("{t}{d}", .{ i.signedness, i.bits }), - .float => |f| std.fmt.comptimePrint("f{d}", .{f.bits}), + .int => |i| @tagName(i.signedness) ++ decimal(i.bits), + .float => |f| "f" ++ decimal(f.bits), .@"enum" => |e| blk: { var out: []const u8 = shapeOf(e.tag_type, depth + 1) ++ "{"; - for (e.field_names, e.field_values) |n, v| out = out ++ std.fmt.comptimePrint("{s}={d},", .{ n, v }); + for (e.field_names, e.field_values) |n, v| out = out ++ n ++ "=" ++ decimal(v) ++ ","; break :blk out ++ "}"; }, .optional => |o| if (machinery(o.child)) "0" else "?" ++ shapeOf(o.child, depth + 1), - .array => |a| std.fmt.comptimePrint("[{d}]", .{a.len}) ++ shapeOf(a.child, depth + 1), + .array => |a| "[" ++ decimal(a.len) ++ "]" ++ shapeOf(a.child, depth + 1), .pointer => |p| switch (p.size) { .one => shapeOf(p.child, depth + 1), .slice => "[]" ++ shapeOf(p.child, depth + 1), @@ -413,6 +413,15 @@ fn shapeOf(comptime T: type, comptime depth: u8) []const u8 { } } +/// `n` in decimal, as `{d}` writes it: memoized, where comptimePrint (an +/// inline function) formats again at every call, 5e6 of the compiler's +/// instructions each. +fn decimal(comptime n: comptime_int) []const u8 { + if (n < 0) return "-" ++ decimal(-n); + if (n < 10) return &.{'0' + n}; + return decimal(n / 10) ++ &[_]u8{'0' + n % 10}; +} + /// An error by its name. An `anyerror` must be one `decode` can read back /// (`errorNamed`): a Debug build stops at one that is not, as it is taped. fn encodeError(comptime E: type, err: E, w: *std.Io.Writer) std.Io.Writer.Error!void { @@ -2584,3 +2593,8 @@ test "a blob of 4 KiB and up is digested by its length, what it holds told by it small[1] = 'x'; try std.testing.expect(digest(File, &f) != was); } + +test "a shape's numbers are written as {d} writes them" { + inline for (.{ 0, 7, 10, 65535, -1, -300, std.math.minInt(i128), std.math.maxInt(u128) }) |n| + try std.testing.expectEqualStrings(std.fmt.comptimePrint("{d}", .{n}), comptime decimal(n)); +} |
