aboutsummaryrefslogtreecommitdiff
path: root/src/install
diff options
context:
space:
mode:
authorGravatar Dylan Conway <35280289+dylan-conway@users.noreply.github.com> 2023-02-23 23:57:19 -0800
committerGravatar GitHub <noreply@github.com> 2023-02-23 23:57:19 -0800
commit3f04f8d0a653cf5decef2225c2044742b382718a (patch)
tree91eb6500834e3157ecb9ab208101aa368a1191c8 /src/install
parentb5bdde28ed34070cbb1d34d13f414f4c513ee40d (diff)
downloadbun-3f04f8d0a653cf5decef2225c2044742b382718a.tar.gz
bun-3f04f8d0a653cf5decef2225c2044742b382718a.tar.zst
bun-3f04f8d0a653cf5decef2225c2044742b382718a.zip
Upgrade Zig (#2151)
* fixup * Upgrade Zig * Remove bad assertion * strings * bump * mode -> optimize * optimize * Linux build * Update bindgen.zig
Diffstat (limited to 'src/install')
-rw-r--r--src/install/bin.zig2
-rw-r--r--src/install/bit_set.zig24
-rw-r--r--src/install/dependency.zig8
-rw-r--r--src/install/install.zig10
-rw-r--r--src/install/lockfile.zig62
-rw-r--r--src/install/npm.zig8
6 files changed, 57 insertions, 57 deletions
diff --git a/src/install/bin.zig b/src/install/bin.zig
index dfd29c927..f19d8a6ad 100644
--- a/src/install/bin.zig
+++ b/src/install/bin.zig
@@ -85,7 +85,7 @@ pub const Bin = extern struct {
.value = .{ .dir = builder.append(String, this.value.dir.slice(buf)) },
},
.map => {
- for (this.value.map.get(prev_external_strings)) |extern_string, i| {
+ for (this.value.map.get(prev_external_strings), 0..) |extern_string, i| {
extern_strings_slice[i] = builder.append(ExternalString, extern_string.slice(buf));
}
diff --git a/src/install/bit_set.zig b/src/install/bit_set.zig
index bd6d71027..711c4603f 100644
--- a/src/install/bit_set.zig
+++ b/src/install/bit_set.zig
@@ -495,14 +495,14 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type {
/// in the toggles bit set.
pub fn toggleSet(self: *Self, toggles: *const Self) void {
const other = &toggles.masks;
- for (self.masks) |*mask, i| {
+ for (&self.masks, 0..) |*mask, i| {
mask.* ^= other[i];
}
}
/// Flips every bit in the bit set.
pub fn toggleAll(self: *Self) void {
- for (self.masks) |*mask| {
+ for (&self.masks) |*mask| {
mask.* = ~mask.*;
}
@@ -516,7 +516,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type {
/// result in the first one. Bits in the result are
/// set if the corresponding bits were set in either input.
pub fn setUnion(self: *Self, other: *const Self) void {
- for (self.masks) |*mask, i| {
+ for (&self.masks, 0..) |*mask, i| {
mask.* |= other.masks[i];
}
}
@@ -525,7 +525,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type {
/// the result in the first one. Bits in the result are
/// set if the corresponding bits were set in both inputs.
pub fn setIntersection(self: *Self, other: *const Self) void {
- for (self.masks) |*mask, i| {
+ for (&self.masks, 0..) |*mask, i| {
mask.* &= other.masks[i];
}
}
@@ -545,7 +545,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type {
/// If no bits are set, returns null.
pub fn toggleFirstSet(self: *Self) ?usize {
var offset: usize = 0;
- const mask = for (self.masks) |*mask| {
+ const mask = for (&self.masks) |*mask| {
if (mask.* != 0) break mask;
offset += @bitSizeOf(MaskInt);
} else return null;
@@ -870,7 +870,7 @@ pub const DynamicBitSetUnmanaged = struct {
pub fn toggleSet(self: *Self, toggles: Self) void {
assert(toggles.bit_length == self.bit_length);
const num_masks = numMasks(self.bit_length);
- for (self.masks[0..num_masks]) |*mask, i| {
+ for (&self.masks[0..num_masks], 0..) |*mask, i| {
mask.* ^= toggles.masks[i];
}
}
@@ -882,7 +882,7 @@ pub const DynamicBitSetUnmanaged = struct {
if (bit_length == 0) return;
const num_masks = numMasks(self.bit_length);
- for (self.masks[0..num_masks]) |*mask| {
+ for (&self.masks[0..num_masks]) |*mask| {
mask.* = ~mask.*;
}
@@ -897,7 +897,7 @@ pub const DynamicBitSetUnmanaged = struct {
if (bit_length == 0) return;
const num_masks = numMasks(self.bit_length);
- for (self.masks[0..num_masks]) |*mask, i| {
+ for (&self.masks[0..num_masks], 0..) |*mask, i| {
mask.* = other.masks[i];
}
@@ -913,7 +913,7 @@ pub const DynamicBitSetUnmanaged = struct {
pub fn setUnion(self: *Self, other: Self) void {
assert(other.bit_length == self.bit_length);
const num_masks = numMasks(self.bit_length);
- for (self.masks[0..num_masks]) |*mask, i| {
+ for (&self.masks[0..num_masks], 0..) |*mask, i| {
mask.* |= other.masks[i];
}
}
@@ -925,7 +925,7 @@ pub const DynamicBitSetUnmanaged = struct {
pub fn setIntersection(self: *Self, other: Self) void {
assert(other.bit_length == self.bit_length);
const num_masks = numMasks(self.bit_length);
- for (self.masks[0..num_masks]) |*mask, i| {
+ for (&self.masks[0..num_masks], 0..) |*mask, i| {
mask.* &= other.masks[i];
}
}
@@ -933,7 +933,7 @@ pub const DynamicBitSetUnmanaged = struct {
pub fn setExcludeTwo(self: *Self, other: Self, third: Self) void {
assert(other.bit_length == self.bit_length);
const num_masks = numMasks(self.bit_length);
- for (self.masks[0..num_masks]) |*mask, i| {
+ for (&self.masks[0..num_masks], 0..) |*mask, i| {
mask.* &= ~other.masks[i];
mask.* &= ~third.masks[i];
}
@@ -942,7 +942,7 @@ pub const DynamicBitSetUnmanaged = struct {
pub fn setExclude(self: *Self, other: Self) void {
assert(other.bit_length == self.bit_length);
const num_masks = numMasks(self.bit_length);
- for (self.masks[0..num_masks]) |*mask, i| {
+ for (&self.masks[0..num_masks], 0..) |*mask, i| {
mask.* &= ~other.masks[i];
}
}
diff --git a/src/install/dependency.zig b/src/install/dependency.zig
index 902195170..d93629a82 100644
--- a/src/install/dependency.zig
+++ b/src/install/dependency.zig
@@ -165,7 +165,7 @@ pub inline fn isSCPLikePath(dependency: string) bool {
var at_index: ?usize = null;
- for (dependency) |c, i| {
+ for (dependency, 0..) |c, i| {
switch (c) {
'@' => {
if (at_index == null) at_index = i;
@@ -189,7 +189,7 @@ pub inline fn isGitHubRepoPath(dependency: string) bool {
var hash_index: usize = 0;
var slash_index: usize = 0;
- for (dependency) |c, i| {
+ for (dependency, 0..) |c, i| {
switch (c) {
'/' => {
if (i == 0) return false;
@@ -492,7 +492,7 @@ pub const Version = struct {
'n' => {
if (strings.hasPrefixComptime(dependency, "npm:") and dependency.len > "npm:".len) {
const remain = dependency["npm:".len + @boolToInt(dependency["npm:".len] == '@') ..];
- for (remain) |c, i| {
+ for (remain, 0..) |c, i| {
if (c == '@') {
return infer(remain[i + 1 ..]);
}
@@ -772,7 +772,7 @@ pub fn parseWithTag(
var hash_index: usize = 0;
var slash_index: usize = 0;
- for (input) |c, i| {
+ for (input, 0..) |c, i| {
switch (c) {
'/' => {
slash_index = i;
diff --git a/src/install/install.zig b/src/install/install.zig
index c4de35fe9..07bd06692 100644
--- a/src/install/install.zig
+++ b/src/install/install.zig
@@ -1649,7 +1649,7 @@ pub const PackageManager = struct {
is_main: bool,
) DependencyToEnqueue {
const str_buf = this.lockfile.buffers.string_bytes.items;
- for (this.lockfile.buffers.dependencies.items) |dependency, dependency_id| {
+ for (this.lockfile.buffers.dependencies.items, 0..) |dependency, dependency_id| {
if (!strings.eqlLong(dependency.name.slice(str_buf), name, true)) continue;
if (!dependency.version.eql(version, str_buf, version_buf)) continue;
return switch (this.lockfile.buffers.resolutions.items[dependency_id]) {
@@ -4082,7 +4082,7 @@ pub const PackageManager = struct {
}
if (bun_install_) |bun_install| {
if (bun_install.scoped) |scoped| {
- for (scoped.scopes) |name, i| {
+ for (scoped.scopes, 0..) |name, i| {
var registry = scoped.registries[i];
if (registry.url.len == 0) registry.url = base.url;
try this.registries.put(allocator, Npm.Registry.Scope.hash(name), try Npm.Registry.Scope.fromAPI(name, registry, allocator, env));
@@ -4104,7 +4104,7 @@ pub const PackageManager = struct {
if (bun_install.native_bin_links.len > 0) {
var buf = try allocator.alloc(u64, bun_install.native_bin_links.len);
- for (bun_install.native_bin_links) |name, i| {
+ for (bun_install.native_bin_links, 0..) |name, i| {
buf[i] = String.Builder.stringHash(name);
}
this.native_bin_link_allowlist = buf;
@@ -4375,7 +4375,7 @@ pub const PackageManager = struct {
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);
var remain = all[this.native_bin_link_allowlist.len..];
- for (cli.link_native_bins) |name, i| {
+ for (cli.link_native_bins, 0..) |name, i| {
remain[i] = String.Builder.stringHash(name);
}
this.native_bin_link_allowlist = all;
@@ -6901,7 +6901,7 @@ pub const PackageManager = struct {
manager.lockfile.buffers.dependencies.items = manager.lockfile.buffers.dependencies.items.ptr[0 .. off + len];
manager.lockfile.buffers.resolutions.items = manager.lockfile.buffers.resolutions.items.ptr[0 .. off + len];
- for (new_dependencies) |new_dep, i| {
+ for (new_dependencies, 0..) |new_dep, i| {
dependencies[i] = try new_dep.clone(lockfile.buffers.string_bytes.items, *Lockfile.StringBuilder, builder);
if (mapping[i] != invalid_package_id) {
resolutions[i] = old_resolutions[mapping[i]];
diff --git a/src/install/lockfile.zig b/src/install/lockfile.zig
index ed60f55cd..80f95ac83 100644
--- a/src/install/lockfile.zig
+++ b/src/install/lockfile.zig
@@ -375,7 +375,7 @@ pub const Tree = struct {
var dependency_ids = try DependencyIDList.initCapacity(z_allocator, total);
var next = PackageIDSlice{};
- for (trees) |*tree, id| {
+ for (trees, 0..) |*tree, id| {
if (tree.dependencies.len > 0) {
var child = dependencies[id];
const len = @truncate(PackageID, child.items.len);
@@ -525,7 +525,7 @@ pub fn maybeCloneFilteringRootPackages(
var any_changes = false;
const end = @truncate(PackageID, old.packages.len);
- for (root_dependencies) |dependency, i| {
+ for (root_dependencies, 0..) |dependency, i| {
if (!dependency.behavior.isEnabled(features) and resolutions[i] < end) {
resolutions[i] = invalid_package_id;
any_changes = true;
@@ -550,7 +550,7 @@ fn preprocessUpdateRequests(old: *Lockfile, updates: []PackageManager.UpdateRequ
for (updates) |update| {
if (update.version.tag == .uninitialized) {
- for (root_deps) |dep, i| {
+ for (root_deps, 0..) |dep, i| {
if (dep.name_hash == String.Builder.stringHash(update.name)) {
const old_resolution = old_resolutions[i];
if (old_resolution > old.packages.len) continue;
@@ -577,9 +577,9 @@ fn preprocessUpdateRequests(old: *Lockfile, updates: []PackageManager.UpdateRequ
const old_resolutions: []const PackageID = old_resolutions_list.get(old.buffers.resolutions.items);
const resolutions_of_yore: []const Resolution = old.packages.items(.resolution);
- for (updates) |update, update_i| {
+ for (updates, 0..) |update, update_i| {
if (update.version.tag == .uninitialized) {
- for (root_deps) |*dep, i| {
+ for (root_deps, 0..) |*dep, i| {
if (dep.name_hash == String.Builder.stringHash(update.name)) {
const old_resolution = old_resolutions[i];
if (old_resolution > old.packages.len) continue;
@@ -702,7 +702,7 @@ pub fn clean(old: *Lockfile, updates: []PackageManager.UpdateRequest) !*Lockfile
for (updates) |*update| {
if (update.resolution.tag == .uninitialized) {
- for (root_deps) |dep, i| {
+ for (root_deps, 0..) |dep, i| {
if (update.matches(dep, string_buf)) {
const package_id = resolved_ids[i];
if (package_id > new.packages.len) continue;
@@ -893,7 +893,7 @@ pub const Printer = struct {
},
.not_found => {
Output.prettyErrorln("<r><red>lockfile not found:<r> {s}", .{
- std.mem.span(lockfile_path),
+ std.mem.sliceAsBytes(lockfile_path),
});
Global.crash();
},
@@ -988,7 +988,7 @@ pub const Printer = struct {
const package_name = dependency.name.slice(string_buf);
if (this.updates.len > 0) {
- for (this.updates) |update, update_id| {
+ for (this.updates, 0..) |update, update_id| {
if (update.failed) return;
if (update.matches(dependency, string_buf)) {
if (id_map[update_id] == invalid_package_id) {
@@ -1019,14 +1019,14 @@ pub const Printer = struct {
);
}
} else {
- outer: for (dependencies_buffer) |dependency, dep_id| {
+ outer: for (dependencies_buffer, 0..) |dependency, dep_id| {
if (dependency.behavior.isPeer()) continue;
const package_id = resolutions_buffer[dep_id];
if (package_id >= end) continue;
const package_name = dependency.name.slice(string_buf);
if (this.updates.len > 0) {
- for (this.updates) |update, update_id| {
+ for (this.updates, 0..) |update, update_id| {
if (update.failed) return;
if (update.matches(dependency, string_buf)) {
if (id_map[update_id] == invalid_package_id) {
@@ -1343,8 +1343,8 @@ pub fn verifyResolutions(this: *Lockfile, local_features: Features, remote_featu
const string_buf = this.buffers.string_bytes.items;
const root_list = resolutions_list[0];
- for (resolutions_list) |list, parent_id| {
- for (list.get(resolutions_buffer)) |package_id, j| {
+ for (resolutions_list, 0..) |list, parent_id| {
+ for (list.get(resolutions_buffer), 0..) |package_id, j| {
if (package_id >= end) {
const failed_dep: Dependency = dependency_lists[parent_id].get(dependencies_buffer)[j];
if (failed_dep.behavior.isPeer() or !failed_dep.behavior.isEnabled(
@@ -1878,7 +1878,7 @@ pub const Package = extern struct {
package_id_mapping[this.meta.id] = new_package.meta.id;
- for (old_dependencies) |dependency, i| {
+ for (old_dependencies, 0..) |dependency, i| {
dependencies[i] = try dependency.clone(
old_string_buf,
*Lockfile.StringBuilder,
@@ -1890,7 +1890,7 @@ pub const Package = extern struct {
cloner.trees_count += @as(u32, @boolToInt(old_resolutions.len > 0));
- for (old_resolutions) |old_resolution, i| {
+ for (old_resolutions, 0..) |old_resolution, i| {
if (old_resolution >= max_package_id) continue;
const mapped = package_id_mapping[old_resolution];
@@ -2065,7 +2065,7 @@ pub const Package = extern struct {
if (comptime Environment.isDebug) std.debug.assert(keys.len == version_strings.len);
- for (keys) |key, i| {
+ for (keys, 0..) |key, i| {
string_builder.count(key.slice(string_buf));
string_builder.count(version_strings[i].slice(string_buf));
}
@@ -2160,7 +2160,7 @@ pub const Package = extern struct {
// If a dependency appears in both "dependencies" and "optionalDependencies", it is considered optional!
if (comptime group.behavior.isOptional()) {
- for (start_dependencies[0 .. total_dependencies_count - dependencies.len]) |dep, j| {
+ for (start_dependencies[0 .. total_dependencies_count - dependencies.len], 0..) |dep, j| {
if (dep.name_hash == key.hash) {
// https://docs.npmjs.com/cli/v8/configuring-npm/package-json#optionaldependencies
// > Entries in optionalDependencies will override entries of the same name in dependencies, so it's usually best to only put in one place.
@@ -2236,13 +2236,13 @@ pub const Package = extern struct {
const to_deps = to.dependencies.get(to_lockfile.buffers.dependencies.items);
const from_deps = from.dependencies.get(from_lockfile.buffers.dependencies.items);
- for (from_deps) |*from_dep, i| {
+ for (from_deps, 0..) |*from_dep, i| {
// common case: dependency is present in both versions and in the same position
const to_i = if (to_deps.len > i and to_deps[i].name_hash == from_dep.name_hash)
i
else brk: {
// less common, o(n^2) case
- for (to_deps) |to_dep, j| {
+ for (to_deps, 0..) |to_dep, j| {
if (from_dep.name_hash == to_dep.name_hash) break :brk j;
}
@@ -2262,7 +2262,7 @@ pub const Package = extern struct {
summary.update += 1;
}
- outer: for (to_deps) |to_dep, i| {
+ outer: for (to_deps, 0..) |to_dep, i| {
if (from_deps.len > i and from_deps[i].name_hash == to_dep.name_hash) continue;
for (from_deps) |from_dep| {
@@ -2421,7 +2421,7 @@ pub const Package = extern struct {
if (entry.found_existing) {
// duplicate dependencies are allowed in optionalDependencies
if (comptime group.behavior.isOptional()) {
- for (package_dependencies[0 .. package_dependencies.len - dependencies.len]) |package_dep, j| {
+ for (package_dependencies[0 .. package_dependencies.len - dependencies.len], 0..) |package_dep, j| {
if (package_dep.name_hash == this_dep.name_hash) {
package_dependencies[j] = this_dep;
break;
@@ -2470,7 +2470,7 @@ pub const Package = extern struct {
const orig_msgs_len = log.msgs.items.len;
- for (arr.slice()) |item, i| {
+ for (arr.slice(), 0..) |item, i| {
defer fallback.fixed_buffer_allocator.reset();
const path = item.asString(allocator) orelse {
log.addErrorFmt(source, item.loc, allocator,
@@ -2962,7 +2962,7 @@ pub const Package = extern struct {
.e_array => |arr| {
if (arr.items.len == 0) break :brk;
- for (arr.slice()) |item, i| {
+ for (arr.slice(), 0..) |item, i| {
const name = workspace_names[i];
defer allocator.free(name);
@@ -3009,7 +3009,7 @@ pub const Package = extern struct {
var arr = packages_q.data.e_array;
if (arr.items.len == 0) break :brk;
- for (arr.slice()) |item, i| {
+ for (arr.slice(), 0..) |item, i| {
const name = workspace_names[i];
defer allocator.free(name);
@@ -3148,7 +3148,7 @@ pub const Package = extern struct {
Type: type,
};
var data: [fields.len]Data = undefined;
- for (fields) |field_info, i| {
+ for (fields, 0..) |field_info, i| {
data[i] = .{
.size = @sizeOf(field_info.type),
.size_index = i,
@@ -3167,7 +3167,7 @@ pub const Package = extern struct {
var sizes_bytes: [fields.len]usize = undefined;
var field_indexes: [fields.len]usize = undefined;
var Types: [fields.len]type = undefined;
- for (data) |elem, i| {
+ for (data, 0..) |elem, i| {
sizes_bytes[i] = elem.size;
field_indexes[i] = elem.size_index;
Types[i] = elem.Type;
@@ -3304,7 +3304,7 @@ const Buffers = struct {
alignment: usize,
};
var data: [fields.len]Data = undefined;
- for (fields) |field_info, i| {
+ for (fields, 0..) |field_info, i| {
data[i] = .{
.size = @sizeOf(field_info.type),
.name = field_info.name,
@@ -3323,7 +3323,7 @@ const Buffers = struct {
var sizes_bytes: [fields.len]usize = undefined;
var names: [fields.len][]const u8 = undefined;
var types: [fields.len]type = undefined;
- for (data) |elem, i| {
+ for (data, 0..) |elem, i| {
sizes_bytes[i] = elem.size;
names[i] = elem.name;
types[i] = elem.type;
@@ -3454,7 +3454,7 @@ const Buffers = struct {
switch (package_id) {
0 => return Tree.root_dep_id,
invalid_package_id => return invalid_package_id,
- else => for (this.resolutions.items) |pkg_id, dep_id| {
+ else => for (this.resolutions.items, 0..) |pkg_id, dep_id| {
if (pkg_id == package_id) return @truncate(DependencyID, dep_id);
},
}
@@ -3465,7 +3465,7 @@ const Buffers = struct {
var this = Buffers{};
var external_dependency_list_: std.ArrayListUnmanaged(Dependency.External) = std.ArrayListUnmanaged(Dependency.External){};
- inline for (sizes.names) |name, i| {
+ inline for (sizes.names, 0..) |name, i| {
const Type = @TypeOf(@field(this, name));
var pos: usize = 0;
@@ -3485,7 +3485,7 @@ const Buffers = struct {
this.trees = try Tree.List.initCapacity(allocator, tree_list.items.len);
this.trees.items.len = tree_list.items.len;
- for (tree_list.items) |tree, j| {
+ for (tree_list.items, 0..) |tree, j| {
this.trees.items[j] = Tree.toTree(tree);
}
} else {
@@ -3619,7 +3619,7 @@ pub const Serializer = struct {
const slice = lockfile.packages.slice();
const name_hashes = slice.items(.name_hash);
const resolutions = slice.items(.resolution);
- for (name_hashes) |name_hash, id| {
+ for (name_hashes, 0..) |name_hash, id| {
try lockfile.getOrPutID(@truncate(PackageID, id), name_hash);
const resolution = resolutions[id];
diff --git a/src/install/npm.zig b/src/install/npm.zig
index 71b892bef..66f9d02cb 100644
--- a/src/install/npm.zig
+++ b/src/install/npm.zig
@@ -229,7 +229,7 @@ const ExternVersionMap = extern struct {
values: PackageVersionList = PackageVersionList{},
pub fn findKeyIndex(this: ExternVersionMap, buf: []const Semver.Version, find: Semver.Version) ?u32 {
- for (this.keys.get(buf)) |key, i| {
+ for (this.keys.get(buf), 0..) |key, i| {
if (key.eql(find)) {
return @truncate(u32, i);
}
@@ -482,7 +482,7 @@ pub const PackageManifest = struct {
alignment: usize,
};
var data: [fields.len]Data = undefined;
- for (fields) |field_info, i| {
+ for (fields, 0..) |field_info, i| {
data[i] = .{
.size = @sizeOf(field_info.type),
.name = field_info.name,
@@ -499,7 +499,7 @@ pub const PackageManifest = struct {
std.sort.sort(Data, &data, &trash, Sort.lessThan);
var sizes_bytes: [fields.len]usize = undefined;
var names: [fields.len][]const u8 = undefined;
- for (data) |elem, i| {
+ for (data, 0..) |elem, i| {
sizes_bytes[i] = elem.size;
names[i] = elem.name;
}
@@ -717,7 +717,7 @@ pub const PackageManifest = struct {
pub fn findByDistTag(this: *const PackageManifest, tag: string) ?FindResult {
const versions = this.pkg.dist_tags.versions.get(this.versions);
- for (this.pkg.dist_tags.tags.get(this.external_strings)) |tag_str, i| {
+ for (this.pkg.dist_tags.tags.get(this.external_strings), 0..) |tag_str, i| {
if (strings.eql(tag_str.slice(this.string_buf), tag)) {
return this.findByVersion(versions[i]);
}