diff --git a/docs/design/open-questions.md b/docs/design/open-questions.md index 9458b96..2a53193 100644 --- a/docs/design/open-questions.md +++ b/docs/design/open-questions.md @@ -476,3 +476,5 @@ The [audit-report increment](air-type-depth-audit.md#audit-report-traversal) fix The [executed runtime audit](runtime-value-depth-audit.md) confirms that a verified one-byte value with 32,768 length-one nested arrays aborts inside zeroValue under `aji run --fuel 8`, rather than producing a run record. The instruction has not exhausted fuel. Iterative runtime traversal must preserve initialization, value shape, allocator/root lifetimes, collection safety and instruction accounting; adding a depth trap/acceptance limit needs a normative decision. At that baseline, recursive copying, value sizing, collection and serialization were additional audit candidates with unverified failure paths; the increment below records subsequent executed failures. Compiler type repairs in Q-059 do not resolve Q-060. The [zero-materialization increment](runtime-value-depth-audit.md#zero-materialization-repair) removes recursion from zeroValue while preserving payload shape/order, whole-local publication and instruction accounting. Deep unit tests cover 32,768 anonymous/nominal levels and pending siblings; the original run now returns normally. Follow-up probes independently verify native-stack failures in deepCopy/copyAll on local.load and Copier.value/items with collection before every instruction. Those are remaining Q-060 work, not a new acceptance limit; value sizing and output serialization remain audit candidates. + +The [storage/value-copy increment](runtime-value-depth-audit.md#storagevalue-copy-repair) removes recursion from deepCopy/copyAll while retaining per-occurrence payload independence, aggregate identities, shallow handles and failure publication rules. The previous 32,768-level local.load run now returns normally. An added local.store forces ordinary-threshold collection and independently confirms the remaining Copier.value/items native-stack failure, without collect-every-step instrumentation. Sharing-preserving collection/result copying, accounted-value queries and output serialization remain open; no accepted-depth or trap limit is introduced. diff --git a/docs/design/runtime-value-depth-audit.md b/docs/design/runtime-value-depth-audit.md index add9121..e792cfa 100644 --- a/docs/design/runtime-value-depth-audit.md +++ b/docs/design/runtime-value-depth-audit.md @@ -39,3 +39,13 @@ The original 32,768-level input now returns `{"status":"returned","value":null}` - Adding `%v = local.load %a` immediately after zeroing aborts without JSON inside deepCopy/copyAll (4,998 frames each), under the same fuel 8. Storage-to-SSA copying still requires its own iterative traversal. Both probes retain the ordinary native stack limit and disable only child core capture, with no wall-clock termination. Evidence comes from the runner exit status and Zig's symbolized stderr, not a saved core dump. Q-060 stays open for copying, sharing-preserving collection/result copying, accounted-value queries and output serialization. + +## Storage/value-copy repair + +DeepCopy now visits aggregate/array payloads in the original preorder using explicit pending-sibling continuations. CopyAll keeps its root-list order and invokes that traversal for each root. Every occurrence gets a fresh payload, even when the input reuses one payload more than once. Aggregate declaration/variant identity and scalar bits/types are preserved; owner, mutex, graph and other identity leaves remain shallow, just as before. This is distinct from the collector, which must preserve sharing. Temporary traversal storage is released before the next instruction safe point; allocation failure does not publish a partial local.store value. + +The invariant is unchanged storage/SSA value independence, alongside unchanged ownership identity and explicit loan rules. Spec 07a's local.store/local.load/load/store rules and spec 08's type/initialization/borrow checks are unchanged. The mixed Copy-record/enum/array AIR/source pair copies into and out of local storage, changes one repeated row without affecting the other, restores from a snapshot, and checks that a later store does not mutate the snapshot. Existing read_uninitialized and copy_overlapping AIR cases remain rejected with E1010/E2101; there is no new rejection or diagnostic code. Aji authority/effects, deterministic instruction/fuel counts, accepted syntax/types and runtime traps remain unchanged. No new limit or bundle text is introduced. + +Unit tests copy 32,768 alternating array/aggregate levels with pending siblings, empty payloads, variant identities and signed integer bits. They mutate one of two complete copies, independently test reused source payloads within one value, preserve explicit owner/mutex/graph identities, and force a mid-copy payload allocation failure while retaining complete old local storage. A verified deep programme pins exact fuel 0–4 boundaries: local.load still consumes one instruction. Forty-two mixed-type old/new runs have identical records. + +The previously crashing 32,768-level zero/local.load/ret programme now returns normally under fuel 8 at the ordinary collection threshold. Adding local.store back to the same local forces an ordinary threshold collection and aborts without JSON in Copier.value/items (4,997/4,998 symbolized frames, zero deepCopy frames). This confirms the next failure without collection instrumentation. The collector/result copier, accounted-value queries and output serialization remain Q-060 work. diff --git a/docs/plan/phase-6-source-language.md b/docs/plan/phase-6-source-language.md index 188172a..eefb7ec 100644 --- a/docs/plan/phase-6-source-language.md +++ b/docs/plan/phase-6-source-language.md @@ -410,3 +410,9 @@ Old/new comparison of 1,410 pre-existing source files preserves every diagnostic The [Q-060 zero-materialization increment](../design/runtime-value-depth-audit.md#zero-materialization-repair) fills zeroable values iteratively, retaining field/element order, declaration identities, independent payloads, whole-local publication, allocator errors and fuel/scheduling. Unit cases cover 32,768 array/nominal levels with pending siblings and an allocation failure; a mixed AIR/source run pair checks initialization and subsequent writes. The original fuel-8 probe now returns normally and forty shallow mixed-type old/new records are identical. Follow-up probes independently confirm recursive local-load copying and sharing-preserving collection failures. Q-060 and Phase 6 remain open; no normative/bundle/feature/code change or new depth limit. No fresh Claude review was available. Validation: all units/format checks, test-extended and 1,785/1,785 conformance cases pass; both new mixed-type cases also pass with collection before every instruction. A verified 32,768-level unit probe pins exact fuel 0–3 boundaries and instruction counts. Source/AIR semantics and bundle size are unchanged; the separate deep collector/copy failures are retained in Q-060. + +## P6-1 runtime storage/value copying (2026-10-09) + +The [Q-060 storage/value-copy increment](../design/runtime-value-depth-audit.md#storagevalue-copy-repair) replaces recursive aggregate/array copying with pending-sibling continuations. Every source payload occurrence remains independently copied; scalar/variant/declaration facts, identity handles, allocator errors and instruction/fuel counts remain unchanged. Deep unit cases cover 32,768 alternating levels, siblings/empty fields, duplicate payloads, identity leaves and failed local.store publication. A mixed Copy-record/enum/array AIR/source pair and 42 exact old/new run comparisons cover observable copying. The prior deep local.load probe now returns, while an added local.store independently reaches the remaining collector failure under its ordinary threshold. Units/format checks, test-extended and all 1,787 conformance cases pass. No normative/bundle/feature/code change or new depth limit; Q-060 and Phase 6 remain open. No fresh Claude review was available. + +Both new copy cases also pass with collection before every instruction; their shallow sharing-preserving GC behavior is covered separately from the retained deep collector failure. diff --git a/src/interp/machine.zig b/src/interp/machine.zig index 8bdc1b5..f29ee21 100644 --- a/src/interp/machine.zig +++ b/src/interp/machine.zig @@ -1500,12 +1500,45 @@ const Machine = struct { /// Values in storage never share structure with SSA values, so every /// transfer between the two copies aggregates and arrays. - fn deepCopy(m: *Machine, v: Value) std.mem.Allocator.Error!Value { - return switch (v) { - .aggregate => |a| .{ .aggregate = .{ .decl = a.decl, .variant = a.variant, .fields = try m.copyAll(a.fields) } }, - .array => |items| .{ .array = try m.copyAll(items) }, - else => v, - }; + fn deepCopy(m: *Machine, initial: Value) std.mem.Allocator.Error!Value { + // Every occurrence gets independent aggregate/array storage, even + // when source payloads are shared. Handles and places retain identity. + // Collection cannot run inside an instruction; all source pointers + // remain valid while the new value is built in the execution heap. + const CopyFrame = struct { source: []const Value, out: []Value, next: usize }; + var tmp: std.heap.ArenaAllocator = .init(std.heap.page_allocator); + defer tmp.deinit(); + var frames: std.ArrayList(CopyFrame) = .empty; + var result: Value = undefined; + var out = &result; + var value = initial; + while (true) { + const source: ?[]const Value = switch (value) { + .aggregate => |a| a.fields, + .array => |items| items, + else => null, + }; + if (source) |items| { + const copied = try m.heap().alloc(Value, items.len); + out.* = switch (value) { + .aggregate => |a| .{ .aggregate = .{ .decl = a.decl, .variant = a.variant, .fields = copied } }, + .array => .{ .array = copied }, + else => unreachable, + }; + if (items.len != 0) { + if (items.len > 1) try frames.append(tmp.allocator(), .{ .source = items, .out = copied, .next = 1 }); + value = items[0]; + out = &copied[0]; + continue; + } + } else out.* = value; + if (frames.items.len == 0) return result; + const f = &frames.items[frames.items.len - 1]; + value = f.source[f.next]; + out = &f.out[f.next]; + f.next += 1; + if (f.next == f.out.len) _ = frames.pop(); + } } fn copyAll(m: *Machine, items: []const Value) std.mem.Allocator.Error![]Value { @@ -2567,6 +2600,111 @@ fn expectRunFuel(src: []const u8, expected: []const u8, fuel: ?u64) !void { const h = "module t\nair 0\nlang 0.1\nfeatures []\n"; +test "deep copying preserves metadata and separates every payload occurrence" { + var arena_state: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena_state.deinit(); + const arena = arena_state.allocator(); + const module: air.Module = .{ .name = "copy", .format_version = 0, .lang = .{ 0, 1 }, .features = &.{}, .types = &.{}, .functions = &.{} }; + var m: Machine = .{ .arena = arena, .module = module, .fuel = null, .world = try .init(arena, .{}) }; + m.exec_heap.space = .init(std.testing.allocator); + defer m.exec_heap.space.deinit(); + const depth = 32768; + var root: Value = .{ .int = .{ .ty = .i16, .bits = 0xfffa } }; + for (1..depth + 1) |i| { + const fields = try m.heap().alloc(Value, if (i % 2 == 0) 1 else 3); + fields[0] = root; + if (fields.len == 1) { + root = .{ .array = fields }; + } else { + fields[1] = .{ .boolean = true }; + fields[2] = .{ .aggregate = .{ .decl = 0, .variant = 0, .fields = &.{} } }; + root = .{ .aggregate = .{ .decl = @intCast(i), .variant = @intCast(i % 3), .fields = fields } }; + } + } + const copies = try m.copyAll(&.{ root, root }); + for (copies) |copy| { + var original = root; + var copied = copy; + var i: usize = depth; + while (i != 0) : (i -= 1) { + if (i % 2 == 0) { + try std.testing.expect(original.array.ptr != copied.array.ptr); + try std.testing.expectEqual(@as(usize, 1), copied.array.len); + original = original.array[0]; + copied = copied.array[0]; + } else { + try std.testing.expect(original.aggregate.fields.ptr != copied.aggregate.fields.ptr); + try std.testing.expectEqual(original.aggregate.decl, copied.aggregate.decl); + try std.testing.expectEqual(original.aggregate.variant, copied.aggregate.variant); + try std.testing.expectEqual(@as(usize, 3), copied.aggregate.fields.len); + try std.testing.expect(copied.aggregate.fields[1].boolean); + const empty = copied.aggregate.fields[2].aggregate; + try std.testing.expect(empty.decl == 0 and empty.variant == 0 and empty.fields.len == 0); + original = original.aggregate.fields[0]; + copied = copied.aggregate.fields[0]; + } + } + try std.testing.expect(copied.int.ty == .i16 and copied.int.bits == 0xfffa); + } + var leaf0 = &copies[0]; + var leaf1 = &copies[1]; + var source_leaf = &root; + for (0..depth) |_| { + leaf0 = if (leaf0.* == .array) &leaf0.array[0] else &leaf0.aggregate.fields[0]; + leaf1 = if (leaf1.* == .array) &leaf1.array[0] else &leaf1.aggregate.fields[0]; + source_leaf = if (source_leaf.* == .array) &source_leaf.array[0] else &source_leaf.aggregate.fields[0]; + } + leaf0.int.bits = 42; + try std.testing.expect(leaf1.int.bits == 0xfffa and source_leaf.int.bits == 0xfffa); + + // Repeated payloads within one value must also be separated. Identity + // handles are intentionally shallow, unlike aggregate/array storage. + var cell: Value.Cell = .{ .value = .{ .boolean = true }, .ty = .bool }; + var mutex: Value.MutexCell = .{ .locked = true, .cell = &cell }; + var graph: Value.Graph = .{ .id = 7, .authority = 0, .bytes = 1 }; + const shared = try m.heap().alloc(Value, 1); + shared[0] = .{ .int = .{ .ty = .u8, .bits = 9 } }; + const payload = try m.heap().alloc(Value, 5); + payload[0] = .{ .array = shared }; + payload[1] = .{ .array = shared }; + payload[2] = .{ .own = &cell }; + payload[3] = .{ .mutex = &mutex }; + payload[4] = .{ .graph = &graph }; + const copy = try m.deepCopy(.{ .array = payload }); + try std.testing.expect(copy.array[0].array.ptr != copy.array[1].array.ptr); + copy.array[0].array[0].int.bits = 3; + try std.testing.expect(copy.array[1].array[0].int.bits == 9 and shared[0].int.bits == 9); + try std.testing.expect(copy.array[2].own == &cell and copy.array[3].mutex == &mutex and copy.array[4].graph == &graph); +} + +test "failed local store retains its original complete payload" { + var arena_state: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena_state.deinit(); + const arena = arena_state.allocator(); + const byte: air.Type = .{ .int = .u8 }; + const inner: air.Type = .{ .array = &.{ .elem = byte, .len = 16 } }; + const ty: air.Type = .{ .array = &.{ .elem = inner, .len = 1 } }; + const module: air.Module = .{ .name = "copy", .format_version = 0, .lang = .{ 0, 1 }, .features = &.{}, .types = &.{}, .functions = &.{} }; + var m: Machine = .{ .arena = arena, .module = module, .fuel = null, .world = try .init(arena, .{}) }; + var buf: [512]u8 = undefined; + var fixed: std.heap.FixedBufferAllocator = .init(&buf); + m.exec_heap.space = .init(fixed.allocator()); + defer m.exec_heap.space.deinit(); + const old = try arena.alloc(Value, 16); + @memset(old, .{ .int = .{ .ty = .u8, .bits = 8 } }); + const incoming = try arena.alloc(Value, 16); + @memset(incoming, .{ .int = .{ .ty = .u8, .bits = 9 } }); + var old_outer = [_]Value{.{ .array = old }}; + var new_outer = [_]Value{.{ .array = incoming }}; + var cell: Value.Cell = .{ .value = .{ .array = &old_outer }, .ty = ty }; + var vals = [_]Value{ .{ .local = &cell }, .{ .array = &new_outer } }; + const inst: air.Inst = .{ .span = .{ .line = 1, .col = 1 }, .result = null, .op = .{ .local_store = .{ .local = 0, .value = 1 } } }; + try std.testing.expectError(error.OutOfMemory, m.execMemory(&vals, inst)); + try std.testing.expect(fixed.end_index != 0); + try std.testing.expect(cell.value.array.ptr == old_outer[0..].ptr); + for (cell.value.array[0].array) |v| try std.testing.expect(v.int.bits == 8); +} + test "zero construction handles deep arrays and named structures with pending siblings" { var arena_state: std.heap.ArenaAllocator = .init(std.testing.allocator); defer arena_state.deinit(); @@ -2639,7 +2777,7 @@ test "failed zero construction does not publish a partially initialized local" { try std.testing.expect(cell.value == .boolean and cell.value.boolean); } -test "deep zero materialization is one instruction under the ordinary collection threshold" { +test "deep zero and local-load copying count as single instructions at the ordinary collection threshold" { var arena_state: std.heap.ArenaAllocator = .init(std.testing.allocator); defer arena_state.deinit(); const arena = arena_state.allocator(); @@ -2648,6 +2786,7 @@ test "deep zero materialization is one instruction under the ordinary collection for (0..32768) |_| try src.appendSlice(arena, "array<"); try src.appendSlice(arena, "u8"); for (0..32768) |_| try src.appendSlice(arena, ",1>"); + const body_start = src.items.len; try src.appendSlice(arena, "\n local.zero %p\n ret\n"); const checked = try check.checkAir(arena, "zero-fuel.air", src.items); try std.testing.expect(checked.status == .accepted); @@ -2662,6 +2801,21 @@ test "deep zero materialization is one instruction under the ordinary collection try std.testing.expectEqualStrings("fuel", outcome.limit_exceeded.kind); } else try std.testing.expect(outcome == .returned and outcome.returned == .void); } + src.items.len = body_start; + try src.appendSlice(arena, "\n local.zero %p\n %v = local.load %p\n ret\n"); + const copying = try check.checkAir(arena, "copy-fuel.air", src.items); + try std.testing.expect(copying.status == .accepted); + for (0..5) |fuel| { + var stats: MemoryStats = .{}; + const outcome = try run(arena, copying.module.?, "main", .{ .fuel = fuel, .memory = &stats }); + try std.testing.expectEqual(@as(u64, fuel), stats.steps); + if (fuel < 4) { + try std.testing.expect(outcome == .limit_exceeded); + try std.testing.expectEqual(@as(u64, fuel), outcome.limit_exceeded.steps); + try std.testing.expectEqual(@as(u64, fuel), outcome.limit_exceeded.limit); + try std.testing.expectEqualStrings("fuel", outcome.limit_exceeded.kind); + } else try std.testing.expect(outcome == .returned and outcome.returned == .void); + } } fn main1(comptime ret: []const u8, comptime insts: []const u8) []const u8 { diff --git a/tests/conformance/phase1/run/copy_structure_payloads.air b/tests/conformance/phase1/run/copy_structure_payloads.air new file mode 100644 index 0000000..91209c2 --- /dev/null +++ b/tests/conformance/phase1/run/copy_structure_payloads.air @@ -0,0 +1,158 @@ +; expect: run +; result: 42 +; phase: 1 +; spec: docs/spec/07a-air-instructions.md §2 +module runtime.copies +air 0 +lang 0.1 +features [arrays, effects, ownership] + +type @Pair = struct { flag: bool, values: array } +type @Choice = enum { empty, full(@Pair) } +type @Holder = struct { choice: @Choice, rows: array, 2> } + +fn @read(%h: @Holder) -> u16 +effects [] +entry: + %local_1 = local.alloc @Holder + %item_8 = local.alloc @Pair + local.store %local_1, %h + %local_2 = local.load %local_1 + %choice_3 = struct.get @Holder.choice, %local_2 + enum.switch @Choice %choice_3, empty -> @case_empty_4, full -> @case_full_5 +case_empty_4: + %c_7 = const.u16 1 + br @endmatch_21(%c_7) +case_full_5(%p_6: @Pair): + local.store %item_8, %p_6 + %item_9 = local.load %item_8 + %flag_10 = struct.get @Pair.flag, %item_9 + cbr %flag_10, @then_11(), @else_12() +then_11: + %item_13 = borrow.ref %item_8 + %values_14 = borrow.field @Pair.values, %item_13 + %c_15 = const.usize 0 + %e_16 = borrow.index %values_14, %c_15 + %v_17 = load %e_16 + borrow.end %e_16 + borrow.end %values_14 + borrow.end %item_13 + br @endif_19(%v_17) +else_12: + %c_18 = const.u16 1 + br @endif_19(%c_18) +endif_19(%if_20: u16): + br @endmatch_21(%if_20) +endmatch_21(%match_22: u16): + %local_23 = borrow.ref %local_1 + %rows_24 = borrow.field @Holder.rows, %local_23 + %c_25 = const.usize 0 + %e_26 = borrow.index %rows_24, %c_25 + %c_27 = const.usize 0 + %e_28 = borrow.index %e_26, %c_27 + %v_29 = load %e_28 + borrow.end %e_28 + borrow.end %e_26 + borrow.end %rows_24 + borrow.end %local_23 + %t_30 = add.checked.u16 %match_22, %v_29 + %local_31 = borrow.ref %local_1 + %rows_32 = borrow.field @Holder.rows, %local_31 + %c_33 = const.usize 1 + %e_34 = borrow.index %rows_32, %c_33 + %c_35 = const.usize 1 + %e_36 = borrow.index %e_34, %c_35 + %v_37 = load %e_36 + borrow.end %e_36 + borrow.end %e_34 + borrow.end %rows_32 + borrow.end %local_31 + %t_38 = add.checked.u16 %t_30, %v_37 + ret %t_38 + +fn @main() -> u16 +effects [] +entry: + %state_10 = local.alloc @Holder + %snapshot_12 = local.alloc @Holder + %c_1 = const.bool true + %c_2 = const.u16 14 + %arr_3 = array.splat array %c_2 + %s_4 = struct.make @Pair(%c_1, %arr_3) + %c_5 = const.u16 14 + %arr_6 = array.splat array %c_5 + %e_7 = enum.make @Choice.full(%s_4) + %arr_8 = array.splat array, 2> %arr_6 + %s_9 = struct.make @Holder(%e_7, %arr_8) + local.store %state_10, %s_9 + %state_11 = local.load %state_10 + local.store %snapshot_12, %state_11 + %c_13 = const.u16 99 + %state_14 = borrow.mut %state_10 + %rows_15 = borrow.field @Holder.rows, %state_14 + %c_16 = const.usize 0 + %e_17 = borrow.index %rows_15, %c_16 + %c_18 = const.usize 0 + %e_19 = borrow.index %e_17, %c_18 + store %e_19, %c_13 + borrow.end %e_19 + borrow.end %e_17 + borrow.end %rows_15 + borrow.end %state_14 + %snapshot_20 = borrow.ref %snapshot_12 + %rows_21 = borrow.field @Holder.rows, %snapshot_20 + %c_22 = const.usize 0 + %e_23 = borrow.index %rows_21, %c_22 + %c_24 = const.usize 0 + %e_25 = borrow.index %e_23, %c_24 + %v_26 = load %e_25 + borrow.end %e_25 + borrow.end %e_23 + borrow.end %rows_21 + borrow.end %snapshot_20 + %c_27 = const.u16 14 + %cmp_28 = ne.u16 %v_26, %c_27 + cbr %cmp_28, @then_29(), @else_30() +then_29: + %c_31 = const.u16 1 + ret %c_31 +else_30: + br @endif_32() +endif_32: + %state_33 = borrow.ref %state_10 + %rows_34 = borrow.field @Holder.rows, %state_33 + %c_35 = const.usize 1 + %e_36 = borrow.index %rows_34, %c_35 + %c_37 = const.usize 0 + %e_38 = borrow.index %e_36, %c_37 + %v_39 = load %e_38 + borrow.end %e_38 + borrow.end %e_36 + borrow.end %rows_34 + borrow.end %state_33 + %c_40 = const.u16 14 + %cmp_41 = ne.u16 %v_39, %c_40 + cbr %cmp_41, @then_42(), @else_43() +then_42: + %c_44 = const.u16 2 + ret %c_44 +else_43: + br @endif_45() +endif_45: + %snapshot_46 = local.load %snapshot_12 + local.store %state_10, %snapshot_46 + %c_47 = const.u16 7 + %state_48 = borrow.mut %state_10 + %rows_49 = borrow.field @Holder.rows, %state_48 + %c_50 = const.usize 1 + %e_51 = borrow.index %rows_49, %c_50 + %c_52 = const.usize 1 + %e_53 = borrow.index %e_51, %c_52 + store %e_53, %c_47 + borrow.end %e_53 + borrow.end %e_51 + borrow.end %rows_49 + borrow.end %state_48 + %snapshot_54 = local.load %snapshot_12 + %read_55 = call @read(%snapshot_54) + ret %read_55 diff --git a/tests/conformance/source/runtime_values/copy_structure_payloads.aji b/tests/conformance/source/runtime_values/copy_structure_payloads.aji new file mode 100644 index 0000000..f5d856d --- /dev/null +++ b/tests/conformance/source/runtime_values/copy_structure_payloads.aji @@ -0,0 +1,30 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/07a-air-instructions.md §2; docs/spec/15-source-language.md §5 +// equivalent: phase1/run/copy_structure_payloads.air +module runtime.copies +struct Pair { flag: bool, values: [u16; 2] } +enum Choice { empty, full(Pair) } +struct Holder { choice: Choice, rows: [[u16; 2]; 2] } +fn read(h: Holder) -> u16 effects [] { + var local: Holder = h; + let value = match local.choice { + Choice::empty => { 1u16 } + Choice::full(p) => { var item: Pair = p; if item.flag { item.values[0usize] } else { 1u16 } } + }; + return value + local.rows[0usize][0usize] + local.rows[1usize][1usize]; +} +fn main() -> u16 effects [] { + let pair = Pair { flag: true, values: [14u16; 2] }; + let row = [14u16; 2]; + let initial = Holder { choice: Choice::full(pair), rows: [row; 2] }; + var state: Holder = initial; + let snapshot: Holder = state; + state.rows[0usize][0usize] = 99; + if snapshot.rows[0usize][0usize] != 14u16 { return 1; } + if state.rows[1usize][0usize] != 14u16 { return 2; } + state = snapshot; + state.rows[1usize][1usize] = 7; + return read(snapshot); +}