镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Commit 2b46afb

Browse files
committed
feat(vm): forward interleaved direct-eval environments (#785)
Add a precise Environment forwarding record that owns only a replacement parent edge while every own-binding query, read, write, tag, alias, and deletion targets the original live declarative or object record. No binding values or hash tables are copied, and published parent links remain immutable. Route identifier resolution, captured References, with bindings, lexical-conflict checks, and variable-scope selection through the original record. Quick VM binding caches reject forwarding chains and retain the ordinary exact VM path. Trace and relocate the target edge, clear it before Environment reuse, and preserve target lock ownership under no-GIL execution. Validation: Environment clusters pass 13/13 normally and 13/13 under TSan; focused forwarding witnesses pass 2/2 in both modes, with zero failures, leaks, or sanitizer reports. Test262 flips: 0 because compiler admission of interleaved boundaries remains fail-closed. Advances #771 and #785.
1 parent 87ee7e7 commit 2b46afb

3 files changed

Lines changed: 237 additions & 88 deletions

File tree

‎src/gc.zig‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,7 @@ pub fn traceEnv(e: *Environment, v: anytype) void {
11461146
for (activation.bindings) |binding|
11471147
markValueInternal(v, "direct-eval VM activation binding", activation.frame.read(binding.slot));
11481148
}
1149+
if (e.direct_eval_forward_target) |target| markManaged(v, target);
11491150
var vit = e.vars.iterator();
11501151
while (vit.next()) |entry| markValueVariable(v, entry.key_ptr.*, entry.value_ptr.*);
11511152
for (e.disposables.items) |d| {
@@ -1172,6 +1173,7 @@ pub fn relocateEnv(e: *Environment, v: anytype) void {
11721173
gc_relocation.rewriteValueSlot(v, &activation.frame.slots[binding.slot]);
11731174
}
11741175
}
1176+
gc_relocation.rewriteOptionalSlot(v, Environment, &e.direct_eval_forward_target);
11751177
var values = e.vars.valueIterator();
11761178
while (values.next()) |slot| gc_relocation.rewriteValueSlot(v, slot);
11771179
for (e.disposables.items) |*disposable| {
@@ -1201,6 +1203,7 @@ test "Environment relocation rewrites every managed binding slot" {
12011203
var environment = Environment{
12021204
.arena = std.testing.allocator,
12031205
.gc_managed = true,
1206+
.direct_eval_forward_target = &old_environments[1],
12041207
.dispose_pending = Value.obj(&old_objects[3]),
12051208
.object_proto_intrinsic = &old_objects[4],
12061209
.parent = &old_environments[0],
@@ -1250,6 +1253,7 @@ test "Environment relocation rewrites every managed binding slot" {
12501253
try std.testing.expect(environment.disposables.items[0].is_async);
12511254
try std.testing.expectEqual(&new_objects[3], environment.dispose_pending.?.asObj());
12521255
try std.testing.expectEqual(&new_objects[4], environment.object_proto_intrinsic.?);
1256+
try std.testing.expectEqual(&new_environments[1], environment.direct_eval_forward_target.?);
12531257
try std.testing.expectEqual(&new_environments[0], environment.parent.?);
12541258
const alias = environment.aliases.get("imported").?;
12551259
try std.testing.expectEqual(&new_environments[1], alias.env);

0 commit comments

Comments
 (0)