authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-01-25 17:59:48+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-25 22:20:34-08:00
logbea958df4d0c5fc38633f09b6490c16e24a03155
tree2820c9d4c87ff84baffa232d7a00a72949786f62
parentce58f68903f13a90f3bb2a566755e4c74b56ecdf

Compilation: preserve "builtin" as the first dependency

Previously, sorting dependencies would reorder the builtin dependency and cause `Package.Module.getBuiltinDependency` to stop working.

1 files changed, 11 insertions(+), 5 deletions(-)

src/Compilation.zig+11-5
...@@ -1143,12 +1143,14 @@ fn addModuleTableToCacheHash(...@@ -1143,12 +1143,14 @@ fn addModuleTableToCacheHash(
1143 try seen_table.put(gpa, main_mod, {});1143 try seen_table.put(gpa, main_mod, {});
11441144
1145 const SortByName = struct {1145 const SortByName = struct {
1146 has_builtin: bool,
1146 names: []const []const u8,1147 names: []const []const u8,
11471148
1148 pub fn lessThan(ctx: @This(), lhs_index: usize, rhs_index: usize) bool {1149 pub fn lessThan(ctx: @This(), lhs: usize, rhs: usize) bool {
1149 const lhs_key = ctx.names[lhs_index];1150 return if (ctx.has_builtin and (lhs == 0 or rhs == 0))
1150 const rhs_key = ctx.names[rhs_index];1151 lhs < rhs
1151 return mem.lessThan(u8, lhs_key, rhs_key);1152 else
1153 mem.lessThan(u8, ctx.names[lhs], ctx.names[rhs]);
1152 }1154 }
1153 };1155 };
11541156
...@@ -1175,7 +1177,11 @@ fn addModuleTableToCacheHash(...@@ -1175,7 +1177,11 @@ fn addModuleTableToCacheHash(
1175 },1177 },
1176 }1178 }
11771179
1178 mod.deps.sortUnstable(SortByName{ .names = mod.deps.keys() });1180 mod.deps.sortUnstable(SortByName{
1181 .has_builtin = mod.deps.count() >= 1 and
1182 mod.deps.values()[0].isBuiltin(),
1183 .names = mod.deps.keys(),
1184 });
11791185
1180 hash.addListOfBytes(mod.deps.keys());1186 hash.addListOfBytes(mod.deps.keys());
11811187