Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ concurrency:
cancel-in-progress: true

env:
ZIG_VERSION: "0.16.0"
ZIG_VERSION: "0.17.0"

jobs:
changes:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/plugin-loop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:
inputs:
zig_version:
description: "Zig to measure with (a version, or master)"
default: "0.16.0"
default: "0.17.0"
backends:
description: "Comma-separated: default, llvm, self-hosted"
default: "default,llvm,self-hosted"
Expand All @@ -34,7 +34,7 @@ concurrency:
cancel-in-progress: true

env:
ZIG_VERSION: ${{ inputs.zig_version || '0.16.0' }}
ZIG_VERSION: ${{ inputs.zig_version || '0.17.0' }}

jobs:
measure:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ concurrency:
cancel-in-progress: false

env:
ZIG_VERSION: "0.16.0"
ZIG_VERSION: "0.17.0"

jobs:
# Linux + Windows: no fizzy_release environment (no signing secrets needed).
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ on:
default: ""

env:
ZIG_VERSION: "0.16.0"
ZIG_VERSION: "0.17.0"
WEBSITE: fizzyedit/website

jobs:
Expand Down
8 changes: 4 additions & 4 deletions app/App.zig
Original file line number Diff line number Diff line change
Expand Up @@ -820,11 +820,11 @@ pub fn readPluginReservedField(gpa: std.mem.Allocator, settings_data: ?[:0]const
const data = settings_data orelse return null;
const plugins = SettingsPluginsZon.extractField(gpa, data, "plugins") orelse return null;
defer gpa.free(plugins);
const plugins_z = gpa.dupeZ(u8, plugins) catch return null;
const plugins_z = gpa.dupeSentinel(u8, plugins, 0) catch return null;
defer gpa.free(plugins_z);
const id_block = SettingsPluginsZon.extractField(gpa, plugins_z, id) orelse return null;
defer gpa.free(id_block);
const id_z = gpa.dupeZ(u8, id_block) catch return null;
const id_z = gpa.dupeSentinel(u8, id_block, 0) catch return null;
defer gpa.free(id_z);
return SettingsPluginsZon.extractField(gpa, id_z, field);
}
Expand All @@ -834,11 +834,11 @@ pub fn readPluginSettingsText(gpa: std.mem.Allocator, settings_data: ?[:0]const
const data = settings_data orelse return null;
const plugins = SettingsPluginsZon.extractField(gpa, data, "plugins") orelse return null;
defer gpa.free(plugins);
const plugins_z = gpa.dupeZ(u8, plugins) catch return null;
const plugins_z = gpa.dupeSentinel(u8, plugins, 0) catch return null;
defer gpa.free(plugins_z);
const id_block = SettingsPluginsZon.extractField(gpa, plugins_z, id) orelse return null;
defer gpa.free(id_block);
const id_z = gpa.dupeZ(u8, id_block) catch return null;
const id_z = gpa.dupeSentinel(u8, id_block, 0) catch return null;
defer gpa.free(id_z);
return SettingsPluginsZon.extractField(gpa, id_z, "settings");
}
Expand Down
71 changes: 69 additions & 2 deletions app/Recents.zig
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@ pub fn load(allocator: std.mem.Allocator, path: []const u8) !Recents {
if (core.fs.readZ(allocator, dvui.io, path) catch null) |data| {
defer allocator.free(data);

if (std.zon.parse.fromSliceAlloc(Disk, allocator, data, null, .{ .ignore_unknown_fields = true }) catch null) |disk| {
defer std.zon.parse.free(allocator, disk);
if ((zig017_zon: {
var zig017_zd: std.zon.parse.Diagnostics = undefined;
var zig017_arena: std.heap.ArenaAllocator = .init(allocator);
defer zig017_arena.deinit();
const zig017_r = std.zon.parse.fromSlice(Disk, .{ .gpa = allocator, .arena = zig017_arena.allocator(), .source = data, .diagnostics = &zig017_zd, .ignore_unknown_fields = true });
break :zig017_zon if (zig017_r) |zig017_v| zig017ZonDupe(Disk, allocator, zig017_v) else |zig017_e| zig017_e;
}) catch null) |disk| {
defer zig017ZonFree(allocator, disk);

for (disk.folders) |folder| {
// A folder on a mount (`gdrive://…`) is not the disk's to check: it exists
Expand Down Expand Up @@ -166,3 +172,64 @@ pub fn deinit(recents: *Recents, allocator: std.mem.Allocator) void {

recents.commands.deinit(allocator);
}

// ZIG017 stand-in: a deep copy of a zon result out of the parse's arena into the caller's
// allocator, where the code before 0.17 expects to free it. Goes with the zon arena PR.
fn zig017ZonDupe(comptime T: type, gpa: std.mem.Allocator, value: T) error{OutOfMemory}!T {
switch (@typeInfo(T)) {
.pointer => |p| switch (p.size) {
.one => {
const out = try gpa.create(p.child);
out.* = try zig017ZonDupe(p.child, gpa, value.*);
return out;
},
.slice => {
const out = if (comptime p.sentinel()) |s| try gpa.allocSentinel(p.child, value.len, s) else try gpa.alloc(p.child, value.len);
for (out, value) |*o, v| o.* = try zig017ZonDupe(p.child, gpa, v);
return out;
},
else => comptime unreachable,
},
.array => |a| {
var out: T = undefined;
for (&out, value) |*o, v| o.* = try zig017ZonDupe(a.child, gpa, v);
return out;
},
.@"struct" => |s| {
var out: T = value;
inline for (s.field_names, s.field_types, s.field_attrs) |n, FT, attrs| {
if (!attrs.@"comptime") @field(out, n) = try zig017ZonDupe(FT, gpa, @field(value, n));
}
return out;
},
.@"union" => |u| if (u.tag_type == null) return value else switch (value) {
inline else => |payload, tag| return @unionInit(T, @tagName(tag), try zig017ZonDupe(@TypeOf(payload), gpa, payload)),
},
.optional => |o| return if (value) |v| try zig017ZonDupe(o.child, gpa, v) else null,
else => return value,
}
}
// ZIG017 stand-in: 0.16's `std.zon.parse.free`, which 0.17 removed (results now come from an
// arena the caller owns). Goes with the zon arena PR.
fn zig017ZonFree(gpa: std.mem.Allocator, value: anytype) void {
switch (@typeInfo(@TypeOf(value))) {
.pointer => |p| switch (p.size) {
.one => {
zig017ZonFree(gpa, value.*);
gpa.destroy(value);
},
.slice => {
for (value) |item| zig017ZonFree(gpa, item);
gpa.free(value);
},
else => comptime unreachable,
},
.array => for (value) |item| zig017ZonFree(gpa, item),
.@"struct" => |s| inline for (s.field_names) |n| zig017ZonFree(gpa, @field(value, n)),
.@"union" => |u| if (u.tag_type != null) switch (value) {
inline else => |payload| zig017ZonFree(gpa, payload),
},
.optional => if (value) |some| zig017ZonFree(gpa, some),
else => {},
}
}
4 changes: 2 additions & 2 deletions app/Secrets.zig
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn save(self: *Secrets) !void {
const tmp = try std.fmt.allocPrint(self.gpa, "{s}.tmp", .{self.path});
defer self.gpa.free(tmp);
{
var file = try std.Io.Dir.createFileAbsolute(self.io, tmp, .{ .permissions = @enumFromInt(0o600), .truncate = true });
var file = try std.Io.Dir.createFileAbsolute(self.io, tmp, .{ .permissions = @fromBackingInt(@intCast(0o600)), .truncate = true });
defer file.close(self.io);
try file.writeStreamingAll(self.io, out.written());
}
Expand All @@ -162,7 +162,7 @@ test "secrets round-trip through a 0600 file and never through settings" {

// On disk: only the owner can read it, and a fresh instance reads it back.
const st = try tmp.dir.statFile(io, "secrets", .{});
if (builtin.os.tag != .windows) try std.testing.expectEqual(@as(u32, 0o600), @as(u32, @intCast(st.permissions.toMode() & 0o777)));
if (builtin.target.os.tag != .windows) try std.testing.expectEqual(@as(u32, 0o600), @as(u32, @intCast(st.permissions.toMode() & 0o777)));
var again = try Secrets.init(a, io, dir);
defer again.deinit();
try std.testing.expectEqualStrings("1//abc\"quoted\"", again.get("drive.refresh_token").?);
Expand Down
14 changes: 7 additions & 7 deletions app/automation/Service.zig
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn play(ctx: *anyopaque, bytes: []const u8) Api.Play {
else => .{ .invalid = @errorName(err) },
};
if (self.current) |t| self.remember(.{ .ticket = t, .outcome = last });
const ticket: Api.Ticket = @enumFromInt(self.next);
const ticket: Api.Ticket = @fromBackingInt(@intCast(self.next));
self.next += 1;
self.current = ticket;
return .{ .started = ticket };
Expand Down Expand Up @@ -152,22 +152,22 @@ pub fn frameEnded(self: *Service, end_micros: ?u32) bool {
}

fn snapshot(ctx: *anyopaque) Api.SnapshotTicket {
const s = from(ctx).snapshots orelse return @enumFromInt(0);
return @enumFromInt(s.request());
const s = from(ctx).snapshots orelse return @fromBackingInt(@intCast(0));
return @fromBackingInt(@intCast(s.request()));
}

fn snapshotText(ctx: *anyopaque, ticket: Api.SnapshotTicket) ?[]const u8 {
const s = from(ctx).snapshots orelse return null;
return s.get(@intFromEnum(ticket));
return s.get(@backingInt(ticket));
}

fn capture(ctx: *anyopaque, window: []const u8) Api.CaptureTicket {
const c = from(ctx).captures orelse return @enumFromInt(0);
return @enumFromInt(c.request(window));
const c = from(ctx).captures orelse return @fromBackingInt(@intCast(0));
return @fromBackingInt(@intCast(c.request(window)));
}

fn captureImage(ctx: *anyopaque, ticket: Api.CaptureTicket) ?Api.Image {
const c = from(ctx).captures orelse return null;
const image = c.get(@intFromEnum(ticket)) orelse return null;
const image = c.get(@backingInt(ticket)) orelse return null;
return .{ .pixels = image.pixels, .width = image.width, .height = image.height };
}
28 changes: 14 additions & 14 deletions app/automation/overlay.zig
Original file line number Diff line number Diff line change
Expand Up @@ -618,12 +618,12 @@ fn drawTransport(player: *Player, tape: *const Tape, win: dvui.Rect) f32 {

var phys: [5]dvui.Rect.Physical = undefined;
for (pieces, &phys) |r, *out| out.* = wrs.rectToPhysical(r);
tr.prev = phys[@intFromEnum(Piece.prev)];
tr.play = phys[@intFromEnum(Piece.play)];
tr.next = phys[@intFromEnum(Piece.next)];
tr.close = phys[@intFromEnum(Piece.close)];
tr.prev = phys[@backingInt(Piece.prev)];
tr.play = phys[@backingInt(Piece.play)];
tr.next = phys[@backingInt(Piece.next)];
tr.close = phys[@backingInt(Piece.close)];
const hovered: ?Piece = if (tr.pointer) |pt| for (phys, 0..) |r, i| {
if (i != @intFromEnum(Piece.track) and r.contains(pt)) break @enumFromInt(i);
if (i != @backingInt(Piece.track) and r.contains(pt)) break @fromBackingInt(@intCast(i));
} else null else null;

barGlass(fw.data().id, &phys, s, hovered, apart);
Expand All @@ -634,11 +634,11 @@ fn drawTransport(player: *Player, tape: *const Tape, win: dvui.Rect) f32 {
const ink = theme().color(.content, .text);
const playing = player.state == .playing or (player.state == .seeking and player.after_seek == .play);
const play_glyph: Glyph = if (playing) .pause else if (player.state == .ended) .replay else .play;
barIcon(bounds, pieces[@intFromEnum(Piece.prev)], .prev, ink.opacity(0.8));
barIcon(bounds, pieces[@intFromEnum(Piece.play)], play_glyph, ink);
barIcon(bounds, pieces[@intFromEnum(Piece.next)], .next, ink.opacity(0.8));
barIcon(bounds, pieces[@intFromEnum(Piece.close)], .close, ink.opacity(0.65));
tr.track = barTrack(player, tape, bounds, pieces[@intFromEnum(Piece.track)], ink);
barIcon(bounds, pieces[@backingInt(Piece.prev)], .prev, ink.opacity(0.8));
barIcon(bounds, pieces[@backingInt(Piece.play)], play_glyph, ink);
barIcon(bounds, pieces[@backingInt(Piece.next)], .next, ink.opacity(0.8));
barIcon(bounds, pieces[@backingInt(Piece.close)], .close, ink.opacity(0.65));
tr.track = barTrack(player, tape, bounds, pieces[@backingInt(Piece.track)], ink);
return std.math.clamp(p * 1.6, 0, 1);
}

Expand All @@ -655,9 +655,9 @@ fn barGeometry(center: dvui.Point, full_w: f32, p: f32, out: *[5]dvui.Rect) f32
var widths = piece_d;
var round_w: f32 = 0;
for (piece_d, 0..) |d, i| {
if (i != @intFromEnum(Piece.track)) round_w += d;
if (i != @backingInt(Piece.track)) round_w += d;
}
widths[@intFromEnum(Piece.track)] = @max(80, full_w - round_w - 4 * bar_gap);
widths[@backingInt(Piece.track)] = @max(80, full_w - round_w - 4 * bar_gap);
const gap = bar_gap * apart;
var total: f32 = 4 * gap;
for (widths) |w| total += w;
Expand All @@ -678,7 +678,7 @@ fn barGlass(id: dvui.Id, pieces: []const dvui.Rect.Physical, s: f32, hovered: ?P
var bubbles: [5]core.dialogs.Bubble = undefined;
for (pieces, bubbles[0..pieces.len], 0..) |r, *b, i| b.* = .{
.rect = r,
.light = if (hovered != null and @intFromEnum(hovered.?) == i) core.dialogs.bubble_hover else 0,
.light = if (hovered != null and @backingInt(hovered.?) == i) core.dialogs.bubble_hover else 0,
};
core.dialogs.glassBubbles(id, bubbles[0..pieces.len], s, .{ .merge = bar_merge, .shadow = apart });
}
Expand All @@ -699,7 +699,7 @@ fn barIcon(bounds: dvui.Rect, r: dvui.Rect, glyph: Glyph, color: dvui.Color) voi
.stroke_color = .{ .color = color },
.fill_color = .{ .color = color },
}, .{
.id_extra = @intFromEnum(glyph),
.id_extra = @backingInt(glyph),
.rect = .{ .x = r.x + (r.w - d) / 2 - bounds.x, .y = r.y + (r.h - d) / 2 - bounds.y, .w = d, .h = d },
});
}
Expand Down
20 changes: 10 additions & 10 deletions app/crash/crash.zig
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const builtin = @import("builtin");
pub const image = @import("image.zig");

/// Where crash reports can be written: native targets std can catch faults on.
pub const supported = builtin.cpu.arch != .wasm32 and std.debug.have_segfault_handling_support;
pub const supported = builtin.target.cpu.arch != .wasm32 and std.debug.have_segfault_handling_support;

pub const Module = struct {
name_buf: [32]u8 = undefined,
Expand Down Expand Up @@ -90,7 +90,7 @@ pub fn writeReport(
try w.print(": {s}\n", .{s.name}),
}
try w.print("\n{s} {s}, sdk {s}, {t} {t} {t}\n\nmodules:\n", .{
run.app, run.version, run.sdk, builtin.os.tag, builtin.cpu.arch, builtin.mode,
run.app, run.version, run.sdk, builtin.target.os.tag, builtin.target.cpu.arch, builtin.mode,
});
for (modules, 0..) |*m, i| {
try w.print(" {d} {s} {s} 0x{x} 0x{x} ", .{ i, m.name(), m.version(), m.image.base, m.image.end - m.image.base });
Expand Down Expand Up @@ -144,7 +144,7 @@ var run_info: ?Run = null;
/// The report's file, once `writeTo` has named it.
var path_buf: [std.fs.max_path_bytes:0]u8 = undefined;
var path_len: usize = 0;
var path_w: if (builtin.os.tag == .windows) [std.fs.max_path_bytes:0]u16 else void = undefined;
var path_w: if (builtin.target.os.tag == .windows) [std.fs.max_path_bytes:0]u16 else void = undefined;

/// Starts reporting for this run: enters the executable as module 0 and catches aborts and
/// traps. Call once, first thing. std's segfault handler is the root's to switch on
Expand All @@ -154,7 +154,7 @@ pub fn init(run: Run) void {
if (!supported) return;
run_info = run;
addModule(run.app, run.version, @intFromPtr(&init));
if (builtin.os.tag != .windows) {
if (builtin.target.os.tag != .windows) {
const act: std.posix.Sigaction = .{
.handler = .{ .sigaction = onAbortOrTrap },
.mask = std.posix.sigemptyset(),
Expand All @@ -169,16 +169,16 @@ pub fn init(run: Run) void {
/// Nothing is written there unless the run crashes.
pub fn writeTo(io: std.Io, config_folder: []const u8) void {
if (!supported) return;
const pid = if (builtin.os.tag == .windows) win.GetCurrentProcessId() else std.c.getpid();
const pid = if (builtin.target.os.tag == .windows) win.GetCurrentProcessId() else std.c.getpid();
const launched = std.Io.Timestamp.now(io, .real).toMilliseconds();
const sep = std.fs.path.sep;
const path = std.fmt.bufPrintZ(&path_buf, "{s}{c}crashes{c}{d}-{d}.txt", .{ config_folder, sep, sep, launched, pid }) catch return;
const path = std.fmt.bufPrintSentinel(&path_buf, "{s}{c}crashes{c}{d}-{d}.txt", .{ config_folder, sep, sep, launched, pid }, 0) catch return;
const dir = std.fs.path.dirname(path).?;
std.Io.Dir.cwd().createDirPath(io, dir) catch |err| {
std.log.warn("crash reports: can't create {s}: {t}", .{ dir, err });
return;
};
if (builtin.os.tag == .windows) {
if (builtin.target.os.tag == .windows) {
const n = std.unicode.wtf8ToWtf16Le(&path_w, path) catch return;
if (n >= path_w.len) return;
path_w[n] = 0;
Expand Down Expand Up @@ -248,7 +248,7 @@ fn report(what: What, where: Where) void {
}

fn writeFile(text: []const u8) bool {
if (builtin.os.tag == .windows) {
if (builtin.target.os.tag == .windows) {
const h = win.CreateFileW(&path_w, win.GENERIC_WRITE, 0, null, win.CREATE_ALWAYS, win.FILE_ATTRIBUTE_NORMAL, null);
if (h == win.INVALID_HANDLE_VALUE) return false;
defer _ = win.CloseHandle(h);
Expand All @@ -261,7 +261,7 @@ fn writeFile(text: []const u8) bool {
}

fn writeStderr(text: []const u8) void {
if (builtin.os.tag == .windows) {
if (builtin.target.os.tag == .windows) {
_ = win.writeAll(win.GetStdHandle(win.STD_ERROR_HANDLE) orelse return, text);
} else _ = posixWriteAll(2, text);
}
Expand All @@ -278,7 +278,7 @@ fn posixWriteAll(fd: std.c.fd_t, text: []const u8) bool {

/// The file name of the image holding `address`, for a frame in no known module.
fn imageName(address: usize, buf: []u8) ?[]const u8 {
if (builtin.os.tag == .windows) return null;
if (builtin.target.os.tag == .windows) return null;
var info: Dl_info = undefined;
if (dladdr(@ptrFromInt(address), &info) == 0) return null;
const path = std.mem.span(info.dli_fname orelse return null);
Expand Down
Loading
Loading