diff options
Diffstat (limited to 'src/install')
-rw-r--r-- | src/install/bin.zig | 36 | ||||
-rw-r--r-- | src/install/bit_set.zig | 63 | ||||
-rw-r--r-- | src/install/install.zig | 45 | ||||
-rw-r--r-- | src/install/lockfile.zig | 151 | ||||
-rw-r--r-- | src/install/npm.zig | 6 | ||||
-rw-r--r-- | src/install/repository.zig | 6 | ||||
-rw-r--r-- | src/install/resolvers/folder_resolver.zig | 14 | ||||
-rw-r--r-- | src/install/semver.zig | 57 |
8 files changed, 191 insertions, 187 deletions
diff --git a/src/install/bin.zig b/src/install/bin.zig index f19d8a6ad..3b90544e0 100644 --- a/src/install/bin.zig +++ b/src/install/bin.zig @@ -330,7 +330,7 @@ pub const Bin = extern struct { return; }; const rel = Path.relative(from, to); - std.mem.copy(u8, remain, rel); + bun.copy(u8, remain, rel); remain = remain[rel.len..]; remain[0] = std.fs.path.sep; remain = remain[1..]; @@ -342,7 +342,7 @@ pub const Bin = extern struct { return; } - std.mem.copy(u8, &target_buf, this.global_bin_path); + bun.copy(u8, &target_buf, this.global_bin_path); from_remain = target_buf[this.global_bin_path.len..]; from_remain[0] = std.fs.path.sep; from_remain = from_remain[1..]; @@ -358,7 +358,7 @@ pub const Bin = extern struct { } const name = this.package_name.slice(); - std.mem.copy(u8, remain, name); + bun.copy(u8, remain, name); remain = remain[name.len..]; remain[0] = std.fs.path.sep; remain = remain[1..]; @@ -379,7 +379,7 @@ pub const Bin = extern struct { if (strings.hasPrefixComptime(target, "./")) { target = target["./".len..]; } - std.mem.copy(u8, remain, target); + bun.copy(u8, remain, target); remain = remain[target.len..]; remain[0] = 0; const target_len = @ptrToInt(remain.ptr) - @ptrToInt(&dest_buf); @@ -389,7 +389,7 @@ pub const Bin = extern struct { // we need to use the unscoped package name here // this is why @babel/parser would fail to link const unscoped_name = unscopedPackageName(name); - std.mem.copy(u8, from_remain, unscoped_name); + bun.copy(u8, from_remain, unscoped_name); from_remain = from_remain[unscoped_name.len..]; from_remain[0] = 0; var dest_path: [:0]u8 = target_buf[0 .. @ptrToInt(from_remain.ptr) - @ptrToInt(&target_buf) :0]; @@ -401,7 +401,7 @@ pub const Bin = extern struct { if (strings.hasPrefixComptime(target, "./")) { target = target["./".len..]; } - std.mem.copy(u8, remain, target); + bun.copy(u8, remain, target); remain = remain[target.len..]; remain[0] = 0; const target_len = @ptrToInt(remain.ptr) - @ptrToInt(&dest_buf); @@ -409,7 +409,7 @@ pub const Bin = extern struct { var target_path: [:0]u8 = dest_buf[0..target_len :0]; var name_to_use = this.bin.value.named_file[0].slice(this.string_buf); - std.mem.copy(u8, from_remain, name_to_use); + bun.copy(u8, from_remain, name_to_use); from_remain = from_remain[name_to_use.len..]; from_remain[0] = 0; var dest_path: [:0]u8 = target_buf[0 .. @ptrToInt(from_remain.ptr) - @ptrToInt(&target_buf) :0]; @@ -431,7 +431,7 @@ pub const Bin = extern struct { if (strings.hasPrefixComptime(target, "./")) { target = target["./".len..]; } - std.mem.copy(u8, remain, target); + bun.copy(u8, remain, target); remain = remain[target.len..]; remain[0] = 0; const target_len = @ptrToInt(remain.ptr) - @ptrToInt(&dest_buf); @@ -439,7 +439,7 @@ pub const Bin = extern struct { var target_path: [:0]u8 = dest_buf[0..target_len :0]; var name_to_use = name_in_terminal.slice(this.string_buf); - std.mem.copy(u8, from_remain, name_to_use); + bun.copy(u8, from_remain, name_to_use); from_remain = from_remain[name_to_use.len..]; from_remain[0] = 0; var dest_path: [:0]u8 = target_buf[0 .. @ptrToInt(from_remain.ptr) - @ptrToInt(&target_buf) :0]; @@ -455,7 +455,7 @@ pub const Bin = extern struct { var parts = [_][]const u8{ name, target }; - std.mem.copy(u8, remain, target); + bun.copy(u8, remain, target); remain = remain[target.len..]; var dir = std.fs.Dir{ .fd = this.package_installed_node_modules }; @@ -484,7 +484,7 @@ pub const Bin = extern struct { switch (entry.kind) { std.fs.IterableDir.Entry.Kind.SymLink, std.fs.IterableDir.Entry.Kind.File => { target_buf_remain = prev_target_buf_remain; - std.mem.copy(u8, target_buf_remain, entry.name); + bun.copy(u8, target_buf_remain, entry.name); target_buf_remain = target_buf_remain[entry.name.len..]; target_buf_remain[0] = 0; var from_path: [:0]u8 = target_buf[0 .. @ptrToInt(target_buf_remain.ptr) - @ptrToInt(&target_buf) :0]; @@ -535,7 +535,7 @@ pub const Bin = extern struct { } const name = this.package_name.slice(); - std.mem.copy(u8, remain, name); + bun.copy(u8, remain, name); remain = remain[name.len..]; remain[0] = std.fs.path.sep; remain = remain[1..]; @@ -554,7 +554,7 @@ pub const Bin = extern struct { // we need to use the unscoped package name here // this is why @babel/parser would fail to link const unscoped_name = unscopedPackageName(name); - std.mem.copy(u8, from_remain, unscoped_name); + bun.copy(u8, from_remain, unscoped_name); from_remain = from_remain[unscoped_name.len..]; from_remain[0] = 0; var dest_path: [:0]u8 = target_buf[0 .. @ptrToInt(from_remain.ptr) - @ptrToInt(&target_buf) :0]; @@ -563,7 +563,7 @@ pub const Bin = extern struct { }, .named_file => { var name_to_use = this.bin.value.named_file[0].slice(this.string_buf); - std.mem.copy(u8, from_remain, name_to_use); + bun.copy(u8, from_remain, name_to_use); from_remain = from_remain[name_to_use.len..]; from_remain[0] = 0; var dest_path: [:0]u8 = target_buf[0 .. @ptrToInt(from_remain.ptr) - @ptrToInt(&target_buf) :0]; @@ -585,13 +585,13 @@ pub const Bin = extern struct { if (strings.hasPrefix(target, "./")) { target = target[2..]; } - std.mem.copy(u8, remain, target); + bun.copy(u8, remain, target); remain = remain[target.len..]; remain[0] = 0; remain = remain[1..]; var name_to_use = name_in_terminal.slice(this.string_buf); - std.mem.copy(u8, from_remain, name_to_use); + bun.copy(u8, from_remain, name_to_use); from_remain = from_remain[name_to_use.len..]; from_remain[0] = 0; var dest_path: [:0]u8 = target_buf[0 .. @ptrToInt(from_remain.ptr) - @ptrToInt(&target_buf) :0]; @@ -607,7 +607,7 @@ pub const Bin = extern struct { var parts = [_][]const u8{ name, target }; - std.mem.copy(u8, remain, target); + bun.copy(u8, remain, target); remain = remain[target.len..]; var dir = std.fs.Dir{ .fd = this.package_installed_node_modules }; @@ -636,7 +636,7 @@ pub const Bin = extern struct { switch (entry.kind) { std.fs.IterableDir.Entry.Kind.SymLink, std.fs.IterableDir.Entry.Kind.File => { target_buf_remain = prev_target_buf_remain; - std.mem.copy(u8, target_buf_remain, entry.name); + bun.copy(u8, target_buf_remain, entry.name); target_buf_remain = target_buf_remain[entry.name.len..]; target_buf_remain[0] = 0; var to_path = if (!link_global) diff --git a/src/install/bit_set.zig b/src/install/bit_set.zig index 711c4603f..661a3a4bf 100644 --- a/src/install/bit_set.zig +++ b/src/install/bit_set.zig @@ -31,8 +31,9 @@ //! allocator, in order to save space. const std = @import("std"); -const assert = std.debug.assert; const Allocator = std.mem.Allocator; +const bun = @import("bun"); +const Environment = bun.Environment; /// Returns the optimal static bit set type for the specified number /// of elements. The returned type will perform no allocations, @@ -85,7 +86,7 @@ pub fn IntegerBitSet(comptime size: u16) type { /// Returns true if the bit at the specified index /// is present in the set, false otherwise. pub fn isSet(self: Self, index: usize) bool { - assert(index < bit_length); + if (comptime Environment.allow_assert) std.debug.assert(index < bit_length); return (self.mask & maskBit(index)) != 0; } @@ -97,7 +98,7 @@ pub fn IntegerBitSet(comptime size: u16) type { /// Changes the value of the specified bit of the bit /// set to match the passed boolean. pub fn setValue(self: *Self, index: usize, value: bool) void { - assert(index < bit_length); + if (comptime Environment.allow_assert) std.debug.assert(index < bit_length); if (MaskInt == u0) return; const bit = maskBit(index); const new_bit = bit & std.math.boolMask(MaskInt, value); @@ -106,15 +107,17 @@ pub fn IntegerBitSet(comptime size: u16) type { /// Adds a specific bit to the bit set pub fn set(self: *Self, index: usize) void { - assert(index < bit_length); + if (comptime Environment.allow_assert) std.debug.assert(index < bit_length); self.mask |= maskBit(index); } /// Changes the value of all bits in the specified range to /// match the passed boolean. pub fn setRangeValue(self: *Self, range: Range, value: bool) void { - assert(range.end <= bit_length); - assert(range.start <= range.end); + if (comptime Environment.allow_assert) { + std.debug.assert(range.end <= bit_length); + std.debug.assert(range.start <= range.end); + } if (range.start == range.end) return; if (MaskInt == u0) return; @@ -137,7 +140,7 @@ pub fn IntegerBitSet(comptime size: u16) type { /// Removes a specific bit from the bit set pub fn unset(self: *Self, index: usize) void { - assert(index < bit_length); + if (comptime Environment.allow_assert) std.debug.assert(index < bit_length); // Workaround for #7953 if (MaskInt == u0) return; self.mask &= ~maskBit(index); @@ -145,7 +148,7 @@ pub fn IntegerBitSet(comptime size: u16) type { /// Flips a specific bit in the bit set pub fn toggle(self: *Self, index: usize) void { - assert(index < bit_length); + if (comptime Environment.allow_assert) std.debug.assert(index < bit_length); self.mask ^= maskBit(index); } @@ -400,7 +403,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type { /// Returns true if the bit at the specified index /// is present in the set, false otherwise. pub fn isSet(self: *const Self, index: usize) bool { - assert(index < bit_length); + if (comptime Environment.allow_assert) std.debug.assert(index < bit_length); if (num_masks == 0) return false; // doesn't compile in this case return (self.masks[maskIndex(index)] & maskBit(index)) != 0; } @@ -417,7 +420,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type { /// Changes the value of the specified bit of the bit /// set to match the passed boolean. pub fn setValue(self: *Self, index: usize, value: bool) void { - assert(index < bit_length); + if (comptime Environment.allow_assert) std.debug.assert(index < bit_length); if (num_masks == 0) return; // doesn't compile in this case const bit = maskBit(index); const mask_index = maskIndex(index); @@ -427,7 +430,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type { /// Adds a specific bit to the bit set pub fn set(self: *Self, index: usize) void { - assert(index < bit_length); + if (comptime Environment.allow_assert) std.debug.assert(index < bit_length); if (num_masks == 0) return; // doesn't compile in this case self.masks[maskIndex(index)] |= maskBit(index); } @@ -435,8 +438,10 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type { /// Changes the value of all bits in the specified range to /// match the passed boolean. pub fn setRangeValue(self: *Self, range: Range, value: bool) void { - assert(range.end <= bit_length); - assert(range.start <= range.end); + if (comptime Environment.allow_assert) { + std.debug.assert(range.end <= bit_length); + std.debug.assert(range.start <= range.end); + } if (range.start == range.end) return; if (num_masks == 0) return; @@ -479,14 +484,14 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type { /// Removes a specific bit from the bit set pub fn unset(self: *Self, index: usize) void { - assert(index < bit_length); + if (comptime Environment.allow_assert) std.debug.assert(index < bit_length); if (num_masks == 0) return; // doesn't compile in this case self.masks[maskIndex(index)] &= ~maskBit(index); } /// Flips a specific bit in the bit set pub fn toggle(self: *Self, index: usize) void { - assert(index < bit_length); + if (comptime Environment.allow_assert) std.debug.assert(index < bit_length); if (num_masks == 0) return; // doesn't compile in this case self.masks[maskIndex(index)] ^= maskBit(index); } @@ -702,7 +707,7 @@ pub const DynamicBitSetUnmanaged = struct { const old_allocation = (self.masks - 1)[0..(self.masks - 1)[0]]; if (new_masks == 0) { - assert(new_len == 0); + if (comptime Environment.allow_assert) std.debug.assert(new_len == 0); allocator.free(old_allocation); self.masks = empty_masks_ptr; self.bit_length = 0; @@ -765,7 +770,7 @@ pub const DynamicBitSetUnmanaged = struct { const num_masks = numMasks(self.bit_length); var copy = Self{}; try copy.resize(new_allocator, self.bit_length, false); - std.mem.copy(MaskInt, copy.masks[0..num_masks], self.masks[0..num_masks]); + bun.copy(MaskInt, copy.masks, self.masks[0..num_masks]); return copy; } @@ -777,7 +782,7 @@ pub const DynamicBitSetUnmanaged = struct { /// Returns true if the bit at the specified index /// is present in the set, false otherwise. pub fn isSet(self: Self, index: usize) bool { - assert(index < self.bit_length); + if (comptime Environment.allow_assert) std.debug.assert(index < self.bit_length); return (self.masks[maskIndex(index)] & maskBit(index)) != 0; } @@ -795,7 +800,7 @@ pub const DynamicBitSetUnmanaged = struct { /// Changes the value of the specified bit of the bit /// set to match the passed boolean. pub fn setValue(self: *Self, index: usize, value: bool) void { - assert(index < self.bit_length); + if (comptime Environment.allow_assert) std.debug.assert(index < self.bit_length); const bit = maskBit(index); const mask_index = maskIndex(index); const new_bit = bit & std.math.boolMask(MaskInt, value); @@ -804,15 +809,15 @@ pub const DynamicBitSetUnmanaged = struct { /// Adds a specific bit to the bit set pub fn set(self: *Self, index: usize) void { - assert(index < self.bit_length); + if (comptime Environment.allow_assert) std.debug.assert(index < self.bit_length); self.masks[maskIndex(index)] |= maskBit(index); } /// Changes the value of all bits in the specified range to /// match the passed boolean. pub fn setRangeValue(self: *Self, range: Range, value: bool) void { - assert(range.end <= self.bit_length); - assert(range.start <= range.end); + if (comptime Environment.allow_assert) std.debug.assert(range.end <= self.bit_length); + if (comptime Environment.allow_assert) std.debug.assert(range.start <= range.end); if (range.start == range.end) return; const start_mask_index = maskIndex(range.start); @@ -854,13 +859,13 @@ pub const DynamicBitSetUnmanaged = struct { /// Removes a specific bit from the bit set pub fn unset(self: *Self, index: usize) void { - assert(index < self.bit_length); + if (comptime Environment.allow_assert) std.debug.assert(index < self.bit_length); self.masks[maskIndex(index)] &= ~maskBit(index); } /// Flips a specific bit in the bit set pub fn toggle(self: *Self, index: usize) void { - assert(index < self.bit_length); + if (comptime Environment.allow_assert) std.debug.assert(index < self.bit_length); self.masks[maskIndex(index)] ^= maskBit(index); } @@ -868,7 +873,7 @@ pub const DynamicBitSetUnmanaged = struct { /// in the toggles bit set. Both sets must have the /// same bit_length. pub fn toggleSet(self: *Self, toggles: Self) void { - assert(toggles.bit_length == self.bit_length); + if (comptime Environment.allow_assert) std.debug.assert(toggles.bit_length == self.bit_length); const num_masks = numMasks(self.bit_length); for (&self.masks[0..num_masks], 0..) |*mask, i| { mask.* ^= toggles.masks[i]; @@ -911,7 +916,7 @@ pub const DynamicBitSetUnmanaged = struct { /// set if the corresponding bits were set in either input. /// The two sets must both be the same bit_length. pub fn setUnion(self: *Self, other: Self) void { - assert(other.bit_length == self.bit_length); + if (comptime Environment.allow_assert) std.debug.assert(other.bit_length == self.bit_length); const num_masks = numMasks(self.bit_length); for (&self.masks[0..num_masks], 0..) |*mask, i| { mask.* |= other.masks[i]; @@ -923,7 +928,7 @@ pub const DynamicBitSetUnmanaged = struct { /// set if the corresponding bits were set in both inputs. /// The two sets must both be the same bit_length. pub fn setIntersection(self: *Self, other: Self) void { - assert(other.bit_length == self.bit_length); + if (comptime Environment.allow_assert) std.debug.assert(other.bit_length == self.bit_length); const num_masks = numMasks(self.bit_length); for (&self.masks[0..num_masks], 0..) |*mask, i| { mask.* &= other.masks[i]; @@ -931,7 +936,7 @@ pub const DynamicBitSetUnmanaged = struct { } pub fn setExcludeTwo(self: *Self, other: Self, third: Self) void { - assert(other.bit_length == self.bit_length); + if (comptime Environment.allow_assert) std.debug.assert(other.bit_length == self.bit_length); const num_masks = numMasks(self.bit_length); for (&self.masks[0..num_masks], 0..) |*mask, i| { mask.* &= ~other.masks[i]; @@ -940,7 +945,7 @@ pub const DynamicBitSetUnmanaged = struct { } pub fn setExclude(self: *Self, other: Self) void { - assert(other.bit_length == self.bit_length); + if (comptime Environment.allow_assert) std.debug.assert(other.bit_length == self.bit_length); const num_masks = numMasks(self.bit_length); for (&self.masks[0..num_masks], 0..) |*mask, i| { mask.* &= ~other.masks[i]; diff --git a/src/install/install.zig b/src/install/install.zig index 07bd06692..0c280ccaa 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -81,7 +81,6 @@ const String = Semver.String; const GlobalStringBuilder = @import("../string_builder.zig"); const SlicedString = Semver.SlicedString; const Repository = @import("./repository.zig").Repository; -const StructBuilder = @import("../builder.zig"); const Bin = @import("./bin.zig").Bin; const Dependency = @import("./dependency.zig"); const Behavior = @import("./dependency.zig").Behavior; @@ -799,7 +798,7 @@ const PackageInstall = struct { var total: usize = 0; var read: usize = 0; - std.mem.copy(u8, this.destination_dir_subpath_buf[this.destination_dir_subpath.len..], std.fs.path.sep_str ++ ".bun-tag"); + bun.copy(u8, this.destination_dir_subpath_buf[this.destination_dir_subpath.len..], std.fs.path.sep_str ++ ".bun-tag"); this.destination_dir_subpath_buf[this.destination_dir_subpath.len + std.fs.path.sep_str.len + ".bun-tag".len] = 0; const bun_tag_path: [:0]u8 = this.destination_dir_subpath_buf[0 .. this.destination_dir_subpath.len + std.fs.path.sep_str.len + ".bun-tag".len :0]; defer this.destination_dir_subpath_buf[this.destination_dir_subpath.len] = 0; @@ -861,7 +860,7 @@ const PackageInstall = struct { var total: usize = 0; var read: usize = 0; - std.mem.copy(u8, this.destination_dir_subpath_buf[this.destination_dir_subpath.len..], std.fs.path.sep_str ++ "package.json"); + bun.copy(u8, this.destination_dir_subpath_buf[this.destination_dir_subpath.len..], std.fs.path.sep_str ++ "package.json"); this.destination_dir_subpath_buf[this.destination_dir_subpath.len + std.fs.path.sep_str.len + "package.json".len] = 0; var package_json_path: [:0]u8 = this.destination_dir_subpath_buf[0 .. this.destination_dir_subpath.len + std.fs.path.sep_str.len + "package.json".len :0]; defer this.destination_dir_subpath_buf[this.destination_dir_subpath.len] = 0; @@ -987,7 +986,7 @@ const PackageInstall = struct { std.os.mkdirat(destination_dir_.dir.fd, entry.path, 0o755) catch {}; }, .File => { - std.mem.copy(u8, &stackpath, entry.path); + bun.copy(u8, &stackpath, entry.path); stackpath[entry.path.len] = 0; var path: [:0]u8 = stackpath[0..entry.path.len :0]; var basename: [:0]u8 = stackpath[entry.path.len - entry.basename.len .. entry.path.len :0]; @@ -1681,7 +1680,7 @@ pub const PackageManager = struct { const index = @truncate(DependencyID, this.lockfile.buffers.dependencies.items.len); this.lockfile.buffers.dependencies.append(this.allocator, cloned_dependency) catch unreachable; this.lockfile.buffers.resolutions.append(this.allocator, invalid_package_id) catch unreachable; - if (Environment.allow_assert) std.debug.assert(this.lockfile.buffers.dependencies.items.len == this.lockfile.buffers.resolutions.items.len); + if (comptime Environment.allow_assert) std.debug.assert(this.lockfile.buffers.dependencies.items.len == this.lockfile.buffers.resolutions.items.len); if (is_main) { this.enqueueDependencyWithMainAndSuccessFn( index, @@ -1812,15 +1811,15 @@ pub const PackageManager = struct { ) void { if (Output.isEmojiEnabled()) { if (is_first) { - std.mem.copy(u8, &this.progress_name_buf, emoji); - std.mem.copy(u8, this.progress_name_buf[emoji.len..], name); + bun.copy(u8, &this.progress_name_buf, emoji); + bun.copy(u8, this.progress_name_buf[emoji.len..], name); node.name = this.progress_name_buf[0 .. emoji.len + name.len]; } else { - std.mem.copy(u8, this.progress_name_buf[emoji.len..], name); + bun.copy(u8, this.progress_name_buf[emoji.len..], name); node.name = this.progress_name_buf[0 .. emoji.len + name.len]; } } else { - std.mem.copy(u8, &this.progress_name_buf, name); + bun.copy(u8, &this.progress_name_buf, name); node.name = this.progress_name_buf[0..name.len]; } } @@ -4256,7 +4255,7 @@ pub const PackageManager = struct { const len = std.mem.count(u8, native_packages, " "); if (len > 0) { var all = try allocator.alloc(PackageNameHash, this.native_bin_link_allowlist.len + len); - std.mem.copy(PackageNameHash, all, this.native_bin_link_allowlist); + bun.copy(PackageNameHash, all, this.native_bin_link_allowlist); var remain = all[this.native_bin_link_allowlist.len..]; var splitter = std.mem.split(u8, native_packages, " "); var i: usize = 0; @@ -4373,7 +4372,7 @@ pub const PackageManager = struct { if (cli.link_native_bins.len > 0) { var all = try allocator.alloc(PackageNameHash, this.native_bin_link_allowlist.len + cli.link_native_bins.len); - std.mem.copy(PackageNameHash, all, this.native_bin_link_allowlist); + bun.copy(PackageNameHash, all, this.native_bin_link_allowlist); var remain = all[this.native_bin_link_allowlist.len..]; for (cli.link_native_bins, 0..) |name, i| { remain[i] = String.Builder.stringHash(name); @@ -4527,7 +4526,7 @@ pub const PackageManager = struct { } var new_dependencies = try allocator.alloc(G.Property, dependencies.len + remaining - replacing); - std.mem.copy(G.Property, new_dependencies, dependencies); + bun.copy(G.Property, new_dependencies, dependencies); std.mem.set(G.Property, new_dependencies[dependencies.len..], G.Property{}); outer: for (updates) |*update| { @@ -4618,7 +4617,7 @@ pub const PackageManager = struct { current_package_json.* = JSAst.Expr.init(JSAst.E.Object, JSAst.E.Object{ .properties = JSAst.G.Property.List.init(root_properties) }, logger.Loc.Empty); } else if (needs_new_dependency_list) { var root_properties = try allocator.alloc(JSAst.G.Property, current_package_json.data.e_object.properties.len + 1); - std.mem.copy(JSAst.G.Property, root_properties, current_package_json.data.e_object.properties.slice()); + bun.copy(JSAst.G.Property, root_properties, current_package_json.data.e_object.properties.slice()); root_properties[root_properties.len - 1] = .{ .key = JSAst.Expr.init( JSAst.E.String, @@ -4705,7 +4704,7 @@ pub const PackageManager = struct { var fs = try Fs.FileSystem.init1(ctx.allocator, null); var original_cwd = std.mem.trimRight(u8, fs.top_level_dir, "/"); - std.mem.copy(u8, &cwd_buf, original_cwd); + bun.copy(u8, &cwd_buf, original_cwd); // Step 1. Find the nearest package.json directory // @@ -4736,7 +4735,7 @@ pub const PackageManager = struct { }; } - std.mem.copy(u8, &cwd_buf, original_cwd); + bun.copy(u8, &cwd_buf, original_cwd); cwd_buf[original_cwd.len] = 0; var real_cwd: [:0]u8 = cwd_buf[0..original_cwd.len :0]; std.os.chdirZ(real_cwd) catch {}; @@ -4749,8 +4748,8 @@ pub const PackageManager = struct { cwd_buf[fs.top_level_dir.len] = '/'; cwd_buf[fs.top_level_dir.len + 1] = 0; fs.top_level_dir = cwd_buf[0 .. fs.top_level_dir.len + 1]; - std.mem.copy(u8, &package_json_cwd_buf, fs.top_level_dir); - std.mem.copy(u8, package_json_cwd_buf[fs.top_level_dir.len..], "package.json"); + bun.copy(u8, &package_json_cwd_buf, fs.top_level_dir); + bun.copy(u8, package_json_cwd_buf[fs.top_level_dir.len..], "package.json"); var entries_option = try fs.fs.readDirectory(fs.top_level_dir, null); var options = Options{ @@ -5461,7 +5460,7 @@ pub const PackageManager = struct { buf2[path_.len] = 0; final_path = buf2[0..path_.len :0]; } else { - std.mem.copy(u8, &buf, cwd_); + bun.copy(u8, &buf, cwd_); buf[cwd_.len] = 0; final_path = buf[0..cwd_.len :0]; } @@ -5980,8 +5979,8 @@ pub const PackageManager = struct { var cwd = std.fs.cwd(); // This is not exactly correct var node_modules_buf: [bun.MAX_PATH_BYTES]u8 = undefined; - std.mem.copy(u8, &node_modules_buf, "node_modules" ++ std.fs.path.sep_str); - var offset_buf: []u8 = node_modules_buf["node_modules/".len..]; + bun.copy(u8, &node_modules_buf, "node_modules" ++ std.fs.path.sep_str); + var offset_buf = node_modules_buf["node_modules/".len..]; const name_hashes = manager.lockfile.packages.items(.name_hash); for (updates) |update| { // If the package no longer exists in the updated lockfile, delete the directory @@ -5989,7 +5988,7 @@ pub const PackageManager = struct { // It does not handle nested dependencies // This is a quick & dirty cleanup intended for when deleting top-level dependencies if (std.mem.indexOfScalar(PackageNameHash, name_hashes, String.Builder.stringHash(update.name)) == null) { - std.mem.copy(u8, offset_buf, update.name); + bun.copy(u8, offset_buf, update.name); cwd.deleteTree(node_modules_buf[0 .. "node_modules/".len + update.name.len]) catch {}; } } @@ -6005,7 +6004,7 @@ pub const PackageManager = struct { // any symlinks which we are unable to open are assumed to be dangling // note that using access won't work here, because access doesn't resolve symlinks - std.mem.copy(u8, &node_modules_buf, entry.name); + bun.copy(u8, &node_modules_buf, entry.name); node_modules_buf[entry.name.len] = 0; var buf: [:0]u8 = node_modules_buf[0..entry.name.len :0]; @@ -6134,7 +6133,7 @@ pub const PackageManager = struct { const alias = this.lockfile.buffers.dependencies.items[dependency_id].name.slice(buf); const destination_dir_subpath: [:0]u8 = brk: { - std.mem.copy(u8, &this.destination_dir_subpath_buf, alias); + bun.copy(u8, &this.destination_dir_subpath_buf, alias); this.destination_dir_subpath_buf[alias.len] = 0; break :brk this.destination_dir_subpath_buf[0..alias.len :0]; }; diff --git a/src/install/lockfile.zig b/src/install/lockfile.zig index 80f95ac83..c7009c57b 100644 --- a/src/install/lockfile.zig +++ b/src/install/lockfile.zig @@ -1,3 +1,5 @@ +const std = @import("std"); +const Allocator = std.mem.Allocator; const bun = @import("bun"); const string = bun.string; const Output = bun.Output; @@ -8,10 +10,10 @@ const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; const C = bun.C; -const std = @import("std"); +const JSAst = bun.JSAst; const JSLexer = bun.js_lexer; -const logger = @import("bun").logger; +const logger = bun.logger; const js_parser = bun.js_parser; const Expr = @import("../js_ast.zig").Expr; @@ -31,19 +33,17 @@ const NodeModuleBundle = @import("../node_module_bundle.zig").NodeModuleBundle; const DotEnv = @import("../env_loader.zig"); const which = @import("../which.zig").which; const Run = @import("../bun_js.zig").Run; -const HeaderBuilder = @import("bun").HTTP.HeaderBuilder; +const HeaderBuilder = bun.HTTP.HeaderBuilder; const Fs = @import("../fs.zig"); const FileSystem = Fs.FileSystem; const Lock = @import("../lock.zig").Lock; -var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined; -var path_buf2: [bun.MAX_PATH_BYTES]u8 = undefined; const URL = @import("../url.zig").URL; -const AsyncHTTP = @import("bun").HTTP.AsyncHTTP; -const HTTPChannel = @import("bun").HTTP.HTTPChannel; -const NetworkThread = @import("bun").HTTP.NetworkThread; +const AsyncHTTP = bun.HTTP.AsyncHTTP; +const HTTPChannel = bun.HTTP.HTTPChannel; +const NetworkThread = bun.HTTP.NetworkThread; const Integrity = @import("./integrity.zig").Integrity; -const clap = @import("bun").clap; +const clap = bun.clap; const ExtractTarball = @import("./extract_tarball.zig"); const Npm = @import("./npm.zig"); const Bitset = @import("./bit_set.zig").DynamicBitSetUnmanaged; @@ -58,33 +58,32 @@ const String = Semver.String; const GlobalStringBuilder = @import("../string_builder.zig"); const SlicedString = Semver.SlicedString; const Repository = @import("./repository.zig").Repository; -const StructBuilder = @import("../builder.zig"); const Bin = @import("./bin.zig").Bin; const Dependency = @import("./dependency.zig"); const Behavior = Dependency.Behavior; const FolderResolution = @import("./resolvers/folder_resolver.zig").FolderResolution; -const PackageManager = @import("./install.zig").PackageManager; -const ExternalSlice = @import("./install.zig").ExternalSlice; -const ExternalSliceAligned = @import("./install.zig").ExternalSliceAligned; -const PackageID = @import("./install.zig").PackageID; -const DependencyID = @import("./install.zig").DependencyID; -const Features = @import("./install.zig").Features; -const PackageInstall = @import("./install.zig").PackageInstall; -const PackageNameHash = @import("./install.zig").PackageNameHash; -const Aligner = @import("./install.zig").Aligner; -const ExternalStringMap = @import("./install.zig").ExternalStringMap; -const alignment_bytes_to_repeat_buffer = @import("./install.zig").alignment_bytes_to_repeat_buffer; +const Install = @import("./install.zig"); +const PackageManager = Install.PackageManager; +const ExternalSlice = Install.ExternalSlice; +const ExternalSliceAligned = Install.ExternalSliceAligned; +const PackageID = Install.PackageID; +const DependencyID = Install.DependencyID; +const Features = Install.Features; +const PackageInstall = Install.PackageInstall; +const PackageNameHash = Install.PackageNameHash; +const Aligner = Install.Aligner; +const ExternalStringMap = Install.ExternalStringMap; +const alignment_bytes_to_repeat_buffer = Install.alignment_bytes_to_repeat_buffer; +const initializeStore = Install.initializeStore; +const invalid_package_id = Install.invalid_package_id; +const ExternalStringList = Install.ExternalStringList; const Resolution = @import("./resolution.zig").Resolution; -const initializeStore = @import("./install.zig").initializeStore; -const invalid_package_id = @import("./install.zig").invalid_package_id; -const JSAst = bun.JSAst; -const Origin = @import("./install.zig").Origin; +const Origin = Install.Origin; const Crypto = @import("../sha.zig").Hashers; -pub const MetaHash = [std.crypto.hash.sha2.Sha512256.digest_length]u8; -const zero_hash = std.mem.zeroes(MetaHash); - const PackageJSON = @import("../resolver/package_json.zig").PackageJSON; +const MetaHash = [std.crypto.hash.sha2.Sha512256.digest_length]u8; +const zero_hash = std.mem.zeroes(MetaHash); const NameHashMap = std.ArrayHashMapUnmanaged(u32, String, ArrayIdentityContext, false); // Serialized data @@ -93,16 +92,16 @@ format: FormatVersion = .v1, meta_hash: MetaHash = zero_hash, -packages: Lockfile.Package.List = Lockfile.Package.List{}, -buffers: Buffers = Buffers{}, +packages: Lockfile.Package.List = .{}, +buffers: Buffers = .{}, /// name -> PackageID || [*]PackageID /// Not for iterating. package_index: PackageIndex.Map, unique_packages: Bitset, string_pool: StringPool, -allocator: std.mem.Allocator, -scratch: Scratch = Scratch{}, +allocator: Allocator, +scratch: Scratch = .{}, scripts: Scripts = .{}, workspace_paths: NameHashMap = .{}, @@ -134,7 +133,7 @@ pub const Scripts = struct { this.postprepare.items.len) > 0; } - pub fn run(this: *Scripts, allocator: std.mem.Allocator, env: *DotEnv.Loader, silent: bool, comptime hook: []const u8) !void { + pub fn run(this: *Scripts, allocator: Allocator, env: *DotEnv.Loader, silent: bool, comptime hook: []const u8) !void { for (@field(this, hook).items) |entry| { std.debug.assert(Fs.FileSystem.instance_loaded); const cwd = Path.joinAbsString( @@ -148,7 +147,7 @@ pub const Scripts = struct { } } - pub fn deinit(this: *Scripts, allocator: std.mem.Allocator) void { + pub fn deinit(this: *Scripts, allocator: Allocator) void { this.preinstall.deinit(allocator); this.install.deinit(allocator); this.postinstall.deinit(allocator); @@ -179,7 +178,7 @@ pub const LoadFromDiskResult = union(Tag) { }; }; -pub fn loadFromDisk(this: *Lockfile, allocator: std.mem.Allocator, log: *logger.Log, filename: stringZ) LoadFromDiskResult { +pub fn loadFromDisk(this: *Lockfile, allocator: Allocator, log: *logger.Log, filename: stringZ) LoadFromDiskResult { std.debug.assert(FileSystem.instance_loaded); var file = std.io.getStdIn(); @@ -199,7 +198,7 @@ pub fn loadFromDisk(this: *Lockfile, allocator: std.mem.Allocator, log: *logger. return this.loadFromBytes(buf, allocator, log); } -pub fn loadFromBytes(this: *Lockfile, buf: []u8, allocator: std.mem.Allocator, log: *logger.Log) LoadFromDiskResult { +pub fn loadFromBytes(this: *Lockfile, buf: []u8, allocator: Allocator, log: *logger.Log) LoadFromDiskResult { var stream = Stream{ .buffer = buf, .pos = 0 }; this.format = FormatVersion.current; @@ -324,7 +323,7 @@ pub const Tree = struct { const tree_id = this.depth_stack[depth_buf_len]; const name = this.dependencies[this.trees[tree_id].dependency_id].name.slice(string_buf); - std.mem.copy(u8, this.path_buf[path_written..], name); + bun.copy(u8, this.path_buf[path_written..], name); path_written += name.len; this.path_buf[path_written..][0.."/node_modules".len].* = (std.fs.path.sep_str ++ "node_modules").*; @@ -345,7 +344,7 @@ pub const Tree = struct { }; const Builder = struct { - allocator: std.mem.Allocator, + allocator: Allocator, name_hashes: []const PackageNameHash, list: ArrayList = .{}, resolutions: []const PackageID, @@ -840,7 +839,7 @@ pub const Printer = struct { var lockfile_path_buf2: [bun.MAX_PATH_BYTES]u8 = undefined; pub fn print( - allocator: std.mem.Allocator, + allocator: Allocator, log: *logger.Log, lockfile_path_: string, format: Format, @@ -856,7 +855,7 @@ pub const Printer = struct { lockfile_path_buf2[lockfile_path__.len] = 0; lockfile_path = lockfile_path_buf2[0..lockfile_path__.len :0]; } else { - std.mem.copy(u8, &lockfile_path_buf1, lockfile_path); + bun.copy(u8, &lockfile_path_buf1, lockfile_path); lockfile_path_buf1[lockfile_path_.len] = 0; lockfile_path = lockfile_path_buf1[0..lockfile_path_.len :0]; } @@ -907,7 +906,7 @@ pub const Printer = struct { } pub fn printWithLockfile( - allocator: std.mem.Allocator, + allocator: Allocator, lockfile: *Lockfile, format: Format, comptime Writer: type, @@ -1451,11 +1450,11 @@ inline fn strWithType(this: *Lockfile, comptime Type: type, slicable: Type) stri return slicable.slice(this.buffers.string_bytes.items); } -pub fn initEmpty(this: *Lockfile, allocator: std.mem.Allocator) !void { - this.* = Lockfile{ +pub fn initEmpty(this: *Lockfile, allocator: Allocator) !void { + this.* = .{ .format = Lockfile.FormatVersion.current, - .packages = Lockfile.Package.List{}, - .buffers = Buffers{}, + .packages = .{}, + .buffers = .{}, .package_index = PackageIndex.Map.initContext(allocator, .{}), .unique_packages = try Bitset.initFull(allocator, 0), .string_pool = StringPool.init(allocator), @@ -1574,7 +1573,7 @@ pub const Scratch = struct { duplicate_checker_map: DuplicateCheckerMap = undefined, dependency_list_queue: DependencyQueue = undefined, - pub fn init(allocator: std.mem.Allocator) Scratch { + pub fn init(allocator: Allocator) Scratch { return Scratch{ .dependency_list_queue = DependencyQueue.init(allocator), .duplicate_checker_map = DuplicateCheckerMap.init(allocator), @@ -1583,15 +1582,11 @@ pub const Scratch = struct { }; pub const StringBuilder = struct { - const Allocator = @import("std").mem.Allocator; - const assert = @import("std").debug.assert; - const copy = @import("std").mem.copy; - len: usize = 0, cap: usize = 0, off: usize = 0, ptr: ?[*]u8 = null, - lockfile: *Lockfile = undefined, + lockfile: *Lockfile, pub inline fn count(this: *StringBuilder, slice: string) void { if (String.canInline(slice)) return; @@ -1646,14 +1641,16 @@ pub const StringBuilder = struct { else => @compileError("Invalid type passed to StringBuilder"), } } - assert(this.len <= this.cap); // didn't count everything - assert(this.ptr != null); // must call allocate first + if (comptime Environment.allow_assert) { + std.debug.assert(this.len <= this.cap); // didn't count everything + std.debug.assert(this.ptr != null); // must call allocate first + } - copy(u8, this.ptr.?[this.len..this.cap], slice); + bun.copy(u8, this.ptr.?[this.len..this.cap], slice); const final_slice = this.ptr.?[this.len..this.cap][0..slice.len]; this.len += slice.len; - assert(this.len <= this.cap); + if (comptime Environment.allow_assert) std.debug.assert(this.len <= this.cap); switch (Type) { String => { @@ -1679,19 +1676,21 @@ pub const StringBuilder = struct { } } - assert(this.len <= this.cap); // didn't count everything - assert(this.ptr != null); // must call allocate first + if (comptime Environment.allow_assert) { + std.debug.assert(this.len <= this.cap); // didn't count everything + std.debug.assert(this.ptr != null); // must call allocate first + } var string_entry = this.lockfile.string_pool.getOrPut(hash) catch unreachable; if (!string_entry.found_existing) { - copy(u8, this.ptr.?[this.len..this.cap], slice); + bun.copy(u8, this.ptr.?[this.len..this.cap], slice); const final_slice = this.ptr.?[this.len..this.cap][0..slice.len]; this.len += slice.len; string_entry.value_ptr.* = String.init(this.lockfile.buffers.string_bytes.items, final_slice); } - assert(this.len <= this.cap); + if (comptime Environment.allow_assert) std.debug.assert(this.len <= this.cap); switch (Type) { String => { @@ -2003,7 +2002,7 @@ pub const Package = extern struct { } pub fn fromNPM( - allocator: std.mem.Allocator, + allocator: Allocator, lockfile: *Lockfile, log: *logger.Log, manifest: *const Npm.PackageManifest, @@ -2225,7 +2224,7 @@ pub const Package = extern struct { }; pub fn generate( - _: std.mem.Allocator, + _: Allocator, from_lockfile: *Lockfile, to_lockfile: *Lockfile, from: *Lockfile.Package, @@ -2286,7 +2285,7 @@ pub const Package = extern struct { pub fn parseMain( package: *Lockfile.Package, lockfile: *Lockfile, - allocator: std.mem.Allocator, + allocator: Allocator, log: *logger.Log, source: logger.Source, comptime features: Features, @@ -2297,7 +2296,7 @@ pub const Package = extern struct { pub fn parse( package: *Lockfile.Package, lockfile: *Lockfile, - allocator: std.mem.Allocator, + allocator: Allocator, log: *logger.Log, source: logger.Source, comptime ResolverContext: type, @@ -2331,7 +2330,7 @@ pub const Package = extern struct { fn parseDependency( lockfile: *Lockfile, - allocator: std.mem.Allocator, + allocator: Allocator, log: *logger.Log, source: logger.Source, comptime group: DependencyGroup, @@ -2455,7 +2454,7 @@ pub const Package = extern struct { fn processWorkspaceNamesArray( workspace_names_ptr: *[]string, - allocator: std.mem.Allocator, + allocator: Allocator, log: *logger.Log, arr: *JSAst.E.Array, source: *const logger.Source, @@ -2578,7 +2577,7 @@ pub const Package = extern struct { fn parseWithJSON( package: *Lockfile.Package, lockfile: *Lockfile, - allocator: std.mem.Allocator, + allocator: Allocator, log: *logger.Log, source: logger.Source, json: Expr, @@ -2833,7 +2832,7 @@ pub const Package = extern struct { try lockfile.buffers.resolutions.ensureUnusedCapacity(lockfile.allocator, total_dependencies_count); const total_len = lockfile.buffers.dependencies.items.len + total_dependencies_count; - if (Environment.allow_assert) std.debug.assert(lockfile.buffers.dependencies.items.len == lockfile.buffers.resolutions.items.len); + if (comptime Environment.allow_assert) std.debug.assert(lockfile.buffers.dependencies.items.len == lockfile.buffers.resolutions.items.len); const off = lockfile.buffers.dependencies.items.len; var package_dependencies = lockfile.buffers.dependencies.items.ptr[off..total_len]; @@ -2903,7 +2902,7 @@ pub const Package = extern struct { std.debug.assert(i == extern_strings.len); package.bin = .{ .tag = .map, - .value = .{ .map = @import("./install.zig").ExternalStringList.init(lockfile.buffers.extern_strings.items, extern_strings) }, + .value = .{ .map = ExternalStringList.init(lockfile.buffers.extern_strings.items, extern_strings) }, }; }, } @@ -3216,7 +3215,7 @@ pub const Package = extern struct { pub fn load( stream: *Stream, end: usize, - allocator: std.mem.Allocator, + allocator: Allocator, ) !Lockfile.Package.List { var reader = stream.reader(); @@ -3279,7 +3278,7 @@ const Buffers = struct { // node_modules_package_ids: PackageIDList = PackageIDList{}, string_bytes: StringBuffer = .{}, - pub fn deinit(this: *Buffers, allocator: std.mem.Allocator) void { + pub fn deinit(this: *Buffers, allocator: Allocator) void { this.trees.deinit(allocator); this.resolutions.deinit(allocator); this.dependencies.deinit(allocator); @@ -3287,7 +3286,7 @@ const Buffers = struct { this.string_bytes.deinit(allocator); } - pub fn preallocate(this: *Buffers, that: Buffers, allocator: std.mem.Allocator) !void { + pub fn preallocate(this: *Buffers, that: Buffers, allocator: Allocator) !void { try this.trees.ensureTotalCapacity(allocator, that.trees.items.len); try this.resolutions.ensureTotalCapacity(allocator, that.resolutions.items.len); try this.dependencies.ensureTotalCapacity(allocator, that.dependencies.items.len); @@ -3335,7 +3334,7 @@ const Buffers = struct { }; }; - pub fn readArray(stream: *Stream, allocator: std.mem.Allocator, comptime ArrayList: type) !ArrayList { + pub fn readArray(stream: *Stream, allocator: Allocator, comptime ArrayList: type) !ArrayList { const arraylist: ArrayList = undefined; const PointerType = std.meta.Child(@TypeOf(arraylist.items.ptr)); @@ -3401,7 +3400,7 @@ const Buffers = struct { } } - pub fn save(this: Buffers, allocator: std.mem.Allocator, comptime StreamType: type, stream: StreamType, comptime Writer: type, writer: Writer) !void { + pub fn save(this: Buffers, allocator: Allocator, comptime StreamType: type, stream: StreamType, comptime Writer: type, writer: Writer) !void { inline for (sizes.names) |name| { if (PackageManager.instance.options.log_level.isVerbose()) { Output.prettyErrorln("Saving {d} {s}", .{ @field(this, name).items.len, name }); @@ -3461,7 +3460,7 @@ const Buffers = struct { return error.@"Lockfile is missing resolution data"; } - pub fn load(stream: *Stream, allocator: std.mem.Allocator, log: *logger.Log) !Buffers { + pub fn load(stream: *Stream, allocator: Allocator, log: *logger.Log) !Buffers { var this = Buffers{}; var external_dependency_list_: std.ArrayListUnmanaged(Dependency.External) = std.ArrayListUnmanaged(Dependency.External){}; @@ -3571,7 +3570,7 @@ pub const Serializer = struct { pub fn load( lockfile: *Lockfile, stream: *Stream, - allocator: std.mem.Allocator, + allocator: Allocator, log: *logger.Log, ) !void { var reader = stream.reader(); @@ -3641,7 +3640,7 @@ pub fn hasMetaHashChanged(this: *Lockfile, print_name_version_string: bool) !boo this.meta_hash = try this.generateMetaHash(print_name_version_string); return !strings.eqlLong(&previous_meta_hash, &this.meta_hash, false); } -pub fn generateMetaHash(this: *Lockfile, print_name_version_string: bool) !MetaHash { +fn generateMetaHash(this: *Lockfile, print_name_version_string: bool) !MetaHash { if (this.packages.len <= 1) return zero_hash; diff --git a/src/install/npm.zig b/src/install/npm.zig index 66f9d02cb..e7fa24b1a 100644 --- a/src/install/npm.zig +++ b/src/install/npm.zig @@ -180,10 +180,10 @@ pub const Registry = struct { const hashed = HTTPClient.hashHeaderName(header.name); switch (hashed) { - HTTPClient.hashHeaderName("last-modified") => { + HTTPClient.hashHeaderConst("last-modified") => { newly_last_modified = header.value; }, - HTTPClient.hashHeaderName("etag") => { + HTTPClient.hashHeaderConst("etag") => { new_etag = header.value; }, else => {}, @@ -193,7 +193,7 @@ pub const Registry = struct { var new_etag_buf: [64]u8 = undefined; if (new_etag.len < new_etag_buf.len) { - std.mem.copy(u8, &new_etag_buf, new_etag); + bun.copy(u8, &new_etag_buf, new_etag); new_etag = new_etag_buf[0..new_etag.len]; } diff --git a/src/install/repository.zig b/src/install/repository.zig index 557953d76..c63f1294e 100644 --- a/src/install/repository.zig +++ b/src/install/repository.zig @@ -79,7 +79,7 @@ pub const Repository = extern struct { buf: []const u8, repository: *const Repository, pub fn format(formatter: Formatter, comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void { - if (Environment.allow_assert) std.debug.assert(formatter.label.len > 0); + if (comptime Environment.allow_assert) std.debug.assert(formatter.label.len > 0); try writer.writeAll(formatter.label); const repo = formatter.repository.repo.slice(formatter.buf); @@ -124,13 +124,13 @@ pub const Repository = extern struct { pub fn tryHTTPS(url: string) ?string { if (strings.hasPrefixComptime(url, "ssh://")) { final_path_buf[0.."https".len].* = "https".*; - std.mem.copy(u8, final_path_buf["https".len..], url["ssh".len..]); + bun.copy(u8, final_path_buf["https".len..], url["ssh".len..]); return final_path_buf[0..(url.len - "ssh".len + "https".len)]; } if (Dependency.isSCPLikePath(url)) { final_path_buf[0.."https://".len].* = "https://".*; var rest = final_path_buf["https://".len..]; - std.mem.copy(u8, rest, url); + bun.copy(u8, rest, url); if (strings.indexOfChar(rest, ':')) |colon| rest[colon] = '/'; return final_path_buf[0..(url.len + "https://".len)]; } diff --git a/src/install/resolvers/folder_resolver.zig b/src/install/resolvers/folder_resolver.zig index c16f0c8ed..c9cc682aa 100644 --- a/src/install/resolvers/folder_resolver.zig +++ b/src/install/resolvers/folder_resolver.zig @@ -84,10 +84,9 @@ pub const FolderResolution = union(Tag) { if (strings.startsWithChar(normalized, '.')) { var tempcat: [bun.MAX_PATH_BYTES]u8 = undefined; - std.mem.copy(u8, &tempcat, normalized); - tempcat[normalized.len] = std.fs.path.sep; - std.mem.copy(u8, tempcat[normalized.len + 1 ..], "package.json"); - var parts = [_]string{ FileSystem.instance.top_level_dir, tempcat[0 .. normalized.len + 1 + "package.json".len] }; + bun.copy(u8, &tempcat, normalized); + tempcat[normalized.len..][0.."/package.json".len].* = (std.fs.path.sep_str ++ "package.json").*; + var parts = [_]string{ FileSystem.instance.top_level_dir, tempcat[0 .. normalized.len + "/package.json".len] }; abs = FileSystem.instance.absBuf(&parts, joined); rel = FileSystem.instance.relative(FileSystem.instance.top_level_dir, abs[0 .. abs.len - "/package.json".len]); } else { @@ -110,10 +109,9 @@ pub const FolderResolution = union(Tag) { }, else => {}, } - std.mem.copy(u8, remain, normalized); - remain[normalized.len] = std.fs.path.sep; - remain[normalized.len + 1 ..][0.."package.json".len].* = "package.json".*; - remain = remain[normalized.len + 1 + "package.json".len ..]; + bun.copy(u8, remain, normalized); + remain[normalized.len..][0.."/package.json".len].* = (std.fs.path.sep_str ++ "package.json").*; + remain = remain[normalized.len + "/package.json".len ..]; abs = joined[0 .. joined.len - remain.len]; // We store the folder name without package.json rel = abs[0 .. abs.len - "/package.json".len]; diff --git a/src/install/semver.zig b/src/install/semver.zig index f9e16968f..e96b1cddc 100644 --- a/src/install/semver.zig +++ b/src/install/semver.zig @@ -1,3 +1,5 @@ +const std = @import("std"); +const Allocator = std.mem.Allocator; const bun = @import("bun"); const string = bun.string; const Output = bun.Output; @@ -8,7 +10,7 @@ const MutableString = bun.MutableString; const stringZ = bun.stringZ; const default_allocator = bun.default_allocator; const C = bun.C; -const std = @import("std"); +const IdentityContext = @import("../identity_context.zig").IdentityContext; /// String type that stores either an offset/length into an external buffer or a string inline directly pub const String = extern struct { @@ -301,11 +303,6 @@ pub const String = extern struct { } pub const Builder = struct { - const Allocator = @import("std").mem.Allocator; - const assert = @import("std").debug.assert; - const copy = @import("std").mem.copy; - const IdentityContext = @import("../identity_context.zig").IdentityContext; - len: usize = 0, cap: usize = 0, ptr: ?[*]u8 = null, @@ -335,7 +332,7 @@ pub const String = extern struct { else &[_]u8{}; } - pub fn allocate(this: *Builder, allocator: std.mem.Allocator) !void { + pub fn allocate(this: *Builder, allocator: Allocator) !void { var ptr_ = try allocator.alloc(u8, this.cap); this.ptr = ptr_.ptr; } @@ -359,14 +356,16 @@ pub const String = extern struct { } } - assert(this.len <= this.cap); // didn't count everything - assert(this.ptr != null); // must call allocate first + if (comptime Environment.allow_assert) { + std.debug.assert(this.len <= this.cap); // didn't count everything + std.debug.assert(this.ptr != null); // must call allocate first + } - copy(u8, this.ptr.?[this.len..this.cap], slice_); + bun.copy(u8, this.ptr.?[this.len..this.cap], slice_); const final_slice = this.ptr.?[this.len..this.cap][0..slice_.len]; this.len += slice_.len; - assert(this.len <= this.cap); + if (comptime Environment.allow_assert) std.debug.assert(this.len <= this.cap); switch (Type) { String => { @@ -392,14 +391,16 @@ pub const String = extern struct { else => @compileError("Invalid type passed to StringBuilder"), } } - assert(this.len <= this.cap); // didn't count everything - assert(this.ptr != null); // must call allocate first + if (comptime Environment.allow_assert) { + std.debug.assert(this.len <= this.cap); // didn't count everything + std.debug.assert(this.ptr != null); // must call allocate first + } - copy(u8, this.ptr.?[this.len..this.cap], slice_); + bun.copy(u8, this.ptr.?[this.len..this.cap], slice_); const final_slice = this.ptr.?[this.len..this.cap][0..slice_.len]; this.len += slice_.len; - assert(this.len <= this.cap); + if (comptime Environment.allow_assert) std.debug.assert(this.len <= this.cap); switch (Type) { String => { @@ -425,19 +426,21 @@ pub const String = extern struct { } } - assert(this.len <= this.cap); // didn't count everything - assert(this.ptr != null); // must call allocate first + if (comptime Environment.allow_assert) { + std.debug.assert(this.len <= this.cap); // didn't count everything + std.debug.assert(this.ptr != null); // must call allocate first + } var string_entry = this.string_pool.getOrPut(hash) catch unreachable; if (!string_entry.found_existing) { - copy(u8, this.ptr.?[this.len..this.cap], slice_); + bun.copy(u8, this.ptr.?[this.len..this.cap], slice_); const final_slice = this.ptr.?[this.len..this.cap][0..slice_.len]; this.len += slice_.len; string_entry.value_ptr.* = String.init(this.allocatedSlice(), final_slice); } - assert(this.len <= this.cap); + if (comptime Environment.allow_assert) std.debug.assert(this.len <= this.cap); switch (Type) { String => { @@ -765,7 +768,7 @@ pub const Version = extern struct { pre = this.pre.value; } else { const pre_slice = this.pre.slice(slice); - std.mem.copy(u8, buf.*, pre_slice); + bun.copy(u8, buf.*, pre_slice); pre = String.init(buf.*, buf.*[0..pre_slice.len]); buf.* = buf.*[pre_slice.len..]; } @@ -774,7 +777,7 @@ pub const Version = extern struct { build = this.build.value; } else { const build_slice = this.build.slice(slice); - std.mem.copy(u8, buf.*, build_slice); + bun.copy(u8, buf.*, build_slice); build = String.init(buf.*, buf.*[0..build_slice.len]); buf.* = buf.*[build_slice.len..]; } @@ -811,11 +814,11 @@ pub const Version = extern struct { var multi_tag_warn = false; // TODO: support multiple tags - pub fn parse(allocator: std.mem.Allocator, sliced_string: SlicedString) TagResult { + pub fn parse(allocator: Allocator, sliced_string: SlicedString) TagResult { return parseWithPreCount(allocator, sliced_string, 0); } - pub fn parseWithPreCount(_: std.mem.Allocator, sliced_string: SlicedString, initial_pre_count: u32) TagResult { + pub fn parseWithPreCount(_: Allocator, sliced_string: SlicedString, initial_pre_count: u32) TagResult { var input = sliced_string.slice; var build_count: u32 = 0; var pre_count: u32 = initial_pre_count; @@ -929,7 +932,7 @@ pub const Version = extern struct { stopped_at: u32 = 0, }; - pub fn parse(sliced_string: SlicedString, allocator: std.mem.Allocator) ParseResult { + pub fn parse(sliced_string: SlicedString, allocator: Allocator) ParseResult { var input = sliced_string.slice; var result = ParseResult{}; @@ -1338,7 +1341,7 @@ pub const Query = struct { return lhs_next.eql(rhs_next); } - pub fn andRange(self: *List, allocator: std.mem.Allocator, range: Range) !void { + pub fn andRange(self: *List, allocator: Allocator, range: Range) !void { if (!self.head.range.hasLeft() and !self.head.range.hasRight()) { self.head.range = range; return; @@ -1359,7 +1362,7 @@ pub const Query = struct { pub const Group = struct { head: List = List{}, tail: ?*List = null, - allocator: std.mem.Allocator, + allocator: Allocator, input: string = "", flags: FlagsBitSet = FlagsBitSet.initEmpty(), @@ -1686,7 +1689,7 @@ pub const Query = struct { }; pub fn parse( - allocator: std.mem.Allocator, + allocator: Allocator, input: string, sliced: SlicedString, ) !Group { |