Commit 17196a8
reg VM: make Managed transparent on read; don't wrap immutable scalars
The reg VM models the 'manage' keyword as VmValue::Managed(Rc<RefCell<..>>),
a shared mutable cell for retaining a value in a collection/field. But this
wrapper leaked into reads: a value stored via 'manage' (e.g. List.push(manage x)
or Map.insert(value: read (manage x))) came back wrapped, and the typed
accessors rejected it ("reg VM expected List/String, got ...").
Two complementary fixes, matching the rest of the value model where Managed is
already transparent (display/native_value/equality all unwrap it):
1. Owned/Copy/Rc-returning accessors (expect_int/float/char/bool/list/deque/
map/closure_ref) now peel Managed by recursing, so a Managed collection or
scalar reaching an op is handled from any source.
2. The borrow-returning accessors (String/Bytes/Json -> &str/&[u8]/&Value)
cannot peel through a RefCell. Fix at the source: Manage now skips wrapping
immutable scalars (Unit/Int/Float/Bool/Char/Bytes/String/Json), since they
have value semantics and no in-place mutation -- wrapping them was a no-op
that only leaked an opaque Managed. Collections/structs still wrap (aliasing).
Unblocks running real packages on the dev VM (tinygrad port): the device
allocator/buffer store and state-dict name lists round-trip managed values
through Map/List. Full rsscript suite green (only the unrelated pre-existing
Channel.message parity-fixture failure remains).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 5ac8157 commit 17196a8
2 files changed
Lines changed: 42 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6677 | 6677 | | |
6678 | 6678 | | |
6679 | 6679 | | |
6680 | | - | |
| 6680 | + | |
| 6681 | + | |
| 6682 | + | |
| 6683 | + | |
| 6684 | + | |
| 6685 | + | |
| 6686 | + | |
| 6687 | + | |
| 6688 | + | |
| 6689 | + | |
| 6690 | + | |
| 6691 | + | |
6681 | 6692 | | |
6682 | 6693 | | |
6683 | 6694 | | |
| |||
12634 | 12645 | | |
12635 | 12646 | | |
12636 | 12647 | | |
| 12648 | + | |
| 12649 | + | |
| 12650 | + | |
| 12651 | + | |
12637 | 12652 | | |
12638 | 12653 | | |
12639 | 12654 | | |
| |||
12644 | 12659 | | |
12645 | 12660 | | |
12646 | 12661 | | |
| 12662 | + | |
12647 | 12663 | | |
12648 | 12664 | | |
12649 | 12665 | | |
| |||
12654 | 12670 | | |
12655 | 12671 | | |
12656 | 12672 | | |
| 12673 | + | |
12657 | 12674 | | |
12658 | 12675 | | |
12659 | 12676 | | |
| |||
13094 | 13111 | | |
13095 | 13112 | | |
13096 | 13113 | | |
| 13114 | + | |
13097 | 13115 | | |
13098 | 13116 | | |
13099 | 13117 | | |
| |||
13104 | 13122 | | |
13105 | 13123 | | |
13106 | 13124 | | |
| 13125 | + | |
13107 | 13126 | | |
13108 | 13127 | | |
13109 | 13128 | | |
| |||
13116 | 13135 | | |
13117 | 13136 | | |
13118 | 13137 | | |
| 13138 | + | |
13119 | 13139 | | |
13120 | 13140 | | |
13121 | 13141 | | |
| |||
13139 | 13159 | | |
13140 | 13160 | | |
13141 | 13161 | | |
| 13162 | + | |
13142 | 13163 | | |
13143 | 13164 | | |
13144 | 13165 | | |
| |||
13159 | 13180 | | |
13160 | 13181 | | |
13161 | 13182 | | |
| 13183 | + | |
13162 | 13184 | | |
13163 | 13185 | | |
13164 | 13186 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
306 | 325 | | |
307 | 326 | | |
308 | 327 | | |
| |||
0 commit comments