@@ -1564,6 +1564,7 @@ fn traceCapturedFrame(raw: ?*anyopaque, v: anytype) void {
15641564 var frame : ? * vm.Frame = if (raw ) | pointer | @ptrCast (@alignCast (pointer )) else null ;
15651565 const lock_slots = if (comptime @hasDecl (@TypeOf (v .* ), "concurrent" )) v .concurrent () else false ;
15661566 while (frame ) | current | : (frame = current .parent ) {
1567+ if (current .closure_environment ) | environment | markManaged (v , environment );
15671568 if (current .direct_eval_environment .load (.acquire )) | environment | markManaged (v , environment );
15681569 if (current .direct_eval_parameter_environment .load (.acquire )) | environment | markManaged (v , environment );
15691570 traceFrameMappedParameters (current , v );
@@ -1578,6 +1579,7 @@ fn traceCapturedFrame(raw: ?*anyopaque, v: anytype) void {
15781579fn relocateCapturedFrame (raw : ? * anyopaque , v : anytype ) void {
15791580 var frame : ? * vm.Frame = if (raw ) | pointer | @ptrCast (@alignCast (pointer )) else null ;
15801581 while (frame ) | current | : (frame = current .parent ) {
1582+ gc_relocation .rewriteOptionalSlot (v , Environment , & current .closure_environment );
15811583 gc_relocation .rewriteAtomicOptionalSlot (v , Environment , & current .direct_eval_environment );
15821584 gc_relocation .rewriteAtomicOptionalSlot (v , Environment , & current .direct_eval_parameter_environment );
15831585 relocateFrameMappedParameters (current , v );
@@ -1684,7 +1686,11 @@ test "Function marking and relocation cover every managed field" {
16841686 var parent_frame_slots = [_ ]Value {Value .obj (& old_objects [13 ])};
16851687 var parent_frame = vm.Frame { .slots = & parent_frame_slots , .parent = null };
16861688 var captured_frame_slots = [_ ]Value {Value .obj (& old_objects [14 ])};
1687- var captured_frame = vm.Frame { .slots = & captured_frame_slots , .parent = & parent_frame };
1689+ var captured_frame = vm.Frame {
1690+ .slots = & captured_frame_slots ,
1691+ .parent = & parent_frame ,
1692+ .closure_environment = & old_environment ,
1693+ };
16881694 var function = interp.Function {
16891695 .params = &.{},
16901696 .body = & body ,
@@ -1766,6 +1772,7 @@ test "Function marking and relocation cover every managed field" {
17661772 try std .testing .expectEqual (& new_objects [12 ], async_constants [0 ].asObj ());
17671773 try std .testing .expectEqual (& new_objects [13 ], parent_frame_slots [0 ].asObj ());
17681774 try std .testing .expectEqual (& new_objects [14 ], captured_frame_slots [0 ].asObj ());
1775+ try std .testing .expectEqual (& new_environment , captured_frame .closure_environment .? );
17691776 try std .testing .expect (Binding .traceOldOnMinor (.function ));
17701777}
17711778
@@ -2001,6 +2008,7 @@ pub fn traceGenerator(g: *vm.Generator, v: anytype) void {
20012008 if (handler .environment ) | environment | markManaged (v , environment );
20022009 var frame = g .exec .frame ;
20032010 while (frame ) | current | : (frame = current .parent ) {
2011+ if (current .closure_environment ) | environment | markManaged (v , environment );
20042012 if (current .direct_eval_environment .load (.acquire )) | environment | markManaged (v , environment );
20052013 if (current .direct_eval_parameter_environment .load (.acquire )) | environment | markManaged (v , environment );
20062014 for (current .slots ) | slot | markValue (v , slot );
@@ -2033,6 +2041,7 @@ pub fn relocateGenerator(g: *vm.Generator, v: anytype) void {
20332041 gc_relocation .rewriteOptionalSlot (v , interp .Environment , & handler .environment );
20342042 var frame = g .exec .frame ;
20352043 while (frame ) | current | : (frame = current .parent ) {
2044+ gc_relocation .rewriteOptionalSlot (v , Environment , & current .closure_environment );
20362045 gc_relocation .rewriteAtomicOptionalSlot (v , Environment , & current .direct_eval_environment );
20372046 gc_relocation .rewriteAtomicOptionalSlot (v , Environment , & current .direct_eval_parameter_environment );
20382047 for (current .slots ) | * slot | gc_relocation .rewriteValueSlot (v , slot );
@@ -2113,7 +2122,11 @@ test "Generator and IteratorHelper marking and relocation cover every managed sl
21132122 var parent_frame_slots = [_ ]Value {Value .obj (& old_objects [3 ])};
21142123 var child_frame_slots = [_ ]Value {Value .obj (& old_objects [4 ])};
21152124 var parent_frame = vm.Frame { .slots = & parent_frame_slots , .parent = null };
2116- var child_frame = vm.Frame { .slots = & child_frame_slots , .parent = & parent_frame };
2125+ var child_frame = vm.Frame {
2126+ .slots = & child_frame_slots ,
2127+ .parent = & parent_frame ,
2128+ .closure_environment = & old_environment ,
2129+ };
21172130 var handlers = [_ ]vm.Handler {.{
21182131 .catch_pc = 1 ,
21192132 .stack_depth = 0 ,
@@ -2209,6 +2222,7 @@ test "Generator and IteratorHelper marking and relocation cover every managed sl
22092222 try std .testing .expectEqual (& new_objects [2 ], generator .exec .acc .asObj ());
22102223 try std .testing .expectEqual (& new_objects [3 ], parent_frame_slots [0 ].asObj ());
22112224 try std .testing .expectEqual (& new_objects [4 ], child_frame_slots [0 ].asObj ());
2225+ try std .testing .expectEqual (& new_environment , child_frame .closure_environment .? );
22122226 try std .testing .expectEqual (& new_objects [5 ], generator .this_value .asObj ());
22132227 try std .testing .expectEqual (& new_objects [6 ], generator .home_object .? );
22142228 try std .testing .expectEqual (& new_objects [7 ], generator .super_ctor .? );
@@ -2553,6 +2567,7 @@ pub fn traceInterpreterRoots(machine: *interp.Interpreter, v: anytype) void {
25532567 const lock_slots = v .concurrent ();
25542568 var fr : ? * vm.Frame = exec .frame ;
25552569 while (fr ) | f | : (fr = f .parent ) {
2570+ if (f .closure_environment ) | environment | markManaged (v , environment );
25562571 if (f .direct_eval_environment .load (.acquire )) | environment | markManaged (v , environment );
25572572 if (f .direct_eval_parameter_environment .load (.acquire )) | environment | markManaged (v , environment );
25582573 traceFrameMappedParameters (f , v );
@@ -2674,6 +2689,7 @@ pub fn relocateInterpreterRoots(machine: *interp.Interpreter, v: anytype) void {
26742689 gc_relocation .rewriteOptionalSlot (v , Object , & exec .saved_super_ctor );
26752690 var frame = exec .frame ;
26762691 while (frame ) | current | : (frame = current .parent ) {
2692+ gc_relocation .rewriteOptionalSlot (v , Environment , & current .closure_environment );
26772693 gc_relocation .rewriteAtomicOptionalSlot (v , Environment , & current .direct_eval_environment );
26782694 gc_relocation .rewriteAtomicOptionalSlot (v , Environment , & current .direct_eval_parameter_environment );
26792695 relocateFrameMappedParameters (current , v );
@@ -2790,7 +2806,11 @@ test "realm root relocation rewrites active interpreter containers" {
27902806 var operand_stack = [_ ]Value { Value .obj (& old_objects [16 ]), Value .obj (& old_objects [17 ]) };
27912807 var pending_rest_arguments = [_ ]Value {Value .obj (& old_objects [27 ])};
27922808 var frame_slots = [_ ]Value {Value .obj (& old_objects [19 ])};
2793- var frame = vm.Frame { .slots = & frame_slots , .parent = null };
2809+ var frame = vm.Frame {
2810+ .slots = & frame_slots ,
2811+ .parent = null ,
2812+ .closure_environment = & old_environment ,
2813+ };
27942814 frame .direct_eval_environment .store (& old_environment , .release );
27952815 frame .direct_eval_parameter_environment .store (& old_environment , .release );
27962816 var execution = vm.Exec {
@@ -2899,6 +2919,7 @@ test "realm root relocation rewrites active interpreter containers" {
28992919 try std .testing .expectEqual (& new_objects [18 ], execution .acc .asObj ());
29002920 try std .testing .expectEqual (& new_objects [27 ], pending_rest_arguments [0 ].asObj ());
29012921 try std .testing .expectEqual (& new_objects [19 ], frame_slots [0 ].asObj ());
2922+ try std .testing .expectEqual (& new_environment , frame .closure_environment .? );
29022923 try std .testing .expectEqual (& new_environment , frame .direct_eval_environment .load (.acquire ).? );
29032924 try std .testing .expectEqual (& new_environment , frame .direct_eval_parameter_environment .load (.acquire ).? );
29042925 try std .testing .expectEqual (& new_objects [25 ], execution .saved_home_object .? );
0 commit comments