Title: Wired-in Record.Unsafe: compiler-owned IR record primops · Issue #305 · purescript-lua/purescript-lua · GitHub
Open Graph Title: Wired-in Record.Unsafe: compiler-owned IR record primops · Issue #305 · purescript-lua/purescript-lua
X Title: Wired-in Record.Unsafe: compiler-owned IR record primops · Issue #305 · purescript-lua/purescript-lua
Description: Problem The record-surgery layer from #236 (PR #304) is a handwritten registry: a four-entry map in Language.PureScript.Backend.IR.RecordSurgery holding the compiler's beliefs about the semantics of the prelude fork's Record.Unsafe FFI, ...
Open Graph Description: Problem The record-surgery layer from #236 (PR #304) is a handwritten registry: a four-entry map in Language.PureScript.Backend.IR.RecordSurgery holding the compiler's beliefs about the semantics o...
X Description: Problem The record-surgery layer from #236 (PR #304) is a handwritten registry: a four-entry map in Language.PureScript.Backend.IR.RecordSurgery holding the compiler's beliefs about the semanti...
Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/305
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Wired-in Record.Unsafe: compiler-owned IR record primops","articleBody":"## Problem\n\nThe record-surgery layer from #236 (PR #304) is a handwritten registry: a four-entry map in `Language.PureScript.Backend.IR.RecordSurgery` holding the compiler's *beliefs* about the semantics of the prelude fork's `Record.Unsafe` FFI, with the fork file remaining the authority. That split has three standing costs. First, the drift class is silent: a fork release that changes an entry's semantics keeps compiling and miscompiles quietly (bounded today by the registry's size and the golden eval oracle that runs the same functions down folded and unfolded paths, but bounded is not gone). Second, dynamic-label call sites — `unsafeGet(key)(rec)` in the generic-deriving family — stay opaque foreign calls paying two curried `CALL`s and a closure per read, because the registry only fires on static labels. Third, the planned `record` fork would need Builder FFI plus more registry entries, re-opening the question #304 deferred: upstream's Builder primitives mutate in place, so registry folds like `copyRecord r → r` are unsound unless the fork commits to pure-copy FFI — semantics underdetermined as long as the fork, not the compiler, owns them.\n\n## Approach\n\nWire the module in, GHC-style (wired-in ids like `seq`: compiler-defined, no library source consulted): ship a compiler-owned IR implementation of `Record.Unsafe` so the compiler *is* the semantics and the drift class dies by ownership. Concretely: (a) a record primop family — a dynamic-key read (`get l r` lowering to `r[l]`), a ternary copy-with-extend (`set l v r` lowering to a new runtime fixture; the existing `pslua_object_update` cannot serve because it iterates the base's keys and silently drops patches whose key is absent, while `unsafeSet` must add fields), a delete, and a membership test (lowering to `r[l] ~= nil`); (b) a builtin path in foreign resolution so the module's `ForeignImport` resolves internally instead of to a `.lua` file — until the fork side migrates, the builtin shadows the fork's file exactly as ForeignLift already shadows lifted exports; (c) the four fold arms from #304 transplanted as primop constant folds next to `foldPrimBinOp`, carrying the `plainLabel` side condition (the raw-vs-mangled key schism stays quarantined in the fold, since generated tables key by the `makeSafe` spelling while dynamic reads look up raw strings); (d) classification updates where new shapes meet existing analyses — scalar replacement (#240) must treat a dynamic-key read as a full read of the record, and the allocation/identity guard (#284) must classify copy-with-extend as reference-constructing. Fork-side migration (deleting `Record/Unsafe.lua` and pinning \"prelude ≥ X requires pslua ≥ Y\") is deliberately out of scope here and batches with the next coordinated set release; the `record` fork, created after this lands, ships Builder wired-in from day one and never carries Builder FFI at all.\n\n## Prerequisites / Relations\n\nBlocked by #247, which establishes the exact pattern this issue scales up — extending the primop vocabulary with a lift target, folds, and a codegen lowering — at a fifth of the size. Relates to #283 as the precedent for the coordinated fork+compiler release the fork-side deletion should ride, to #240 and #284 as the analyses that must learn the new shapes, and to #251, which touches the same foreign-resolution code that grows the builtin path. Subsumes the Record.Builder registry extension deferred from #236 in PR #304, and for the record family it also subsumes the idea of a generic Lua-level inline+beta over small FFI bodies (the wired-in lowering already inlines the dynamic-label reads that pass would have caught).\n\n## Verification / Measurement\n\nA dynamic-label `unsafeGet` golden (the `Golden.BugListGenericEq` shape, `local get = Record_Unsafe_foreign.unsafeGet(key)`) emits an inline `rec[key]` read with the two curried calls and the closure elided; every #304 golden stays byte-identical (the folds transplant, so `golden.lua` must not move); all hand-verified eval oracles unchanged; and, until the fork file is deleted, a differential test that the builtin lowering and the fork's `Record/Unsafe.lua` agree on the golden corpus, so the shadowing period cannot hide a semantics gap. Counter check through the #172 harness: the `Bench.RecordSet` censuses stay at their #304 values (no regression), and a dynamic-label micro variant shows the per-read `FNEW` disappearing from the function-body census.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-26T15:41:13Z","url":"https://github.com/purescript-lua/purescript-lua/issues/305"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e4cb1ec5-a6cb-2199-30ee-bddcf1d5e8a0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D05E:1C6C3E:7DA1D3:A83305:6B00DB73 |
| html-safe-nonce | 46c0fc7db2bd3a88606dba09b98673b6642613fad283a5caa2d2955a5d31e3f1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMDVFOjFDNkMzRTo3REExRDM6QTgzMzA1OjZCMDBEQjczIiwidmlzaXRvcl9pZCI6IjM0MDQxNzk0NzEzMDgyMTcyMDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1dba0c22cca6b54f8a359ff28b27f092583602f345d751fff069f89fd8a6483b |
| hovercard-subject-tag | issue:4981283861 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/purescript-lua/purescript-lua/305/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ccd82cd06d944630e4ae581b6e9a006b2e301cf32b9f85f2493972fd6f2730ac/purescript-lua/purescript-lua/issues/305 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ccd82cd06d944630e4ae581b6e9a006b2e301cf32b9f85f2493972fd6f2730ac/purescript-lua/purescript-lua/issues/305 |
| og:image:alt | Problem The record-surgery layer from #236 (PR #304) is a handwritten registry: a four-entry map in Language.PureScript.Backend.IR.RecordSurgery holding the compiler's beliefs about the semantics o... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Unisay |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| turbo-cache-control | no-preview |
| go-import | github.com/purescript-lua/purescript-lua git https://github.com/purescript-lua/purescript-lua.git |
| octolytics-dimension-user_id | 131581790 |
| octolytics-dimension-user_login | purescript-lua |
| octolytics-dimension-repository_id | 587200487 |
| octolytics-dimension-repository_nwo | purescript-lua/purescript-lua |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 587200487 |
| octolytics-dimension-repository_network_root_nwo | purescript-lua/purescript-lua |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width