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

Fix zig build lazy -> eager promotion while fetching dependencies. #23172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 28 additions & 18 deletions src/Package/Fetch.zig
Original file line number Diff line number Diff line change
Expand Up @@ -707,46 +707,56 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {
// calling run(); no need to add it again.
//
// If we add a dep as lazy and then later try to add the same dep as eager,
// eagerness takes precedence and the existing entry is updated.
// eagerness takes precedence and the existing entry is updated and re-scheduled
// for fetching.

for (dep_names, deps) |dep_name, dep| {
var promoted_existing_to_eager = false;
const new_fetch = &new_fetches[new_fetch_index];
const location: Location = switch (dep.location) {
.url => |url| .{ .remote = .{
.url = url,
.hash = h: {
const h = dep.hash orelse break :h null;
const pkg_hash: Package.Hash = .fromSlice(h);
const gop = f.job_queue.table.getOrPutAssumeCapacity(pkg_hash);
if (gop.found_existing) {
if (!dep.lazy) {
gop.value_ptr.*.lazy_status = .eager;
.url => |url| .{
.remote = .{
.url = url,
.hash = h: {
const h = dep.hash orelse break :h null;
const pkg_hash: Package.Hash = .fromSlice(h);
const gop = f.job_queue.table.getOrPutAssumeCapacity(pkg_hash);
if (gop.found_existing) {
if (!dep.lazy and gop.value_ptr.*.lazy_status != .eager) {
gop.value_ptr.*.lazy_status = .eager;
promoted_existing_to_eager = true;
} else {
continue;
}
}
continue;
}
gop.value_ptr.* = new_fetch;
break :h pkg_hash;
gop.value_ptr.* = new_fetch;
break :h pkg_hash;
},
},
} },
},
.path => |rel_path| l: {
// This might produce an invalid path, which is checked for
// at the beginning of run().
const new_root = try f.package_root.resolvePosix(parent_arena, rel_path);
const pkg_hash = relativePathDigest(new_root, cache_root);
const gop = f.job_queue.table.getOrPutAssumeCapacity(pkg_hash);
if (gop.found_existing) {
if (!dep.lazy) {
if (!dep.lazy and gop.value_ptr.*.lazy_status != .eager) {
gop.value_ptr.*.lazy_status = .eager;
promoted_existing_to_eager = true;
} else {
continue;
}
continue;
}
gop.value_ptr.* = new_fetch;
break :l .{ .relative_path = new_root };
},
};
prog_names[new_fetch_index] = dep_name;
new_fetch_index += 1;
f.job_queue.all_fetches.appendAssumeCapacity(new_fetch);
if (!promoted_existing_to_eager) {
f.job_queue.all_fetches.appendAssumeCapacity(new_fetch);
}
new_fetch.* = .{
.arena = std.heap.ArenaAllocator.init(gpa),
.location = location,
Expand Down
Loading