From e0fdbfb705d1c8184eb3664e1d540f90031f7dd5 Mon Sep 17 00:00:00 2001 From: Jonathan Marler Date: Fri, 27 Sep 2024 09:44:44 -0600 Subject: [PATCH] build: make dependency cache hash map unmanaged Allows Build.Graph to initialize dependency_cache with a default value. --- lib/compiler/build_runner.zig | 1 - lib/std/Build.zig | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/compiler/build_runner.zig b/lib/compiler/build_runner.zig index f29b9e6c42..4d643222d7 100644 --- a/lib/compiler/build_runner.zig +++ b/lib/compiler/build_runner.zig @@ -80,7 +80,6 @@ pub fn main() !void { .query = .{}, .result = try std.zig.system.resolveTargetQuery(.{}), }, - .dependency_cache = std.Build.InitializedDepMap.initContext(arena, .{ .allocator = arena }), }; graph.cache.addPrefix(.{ .path = null, .handle = std.fs.cwd() }); diff --git a/lib/std/Build.zig b/lib/std/Build.zig index fd734dd617..963ca709bf 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -122,7 +122,7 @@ pub const Graph = struct { host: ResolvedTarget, incremental: ?bool = null, random_seed: u32 = 0, - dependency_cache: InitializedDepMap, + dependency_cache: InitializedDepMap = .empty, }; const AvailableDeps = []const struct { []const u8, []const u8 }; @@ -142,7 +142,7 @@ const SystemLibraryMode = enum { declared_enabled, }; -pub const InitializedDepMap = std.HashMap(InitializedDepKey, *Dependency, InitializedDepContext, std.hash_map.default_max_load_percentage); +const InitializedDepMap = std.HashMapUnmanaged(InitializedDepKey, *Dependency, InitializedDepContext, std.hash_map.default_max_load_percentage); const InitializedDepKey = struct { build_root_string: []const u8, user_input_options: UserInputOptionsMap, @@ -2121,10 +2121,10 @@ fn dependencyInner( args: anytype, ) *Dependency { const user_input_options = userInputOptionsFromArgs(b.allocator, args); - if (b.graph.dependency_cache.get(.{ + if (b.graph.dependency_cache.getContext(.{ .build_root_string = build_root_string, .user_input_options = user_input_options, - })) |dep| + }, .{ .allocator = b.graph.arena })) |dep| return dep; const build_root: std.Build.Cache.Directory = .{ @@ -2149,10 +2149,10 @@ fn dependencyInner( const dep = b.allocator.create(Dependency) catch @panic("OOM"); dep.* = .{ .builder = sub_builder }; - b.graph.dependency_cache.put(.{ + b.graph.dependency_cache.putContext(b.graph.arena, .{ .build_root_string = build_root_string, .user_input_options = user_input_options, - }, dep) catch @panic("OOM"); + }, dep, .{ .allocator = b.graph.arena }) catch @panic("OOM"); return dep; }