mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-08 08:44:37 +08:00
A record literal asserted to a wider record type (`{ truncated: true }
as TruncationResult`) is a checked cast whose source shape lacks some of
the target's fields. Slice C1 of the presence-narrowing design: teach the
record-view plan, the LLVM backend and the runtime about the PARTIAL view
such a cast answers.
- `dynCheck.partialView` marks the cast; the validator requires a
`dynFrom{liveRef}` record operand whose every field is a target field
with an equal type.
- `planRecordViews` records the (target, source) pairs it cannot plan as
full views and exposes `partial`, `partialTargets` and
`partialMissing`; the cycle analysis owns these views like the rest.
- `recordViewCall` emits the `SIZE_MAX` sentinel for a target field the
source does not declare.
- `scr_record_view_slot` answers NULL for a field the viewed record does
not declare (its offset table holds `SIZE_MAX`), and
`scr_record_view_field` passes that answer through. The emitted view
guard, the clone helper and a presence test (`recordHas`) ask for that
slot and stop with `scr_trap` and the program's own message when it is
absent, so the runtime gains no string constant and no function: a new
function in a linked unit shifts the pack for every program. A program
without a partial assertion compiles to the same bytes.
- `recordHas` asks the view when the field is missing from some partial
source, and still honors an undefined-armed field.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>