mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-04 08:04:37 +08:00
A checked conversion of a capsule of record A into record type B, when A has all of B's fields with the same types in any order, now answers a view: a B object whose two trailing words hold A and A's offsets for B's fields. Every field address of a B value tests the first word (recordViewFieldPtr, the record clone and the JSON walker), so reads and writes through either name reach the same storage. The view's record-source entry owns A's capsule: boxing the view answers that capsule, so identity holds, B's reflective surfaces and spreads see the whole object, and the entry dies with the view, which releases A's capsule. The capsule finds its views again through borrowed cast-list entries. Only the target types of such conversions carry the words and the test. They are planned from the IR before emission (record-views.ts): record types a checked conversion can produce for which another record type in the module has all their fields. Programs without checked conversions are unchanged. This replaces the prefix pointer pass, whose narrower release could not free the source's extra fields. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>