@@ -416,8 +416,8 @@ pub fn main() !void {
416416 .skip_oom_steps = skip_oom_steps ,
417417 .watch = watch ,
418418 .web_server = undefined , // set after `prepare`
419- .memory_blocked_steps = std . ArrayList ( * Step ). init ( arena ) ,
420- .step_stack = .{} ,
419+ .memory_blocked_steps = .empty ,
420+ .step_stack = .empty ,
421421 .prominent_compile_errors = prominent_compile_errors ,
422422
423423 .claimed_rss = 0 ,
@@ -426,6 +426,10 @@ pub fn main() !void {
426426 .stderr = stderr ,
427427 .thread_pool = undefined ,
428428 };
429+ defer {
430+ run .memory_blocked_steps .deinit (gpa );
431+ run .step_stack .deinit (gpa );
432+ }
429433
430434 if (run .max_rss == 0 ) {
431435 run .max_rss = process .totalSystemMemory () catch std .math .maxInt (u64 );
@@ -557,7 +561,9 @@ const Run = struct {
557561 skip_oom_steps : bool ,
558562 watch : bool ,
559563 web_server : ? WebServer ,
560- memory_blocked_steps : std .ArrayList (* Step ),
564+ /// Allocated into `gpa`.
565+ memory_blocked_steps : std .ArrayListUnmanaged (* Step ),
566+ /// Allocated into `gpa`.
561567 step_stack : std .AutoArrayHashMapUnmanaged (* Step , void ),
562568 prominent_compile_errors : bool ,
563569 thread_pool : std.Thread.Pool ,
@@ -604,7 +610,7 @@ fn prepare(
604610 rand .shuffle (* Step , starting_steps );
605611
606612 for (starting_steps ) | s | {
607- constructGraphAndCheckForDependencyLoop (b , s , & run .step_stack , rand ) catch | err | switch (err ) {
613+ constructGraphAndCheckForDependencyLoop (gpa , b , s , & run .step_stack , rand ) catch | err | switch (err ) {
608614 error .DependencyLoopDetected = > return uncleanExit (),
609615 else = > | e | return e ,
610616 };
@@ -1044,6 +1050,7 @@ fn printTreeStep(
10441050/// when it finishes executing in `workerMakeOneStep`, it spawns next steps
10451051/// to run in random order
10461052fn constructGraphAndCheckForDependencyLoop (
1053+ gpa : Allocator ,
10471054 b : * std.Build ,
10481055 s : * Step ,
10491056 step_stack : * std .AutoArrayHashMapUnmanaged (* Step , void ),
@@ -1057,17 +1064,19 @@ fn constructGraphAndCheckForDependencyLoop(
10571064 .precheck_unstarted = > {
10581065 s .state = .precheck_started ;
10591066
1060- try step_stack .ensureUnusedCapacity (b . allocator , s .dependencies .items .len );
1067+ try step_stack .ensureUnusedCapacity (gpa , s .dependencies .items .len );
10611068
10621069 // We dupe to avoid shuffling the steps in the summary, it depends
10631070 // on s.dependencies' order.
1064- const deps = b .allocator .dupe (* Step , s .dependencies .items ) catch @panic ("OOM" );
1071+ const deps = gpa .dupe (* Step , s .dependencies .items ) catch @panic ("OOM" );
1072+ defer gpa .free (deps );
1073+
10651074 rand .shuffle (* Step , deps );
10661075
10671076 for (deps ) | dep | {
1068- try step_stack .put (b . allocator , dep , {});
1077+ try step_stack .put (gpa , dep , {});
10691078 try dep .dependants .append (b .allocator , s );
1070- constructGraphAndCheckForDependencyLoop (b , dep , step_stack , rand ) catch | err | {
1079+ constructGraphAndCheckForDependencyLoop (gpa , b , dep , step_stack , rand ) catch | err | {
10711080 if (err == error .DependencyLoopDetected ) {
10721081 std .debug .print (" {s}\n " , .{s .name });
10731082 }
@@ -1132,7 +1141,7 @@ fn workerMakeOneStep(
11321141 if (new_claimed_rss > run .max_rss ) {
11331142 // Running this step right now could possibly exceed the allotted RSS.
11341143 // Add this step to the queue of memory-blocked steps.
1135- run .memory_blocked_steps .append (s ) catch @panic ("OOM" );
1144+ run .memory_blocked_steps .append (run . gpa , s ) catch @panic ("OOM" );
11361145 return ;
11371146 }
11381147
@@ -1285,10 +1294,10 @@ pub fn printErrorMessages(
12851294}
12861295
12871296fn printSteps (builder : * std.Build , w : * Writer ) ! void {
1288- const allocator = builder .allocator ;
1297+ const arena = builder .graph . arena ;
12891298 for (builder .top_level_steps .values ()) | top_level_step | {
12901299 const name = if (& top_level_step .step == builder .default_step )
1291- try fmt .allocPrint (allocator , "{s} (default)" , .{top_level_step .step .name })
1300+ try fmt .allocPrint (arena , "{s} (default)" , .{top_level_step .step .name })
12921301 else
12931302 top_level_step .step .name ;
12941303 try w .print (" {s:<28} {s}\n " , .{ name , top_level_step .description });
@@ -1361,7 +1370,7 @@ fn printUsage(b: *std.Build, w: *Writer) !void {
13611370 \\
13621371 );
13631372
1364- const arena = b .allocator ;
1373+ const arena = b .graph . arena ;
13651374 if (b .available_options_list .items .len == 0 ) {
13661375 try w .print (" (none)\n " , .{});
13671376 } else {
0 commit comments