Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: just a little bit of cleanup #9319

Merged
merged 2 commits into from Mar 9, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 14 additions & 16 deletions src/install/lockfile.zig
Expand Up @@ -4704,33 +4704,33 @@ pub const Package = extern struct {

pub const Meta = extern struct {
// TODO: when we bump the lockfile version, we should reorder this to:
// id(32), arch(16), os(16), id(8), man_dir(8), __has_install_script(8), integrity(72 align 8)
// id(32), arch(16), os(16), id(8), man_dir(8), has_install_script(8), integrity(72 align 8)
// should allow us to remove padding bytes

// TODO: remove origin. it doesnt do anything and can be inferred from the resolution
origin: Origin = Origin.npm,
_padding_origin: u8 = 0,

arch: Npm.Architecture = Npm.Architecture.all,
os: Npm.OperatingSystem = Npm.OperatingSystem.all,
arch: Npm.Architecture = .all,
os: Npm.OperatingSystem = .all,
_padding_os: u16 = 0,

id: PackageID = invalid_package_id,

man_dir: String = String{},
integrity: Integrity = Integrity{},
man_dir: String = .{},
integrity: Integrity = .{},

/// Shouldn't be used directly. Use `Meta.hasInstallScript()` and
/// `Meta.setHasInstallScript()` instead.
///
/// `.old` represents the value of this field before it was used
/// in the lockfile and should never be saved to a new lockfile.
/// There is a debug assert for this in `Lockfile.Package.Serializer.save()`.
__has_install_script: enum(u8) {
old,
has_install_script: enum(u8) {
old = 0,
false,
true,
},
} = .false,

_padding_integrity: [2]u8 = .{0} ** 2,

Expand All @@ -4741,25 +4741,23 @@ pub const Package = extern struct {
}

pub fn hasInstallScript(this: *const Meta) bool {
return this.__has_install_script == .true;
return this.has_install_script == .true;
}

pub fn setHasInstallScript(this: *Meta, has_script: bool) void {
this.__has_install_script = if (has_script) .true else .false;
this.has_install_script = if (has_script) .true else .false;
}

pub fn needsUpdate(this: *const Meta) bool {
return this.__has_install_script == .old;
return this.has_install_script == .old;
}

pub fn count(this: *const Meta, buf: []const u8, comptime StringBuilderType: type, builder: StringBuilderType) void {
builder.count(this.man_dir.slice(buf));
}

pub fn init() Meta {
return .{
.__has_install_script = .false,
};
return .{};
}

pub fn clone(this: *const Meta, id: PackageID, buf: []const u8, comptime StringBuilderType: type, builder: StringBuilderType) Meta {
Expand All @@ -4770,7 +4768,7 @@ pub const Package = extern struct {
.arch = this.arch,
.os = this.os,
.origin = this.origin,
.__has_install_script = this.__has_install_script,
.has_install_script = this.has_install_script,
};
}
};
Expand Down Expand Up @@ -4852,7 +4850,7 @@ pub const Package = extern struct {
debug("save(\"{s}\") = {d} bytes", .{ field.name, std.mem.sliceAsBytes(value).len });
if (comptime strings.eqlComptime(field.name, "meta")) {
for (value) |meta| {
std.debug.assert(meta.__has_install_script != .old);
std.debug.assert(meta.has_install_script != .old);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/install/migration.zig
Expand Up @@ -487,7 +487,7 @@ pub fn migrateNPMLockfile(this: *Lockfile, allocator: Allocator, log: *logger.Lo

.man_dir = String{},

.__has_install_script = if (pkg.get("hasInstallScript")) |has_install_script_expr| brk: {
.has_install_script = if (pkg.get("hasInstallScript")) |has_install_script_expr| brk: {
if (has_install_script_expr.data != .e_boolean) return error.InvalidNPMLockfile;
break :brk if (has_install_script_expr.data.e_boolean.value)
.true
Expand Down
2 changes: 1 addition & 1 deletion src/install/padding_checker.zig
Expand Up @@ -21,7 +21,7 @@ const std = @import("std");
///
/// The solution is to have it explicitly initialized to zero bytes, like:
/// ```zig
/// const Demo = struct {
/// const Demo = extern struct {
/// a: u8,
/// _padding: [7]u8 = .{0} ** 7,
/// b: u64, // same offset as before
Expand Down
6 changes: 3 additions & 3 deletions src/shell/interpreter.zig
Expand Up @@ -3278,7 +3278,7 @@ pub fn NewInterpreter(comptime EventLoopKind: JSC.EventLoopKind) type {
const err = switch (this.state) {
.expanding_redirect => this.state.expanding_redirect.expansion.state.err,
.expanding_args => this.state.expanding_args.expansion.state.err,
else => @panic("Invalid state"),
else => |t| std.debug.panic("Unexpected state .{s} in Bun shell", .{@tagName(t)}),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Output.panic, we should ban std.debug.panic

};
defer err.deinit(bun.default_allocator);
const buf = err.fmt();
Expand Down Expand Up @@ -6082,7 +6082,7 @@ pub fn NewInterpreter(comptime EventLoopKind: JSC.EventLoopKind) type {
this.bltn.done(this.state.waiting_write_err.exit_code);
return;
},
else => @panic("Invalid state"),
else => |t| std.debug.panic("Unexpected state .{s} in Bun shell 'mv' builtin.", .{@tagName(t)}),
}
}

Expand Down Expand Up @@ -6732,7 +6732,7 @@ pub fn NewInterpreter(comptime EventLoopKind: JSC.EventLoopKind) type {
pub fn onAsyncTaskDone(this: *Rm, task: *ShellRmTask) void {
var exec = &this.state.exec;
const tasks_done = switch (exec.state) {
.idle => @panic("Invalid state"),
.idle => @panic("Unexpected state .idle in Bun shell 'rm' builtin."),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

.waiting => brk: {
exec.state.waiting.tasks_done += 1;
const amt = exec.state.waiting.tasks_done;
Expand Down