Skip to content

Commit

Permalink
zig: else branch is implicitly void (#16406)
Browse files Browse the repository at this point in the history
  • Loading branch information
nektro authored Jan 15, 2025
1 parent 80e9bbc commit 68089a0
Show file tree
Hide file tree
Showing 30 changed files with 61 additions and 79 deletions.
3 changes: 1 addition & 2 deletions src/bun.js/api/Timer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ pub const All = struct {
.context = {},
},
active_timer_count: i32 = 0,
uv_timer: if (Environment.isWindows) uv.Timer else void =
if (Environment.isWindows) std.mem.zeroes(uv.Timer) else {},
uv_timer: if (Environment.isWindows) uv.Timer else void = if (Environment.isWindows) std.mem.zeroes(uv.Timer),

// We split up the map here to avoid storing an extra "repeat" boolean
maps: struct {
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/api/bun/dns_resolver.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ pub const InternalDNS = struct {

valid: bool = true,

libinfo: if (Environment.isMac) MacAsyncDNS else void = if (Environment.isMac) .{} else {},
libinfo: if (Environment.isMac) MacAsyncDNS else void = if (Environment.isMac) .{},

pub fn isExpired(this: *Request, timestamp_to_store: *u32) bool {
if (this.refcount > 0 or this.result == null) {
Expand Down
4 changes: 1 addition & 3 deletions src/bun.js/api/bun/process.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1799,9 +1799,7 @@ pub const sync = struct {
.use_execve_on_macos = this.use_execve_on_macos,
.stream = false,
.argv0 = this.argv0,
.windows = if (Environment.isWindows)
this.windows
else {},
.windows = if (Environment.isWindows) this.windows,
};
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/api/bun/subprocess.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2137,7 +2137,7 @@ pub const Subprocess = struct {
.hide_window = windows_hide,
.verbatim_arguments = windows_verbatim_arguments,
.loop = JSC.EventLoopHandle.init(jsc_vm),
} else {},
},
};

var spawned = switch (bun.spawn.spawnProcess(
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/api/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1565,7 +1565,7 @@ fn NewFlags(comptime debug_mode: bool) type {
is_waiting_for_request_body: bool = false,
/// Used in renderMissing in debug mode to show the user an HTML page
/// Used to avoid looking at the uws.Request struct after it's been freed
is_web_browser_navigation: if (debug_mode) bool else void = if (debug_mode) false else {},
is_web_browser_navigation: if (debug_mode) bool else void = if (debug_mode) false,
has_written_status: bool = false,
response_protected: bool = false,
aborted: bool = false,
Expand Down
6 changes: 3 additions & 3 deletions src/bun.js/event_loop.zig
Original file line number Diff line number Diff line change
Expand Up @@ -785,13 +785,13 @@ pub const EventLoop = struct {
waker: ?Waker = null,
forever_timer: ?*uws.Timer = null,
deferred_tasks: DeferredTaskQueue = .{},
uws_loop: if (Environment.isWindows) ?*uws.Loop else void = if (Environment.isWindows) null else {},
uws_loop: if (Environment.isWindows) ?*uws.Loop else void = if (Environment.isWindows) null,

debug: Debug = .{},
entered_event_loop_count: isize = 0,
concurrent_ref: std.atomic.Value(i32) = std.atomic.Value(i32).init(0),

signal_handler: if (Environment.isPosix) ?*PosixSignalHandle else void = if (Environment.isPosix) null else {},
signal_handler: if (Environment.isPosix) ?*PosixSignalHandle else void = if (Environment.isPosix) null,

pub export fn Bun__ensureSignalHandler() void {
if (Environment.isPosix) {
Expand Down Expand Up @@ -1426,7 +1426,7 @@ pub const EventLoop = struct {

if (loop.isActive()) {
this.processGCTimer();
var event_loop_sleep_timer = if (comptime Environment.isDebug) std.time.Timer.start() catch unreachable else {};
var event_loop_sleep_timer = if (comptime Environment.isDebug) std.time.Timer.start() catch unreachable;
// for the printer, this is defined:
var timespec: bun.timespec = if (Environment.isDebug) .{ .sec = 0, .nsec = 0 } else undefined;
loop.tickWithTimeout(if (ctx.timer.getTimeout(&timespec)) &timespec else null);
Expand Down
8 changes: 4 additions & 4 deletions src/bun.js/javascript.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1916,7 +1916,7 @@ pub const VirtualMachine = struct {
.ref_strings = JSC.RefString.Map.init(allocator),
.ref_strings_mutex = .{},
.standalone_module_graph = opts.graph.?,
.debug_thread_id = if (Environment.allow_assert) std.Thread.getCurrentId() else {},
.debug_thread_id = if (Environment.allow_assert) std.Thread.getCurrentId(),
};
vm.source_mappings.init(&vm.saved_source_map_table);
vm.regular_event_loop.tasks = EventLoop.Queue.init(
Expand Down Expand Up @@ -2032,7 +2032,7 @@ pub const VirtualMachine = struct {
.origin_timestamp = getOriginTimestamp(),
.ref_strings = JSC.RefString.Map.init(allocator),
.ref_strings_mutex = .{},
.debug_thread_id = if (Environment.allow_assert) std.Thread.getCurrentId() else {},
.debug_thread_id = if (Environment.allow_assert) std.Thread.getCurrentId(),
};
vm.source_mappings.init(&vm.saved_source_map_table);
vm.regular_event_loop.tasks = EventLoop.Queue.init(
Expand Down Expand Up @@ -2188,7 +2188,7 @@ pub const VirtualMachine = struct {
.ref_strings_mutex = .{},
.standalone_module_graph = worker.parent.standalone_module_graph,
.worker = worker,
.debug_thread_id = if (Environment.allow_assert) std.Thread.getCurrentId() else {},
.debug_thread_id = if (Environment.allow_assert) std.Thread.getCurrentId(),
};
vm.source_mappings.init(&vm.saved_source_map_table);
vm.regular_event_loop.tasks = EventLoop.Queue.init(
Expand Down Expand Up @@ -2278,7 +2278,7 @@ pub const VirtualMachine = struct {
.origin_timestamp = getOriginTimestamp(),
.ref_strings = JSC.RefString.Map.init(allocator),
.ref_strings_mutex = .{},
.debug_thread_id = if (Environment.allow_assert) std.Thread.getCurrentId() else {},
.debug_thread_id = if (Environment.allow_assert) std.Thread.getCurrentId(),
};
vm.source_mappings.init(&vm.saved_source_map_table);
vm.regular_event_loop.tasks = EventLoop.Queue.init(
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/node/node_fs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5697,7 +5697,7 @@ pub const NodeFS = struct {
defer bun.OSPathBufferPool.put(tmp);
@memcpy(tmp[0..slice.len], slice);
return bun.strings.fromWPath(&this.sync_error_buf, tmp[0..slice.len]);
} else {}
}
}

fn cpSyncInner(
Expand Down
3 changes: 1 addition & 2 deletions src/bun.js/webcore.zig
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ pub const Prompt = struct {
// unset `ENABLE_VIRTUAL_TERMINAL_INPUT` on windows. This prevents backspace from
// deleting the entire line
const original_mode: if (Environment.isWindows) ?bun.windows.DWORD else void = if (comptime Environment.isWindows)
bun.win32.unsetStdioModeFlags(0, bun.windows.ENABLE_VIRTUAL_TERMINAL_INPUT) catch null
else {};
bun.win32.unsetStdioModeFlags(0, bun.windows.ENABLE_VIRTUAL_TERMINAL_INPUT) catch null;

defer if (comptime Environment.isWindows) {
if (original_mode) |mode| {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/bunx_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ pub const BunxCommand = struct {

.windows = if (Environment.isWindows) .{
.loop = bun.JSC.EventLoopHandle.init(bun.JSC.MiniEventLoop.initGlobal(this_transpiler.env)),
} else {},
},
}) catch |err| {
Output.prettyErrorln("<r><red>error<r>: bunx failed to install <b>{s}<r> due to error <b>{s}<r>", .{ install_param, @errorName(err) });
Global.exit(1);
Expand Down
20 changes: 8 additions & 12 deletions src/cli/create_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ fn execTask(allocator: std.mem.Allocator, task_: string, cwd: string, _: string,

.windows = if (Environment.isWindows) .{
.loop = bun.JSC.EventLoopHandle.init(bun.JSC.MiniEventLoop.initGlobal(null)),
} else {},
},
}) catch return;
}

Expand Down Expand Up @@ -475,18 +475,14 @@ pub const CreateCommand = struct {
};

var destination_buf: if (Environment.isWindows) bun.WPathBuffer else void = undefined;
const dst_without_trailing_slash: if (Environment.isWindows) string else void = if (comptime Environment.isWindows)
strings.withoutTrailingSlash(destination)
else {};
const dst_without_trailing_slash: if (Environment.isWindows) string else void = if (comptime Environment.isWindows) strings.withoutTrailingSlash(destination);
if (comptime Environment.isWindows) {
strings.copyU8IntoU16(&destination_buf, dst_without_trailing_slash);
destination_buf[dst_without_trailing_slash.len] = std.fs.path.sep;
}

var template_path_buf: if (Environment.isWindows) bun.WPathBuffer else void = undefined;
const src_without_trailing_slash: if (Environment.isWindows) string else void = if (comptime Environment.isWindows)
strings.withoutTrailingSlash(abs_template_path)
else {};
const src_without_trailing_slash: if (Environment.isWindows) string else void = if (comptime Environment.isWindows) strings.withoutTrailingSlash(abs_template_path);
if (comptime Environment.isWindows) {
strings.copyU8IntoU16(&template_path_buf, src_without_trailing_slash);
template_path_buf[src_without_trailing_slash.len] = std.fs.path.sep;
Expand Down Expand Up @@ -597,10 +593,10 @@ pub const CreateCommand = struct {
&walker_,
node,
&progress,
if (comptime Environment.isWindows) dst_without_trailing_slash.len + 1 else {},
if (comptime Environment.isWindows) &destination_buf else {},
if (comptime Environment.isWindows) src_without_trailing_slash.len + 1 else {},
if (comptime Environment.isWindows) &template_path_buf else {},
if (comptime Environment.isWindows) dst_without_trailing_slash.len + 1,
if (comptime Environment.isWindows) &destination_buf,
if (comptime Environment.isWindows) src_without_trailing_slash.len + 1,
if (comptime Environment.isWindows) &template_path_buf,
);

package_json_file = destination_dir.openFile("package.json", .{ .mode = .read_write }) catch null;
Expand Down Expand Up @@ -1517,7 +1513,7 @@ pub const CreateCommand = struct {

.windows = if (Environment.isWindows) .{
.loop = bun.JSC.EventLoopHandle.init(bun.JSC.MiniEventLoop.initGlobal(null)),
} else {},
},
});
_ = try process.unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/filter_run.zig
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ pub fn runScriptsWithFilter(ctx: Command.Context) !noreturn {
.stdout = if (Environment.isPosix) .buffer else .{ .buffer = try bun.default_allocator.create(bun.windows.libuv.Pipe) },
.stderr = if (Environment.isPosix) .buffer else .{ .buffer = try bun.default_allocator.create(bun.windows.libuv.Pipe) },
.cwd = std.fs.path.dirname(script.package_json_path) orelse "",
.windows = if (Environment.isWindows) .{ .loop = bun.JSC.EventLoopHandle.init(event_loop) } else {},
.windows = if (Environment.isWindows) .{ .loop = bun.JSC.EventLoopHandle.init(event_loop) },
.stream = true,
},
};
Expand Down
3 changes: 1 addition & 2 deletions src/cli/init_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ pub const InitCommand = struct {
// unset `ENABLE_VIRTUAL_TERMINAL_INPUT` on windows. This prevents backspace from
// deleting the entire line
const original_mode: if (Environment.isWindows) ?bun.windows.DWORD else void = if (comptime Environment.isWindows)
bun.win32.unsetStdioModeFlags(0, bun.windows.ENABLE_VIRTUAL_TERMINAL_INPUT) catch null
else {};
bun.win32.unsetStdioModeFlags(0, bun.windows.ENABLE_VIRTUAL_TERMINAL_INPUT) catch null;

defer if (comptime Environment.isWindows) {
if (original_mode) |mode| {
Expand Down
7 changes: 3 additions & 4 deletions src/cli/publish_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ pub const PublishCommand = struct {

normalized_pkg_info: string,

publish_script: if (directory_publish) ?[]const u8 else void = if (directory_publish) null else {},
postpublish_script: if (directory_publish) ?[]const u8 else void = if (directory_publish) null else {},
publish_script: if (directory_publish) ?[]const u8 else void = if (directory_publish) null,
postpublish_script: if (directory_publish) ?[]const u8 else void = if (directory_publish) null,
script_env: if (directory_publish) *DotEnv.Loader else void,

const FromTarballError = OOM || error{
Expand Down Expand Up @@ -683,8 +683,7 @@ pub const PublishCommand = struct {
// unset `ENABLE_VIRTUAL_TERMINAL_INPUT` on windows. This prevents backspace from
// deleting the entire line
const original_mode: if (Environment.isWindows) ?bun.windows.DWORD else void = if (comptime Environment.isWindows)
bun.win32.unsetStdioModeFlags(0, bun.windows.ENABLE_VIRTUAL_TERMINAL_INPUT) catch null
else {};
bun.win32.unsetStdioModeFlags(0, bun.windows.ENABLE_VIRTUAL_TERMINAL_INPUT) catch null;

defer if (comptime Environment.isWindows) {
if (original_mode) |mode| {
Expand Down
4 changes: 2 additions & 2 deletions src/cli/run_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ pub const RunCommand = struct {

.windows = if (Environment.isWindows) .{
.loop = JSC.EventLoopHandle.init(JSC.MiniEventLoop.initGlobal(env)),
} else {},
},
}) catch |err| {
if (!silent) {
Output.prettyErrorln("<r><red>error<r>: Failed to run script <b>{s}<r> due to error <b>{s}<r>", .{ name, @errorName(err) });
Expand Down Expand Up @@ -513,7 +513,7 @@ pub const RunCommand = struct {

.windows = if (Environment.isWindows) .{
.loop = JSC.EventLoopHandle.init(JSC.MiniEventLoop.initGlobal(env)),
} else {},
},
}) catch |err| {
bun.handleErrorReturnTrace(err, @errorReturnTrace());

Expand Down
2 changes: 1 addition & 1 deletion src/cli/upgrade_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ pub const UpgradeCommand = struct {

.windows = if (Environment.isWindows) .{
.loop = bun.JSC.EventLoopHandle.init(bun.JSC.MiniEventLoop.initGlobal(null)),
} else {},
},
}) catch |err| {
Output.prettyErrorln("<r><red>error:<r> Failed to spawn Expand-Archive on {s} due to error {s}", .{ tmpname, @errorName(err) });
Global.exit(1);
Expand Down
4 changes: 2 additions & 2 deletions src/css/css_parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ pub fn DefineShorthand(comptime T: type, comptime property_name: PropertyIdTag)
// const property_id = @unionInit(
// PropertyId,
// field.name,
// if (@hasDecl(T.VendorPrefixMap, field.name)) vendor_prefix else {},
// if (@hasDecl(T.VendorPrefixMap, field.name)) vendor_prefix,
// );
// const value = property.longhand(&property_id);
// if (@as(PropertyIdTag, value) == @as(PropertyIdTag, property_id)) {
Expand Down Expand Up @@ -403,7 +403,7 @@ pub fn DefineShorthand(comptime T: type, comptime property_name: PropertyIdTag)
// out[i] = @unionInit(
// PropertyId,
// field.name,
// if (@hasField(T.VendorPrefixMap, field.name)) vendor_prefix else {},
// if (@hasField(T.VendorPrefixMap, field.name)) vendor_prefix,
// );
// }

Expand Down
2 changes: 1 addition & 1 deletion src/hive_array.zig
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn HiveArray(comptime T: type, comptime capacity: u16) type {
pub fn init(allocator: std.mem.Allocator) This {
return .{
.allocator = allocator,
.hive = if (capacity > 0) HiveArray(T, capacity).init() else {},
.hive = if (capacity > 0) HiveArray(T, capacity).init(),
};
}

Expand Down
12 changes: 6 additions & 6 deletions src/install/install.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1494,10 +1494,10 @@ pub fn NewPackageInstall(comptime kind: PkgInstallKind) type {
cached_package_dir: std.fs.Dir = undefined,
walker: Walker = undefined,
subdir: std.fs.Dir = if (Environment.isWindows) std.fs.Dir{ .fd = std.os.windows.INVALID_HANDLE_VALUE } else undefined,
buf: bun.windows.WPathBuffer = if (Environment.isWindows) undefined else {},
buf2: bun.windows.WPathBuffer = if (Environment.isWindows) undefined else {},
to_copy_buf: if (Environment.isWindows) []u16 else void = if (Environment.isWindows) undefined else {},
to_copy_buf2: if (Environment.isWindows) []u16 else void = if (Environment.isWindows) undefined else {},
buf: bun.windows.WPathBuffer = if (Environment.isWindows) undefined,
buf2: bun.windows.WPathBuffer = if (Environment.isWindows) undefined,
to_copy_buf: if (Environment.isWindows) []u16 else void = if (Environment.isWindows) undefined,
to_copy_buf2: if (Environment.isWindows) []u16 else void = if (Environment.isWindows) undefined,

pub fn deinit(this: *@This()) void {
if (!Environment.isWindows) {
Expand Down Expand Up @@ -1888,7 +1888,7 @@ pub fn NewPackageInstall(comptime kind: PkgInstallKind) type {
head2: if (Environment.isWindows) []u16 else void,
) !u32 {
var real_file_count: u32 = 0;
var queue = if (Environment.isWindows) HardLinkWindowsInstallTask.getQueue() else {};
var queue = if (Environment.isWindows) HardLinkWindowsInstallTask.getQueue();

while (try walker.next()) |entry| {
if (comptime Environment.isPosix) {
Expand Down Expand Up @@ -14998,7 +14998,7 @@ pub const PackageManager = struct {
// added/removed/updated direct dependencies.
Output.pretty(
\\
\\Saved <green>{s}<r> ({d} package{s})
\\Saved <green>{s}<r> ({d} package{s})
, .{
switch (save_format) {
.text => "bun.lock",
Expand Down
8 changes: 3 additions & 5 deletions src/install/lifecycle_script_runner.zig
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,9 @@ pub const LifecycleScriptSubprocess = struct {
},
.cwd = cwd,

.windows = if (Environment.isWindows)
.{
.loop = JSC.EventLoopHandle.init(&manager.event_loop),
}
else {},
.windows = if (Environment.isWindows) .{
.loop = JSC.EventLoopHandle.init(&manager.event_loop),
},

.stream = false,
};
Expand Down
8 changes: 4 additions & 4 deletions src/install/lockfile.zig
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ pub const Tree = struct {
lockfile: *const Lockfile,
manager: if (method == .filter) *const PackageManager else void,
sort_buf: std.ArrayListUnmanaged(DependencyID) = .{},
workspace_filters: if (method == .filter) []const WorkspaceFilter else void = if (method == .filter) &.{} else {},
workspace_filters: if (method == .filter) []const WorkspaceFilter else void = if (method == .filter) &.{},
install_root_dependencies: if (method == .filter) bool else void,
path_buf: []u8,

Expand Down Expand Up @@ -1300,7 +1300,7 @@ pub fn cleanWithLogger(
exact_versions: bool,
comptime log_level: PackageManager.Options.LogLevel,
) !*Lockfile {
var timer: if (log_level.isVerbose()) std.time.Timer else void = if (comptime log_level.isVerbose()) try std.time.Timer.start() else {};
var timer: if (log_level.isVerbose()) std.time.Timer else void = if (comptime log_level.isVerbose()) try std.time.Timer.start();

const old_trusted_dependencies = old.trusted_dependencies;
const old_scripts = old.scripts;
Expand Down Expand Up @@ -1616,7 +1616,7 @@ pub fn hoist(
Tree.invalid_id,
method,
&builder,
if (method == .filter) manager.options.log_level else {},
if (method == .filter) manager.options.log_level,
);

// This goes breadth-first
Expand All @@ -1626,7 +1626,7 @@ pub fn hoist(
item.hoist_root_id,
method,
&builder,
if (method == .filter) manager.options.log_level else {},
if (method == .filter) manager.options.log_level,
);
}

Expand Down
Loading

0 comments on commit 68089a0

Please sign in to comment.