Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
231 commits
Select commit Hold shift + click to select a range
a4e0b39
feat(lua): parse locked LuaJIT 5.2-compat syntax
fffonion Nov 20, 2026
4d395e7
fix(lua): gate the LuaJIT oracle and match locked syntax limits
fffonion Nov 20, 2026
9eeb669
fix(lua): flatten unbounded left-associative chains
fffonion Nov 20, 2026
04085f6
fix(lua): clear strict clippy on the locked syntax frontend
fffonion Nov 21, 2026
87550fd
feat(lua): read top-level .rss links from the syntax tree
fffonion Nov 21, 2026
66ea830
fix(lua): bind named static imports to the declared alias
fffonion Nov 21, 2026
87e1618
feat(lua): lower chunk gotos and early returns on the fixed core
fffonion Nov 21, 2026
ebebdc4
fix(lua): keep control lowering off the production module
fffonion Nov 21, 2026
4d56b12
fix(lua): treat only false as falsy in chunk conditions
fffonion Nov 21, 2026
b872931
lower(lua): map classified numbers onto Core f64 arithmetic
fffonion Nov 20, 2026
2b41fe4
fix(lua): isolate number temps and reject known non-float literals
fffonion Nov 20, 2026
c13b2b0
lower(lua): classify proven binary64 source onto the number kernel
fffonion Nov 21, 2026
52a5c93
fix(lua): close binary64 evidence and cover numeric boundaries
fffonion Nov 21, 2026
401fe64
fix(lua): resume number-temp probes from the last ordinal
fffonion Nov 21, 2026
b737c98
fix(lua): round hex literals onto binary64 in one pass
fffonion Nov 21, 2026
9d1dd2f
feat(lua): lower locked numeric bitwise operators privately
fffonion Nov 21, 2026
f2e3a79
feat(lua): lower chunk repeat until break and continue on the fixed core
fffonion Nov 21, 2026
3fdbb1d
fix(test): isolate frozen corpus scratch from diagnostic probes
fffonion Nov 21, 2026
8d41159
feat(lua): add private table heap and explicit roots
fffonion Nov 20, 2026
3cb9e7c
fix(lua): roll back refused publishes and retire collected tokens
fffonion Nov 20, 2026
3e12114
fix(lua): keep sweeping after a retired table token
fffonion Nov 20, 2026
e52a2bc
fix(lua): collect the private heap in one linear pass
fffonion Nov 21, 2026
9f90bad
fix(lua): account collect slot walks and failed-close retries
fffonion Nov 21, 2026
a194df1
test(lua): exercise table and number isolation on fixed Core
fffonion Nov 21, 2026
5360b8f
test(lua): verify collection during later argument evaluation
fffonion Nov 21, 2026
d90991a
fix(lua): require an issued carrier for table values
fffonion Nov 21, 2026
f8f6f39
fix(lua): clear strict clippy on heap runtime tests
fffonion Nov 21, 2026
9bb5d7b
fix(lua): collapse the mark_slot live check
fffonion Nov 21, 2026
272c99e
test(lua): prove synchronous returns on a real frame
fffonion Nov 21, 2026
ab839ae
fix(lua): bind caller locals to synchronous return roots
fffonion Nov 21, 2026
07ee47a
fix(lua): root each consumed return binding in one caller frame
fffonion Nov 21, 2026
6f510fb
fix(test): claim an exclusive root for each staged example
fffonion Nov 21, 2026
086619d
fix(test): isolate each frozen diagnostic probe
fffonion Nov 21, 2026
cfb9bfc
fix(lua): release a return root only for the binding just cleared
fffonion Nov 21, 2026
1bc0af7
fix(lua): retire the chunk caller frame on normal completion
fffonion Nov 21, 2026
4a16e77
feat(lua): lower chunk numeric for on the fixed core
fffonion Nov 21, 2026
0f78954
test(lua): cover numeric for inside a transferred if arm
fffonion Nov 21, 2026
e8e9546
feat(lua): return from chunk while, repeat, and numeric for
fffonion Nov 21, 2026
48394c3
test(lua): reuse one root slot across 260 callable activations
fffonion Nov 21, 2026
babb91c
fix(lua): retain issued table carriers until sweep
fffonion Nov 21, 2026
3cf856a
feat(lua): leave a structured loop by goto to an outside label
fffonion Nov 21, 2026
ece3aea
feat(lua): follow a strong metatable edge during collection
fffonion Nov 21, 2026
9ed5562
test(lua): execute combined outward gotos beside return and chunk goto
fffonion Nov 21, 2026
6b8c984
feat(lua): lower same-loop gotos within Core iterations
fffonion Nov 21, 2026
0dc995e
feat(lua): trace strong table object keys
fffonion Nov 21, 2026
cc50dcc
feat(lua): collect weak private table entries
fffonion Nov 21, 2026
da43559
test(lua): cover weak field release and cleared entries
fffonion Nov 21, 2026
d4bf0c6
feat(lua): retire chunk do roots on normal exit
fffonion Nov 21, 2026
cedc659
fix(lua): release chunk do multi-return roots when the binding ends
fffonion Nov 21, 2026
1706ec2
fix(lua): release both receivers of a repeated chunk do local
fffonion Nov 21, 2026
80bb1cf
feat(lua): keep ordinary string fields through weak collection
fffonion Nov 21, 2026
f9e2f65
feat(lua): keep object-key strings through weak collection
fffonion Nov 21, 2026
9aa11b0
feat(lua): share one edge for dot and string keys
fffonion Nov 21, 2026
41fad46
fix(lua): compare string-key lookups without constructing a key
fffonion Nov 22, 2026
2f45350
feat(lua): retire chunk do roots on a trailing goto
fffonion Nov 22, 2026
d1d5659
feat(lua): retire chunk do roots across a trailing label set
fffonion Nov 22, 2026
816cdb3
test(lua): jump to the second trailing label and drop the empty control
fffonion Nov 22, 2026
79d5b9d
feat(lua): store numeric keys on the same edge record
fffonion Nov 22, 2026
b2e86e5
feat(lua): read rawget through the existing edge path
fffonion Nov 22, 2026
d5c7606
test(lua): drop the frozen bool-key write refusal
fffonion Nov 22, 2026
ee68c03
feat(lua): trace closures and cells on the weak-table graph
fffonion Nov 22, 2026
139f896
feat(lua): keep a chunk do root through one forward goto
fffonion Nov 22, 2026
b1fee3f
refactor(lua): drop the redundant chunk do label scope scan
fffonion Nov 22, 2026
d1cd2c3
feat(lua): root an open upvalue from the active frame
fffonion Nov 22, 2026
68cb74c
feat(lua): keep closure identity keys on the object-key record
fffonion Nov 22, 2026
858901c
feat(lua): retire the inner do root on one outward goto
fffonion Nov 22, 2026
c8977a4
test(lua): keep an issued envelope local until the block exits
fffonion Nov 22, 2026
6453457
feat(lua): lower one shared source closure cell onto table roots
fffonion Nov 22, 2026
c843c6b
fix(lua): share one cell between the outer binding and each closure
fffonion Nov 22, 2026
20a5be2
fix(lua): reject closure writes to shared upvalue cells
fffonion Nov 22, 2026
0850c4e
feat(lua): walk surviving weak-table entries with next
fffonion Nov 22, 2026
5942f89
fix(lua): refuse tail next and root the next receiver
fffonion Nov 22, 2026
ee1e054
feat(lua): reject LuaJIT local and upvalue limits in resolve
fffonion Nov 22, 2026
fe731a5
docs(lua): state the private lexical-limit vector contract
fffonion Nov 22, 2026
b0689b3
fix(lua): enforce lexical limits at control candidate entry
fffonion Nov 22, 2026
4a95355
fix(lua): report physical lines for static RSS links
fffonion Nov 22, 2026
874c3dc
feat(lua): store bool and binary64 on the shared upvalue edge
fffonion Nov 22, 2026
c4a4f9a
feat(lua): store string and bytes on the shared upvalue edge
fffonion Nov 22, 2026
3f8e959
fix(lua): parse weak mode only from a table owner
fffonion Nov 22, 2026
0866d02
feat(lua): call a top-level named static link
fffonion Nov 22, 2026
96d8a0b
fix(lua): continue next from a weak-cleared key
fffonion Nov 22, 2026
5d36689
fix(lua): reuse marked weak modes in sweep
fffonion Nov 22, 2026
8548f23
feat(lua): lower shared upvalue scalar reads and writes
fffonion Nov 22, 2026
1e0a95c
test(lua): claim source-file fixtures in exclusive temp directories
fffonion Nov 22, 2026
a618802
feat(lua): lower string byte length for rawlen and #
fffonion Nov 22, 2026
a27fa4f
feat(lua): read collectgarbage("count") as logical KiB
fffonion Nov 22, 2026
70bf784
fix(lua): place count fixtures in the process temp directory
fffonion Nov 22, 2026
941502a
feat(lua): honor raw table __metatable
fffonion Nov 22, 2026
72ac433
fix(lua): store a boolean on a raw named field
fffonion Nov 22, 2026
59805c1
feat(lua): lower unbound rawset onto the existing edge write
fffonion Nov 22, 2026
3d3d217
style(lua): order the rawset module registration
fffonion Nov 22, 2026
a8548c8
feat(lua): walk collect edges on owner chains
fffonion Nov 22, 2026
ad289d4
feat(lua): pause mark on a caller budget
fffonion Nov 23, 2026
9468b84
feat(lua): read rawlen from the first raw numeric border
fffonion Nov 23, 2026
a8f510d
feat(lua): pause sweep on a caller budget
fffonion Nov 23, 2026
d1afea8
feat(lua): compare unbound rawequal without metatable dispatch
fffonion Nov 23, 2026
16a65ed
fix(lua): skip nil and raw bytes in shared root gather
fffonion Nov 23, 2026
e45d341
feat(lua): pause pending-close enumeration on a caller budget
fffonion Nov 23, 2026
f685a37
feat(lua): repair a parked gray cursor when its edge slot is reused
fffonion Nov 23, 2026
f70173e
feat(lua): barrier a parked write into a scanned field or passed root
fffonion Nov 23, 2026
3d52c89
fix(lua): refuse a parked rewrite of the private cell edge
fffonion Nov 23, 2026
3d18654
fix(lua/heap): publish weak clears at the end of the owner walk
fffonion Nov 23, 2026
7dfdf0a
style(lua): format weak publish asserts for edition 2024
fffonion Nov 23, 2026
ebb0202
test(lua): cover mixed weak publication in one sweep
fffonion Nov 23, 2026
b0a8f18
fix(lua/heap): barrier a discovered field replace at the shared writer
fffonion Nov 23, 2026
7216459
feat(lua/heap): park an incomplete mark across windows
fffonion Nov 23, 2026
0907ef7
feat(lua/heap): accept a safepoint root batch on the open mark
fffonion Nov 23, 2026
b2e4667
feat(lua/heap): hand the current root batch across the first Roots bo…
fffonion Nov 23, 2026
bb9da39
test(lua): keep a pending table argument across a later Lua collect
fffonion Nov 23, 2026
7b31656
feat(lua/heap): observe a private cycle before it releases dead tables
fffonion Nov 23, 2026
00ada95
fix(lua): root a parenthesized later call before it collects
fffonion Nov 23, 2026
28b0613
feat(lua/heap): resume a saved mark through the same host close
fffonion Nov 23, 2026
7edc331
feat(lua/heap): resume a published sweep after the weak release
fffonion Nov 23, 2026
f9bb077
test(lua): assign equal named fields after saving both sides
fffonion Nov 23, 2026
17a398e
fix(lua): root parallel assignment values across a trailing call
fffonion Nov 23, 2026
22c0109
test(lua): satisfy assignment-root clippy denies
fffonion Nov 23, 2026
6d4afe6
feat(lua/heap): delete one named field during a published sweep tail
fffonion Nov 23, 2026
8eacc17
fix(lua): root earlier assignment calls until the last call
fffonion Nov 24, 2026
8a67805
feat(lua/heap): allocate one unmarked table during a published sweep …
fffonion Nov 24, 2026
5600aa2
docs(lua/heap): correct the published late reservation comment
fffonion Nov 24, 2026
a547f32
feat(lua/heap): refill one named gap during a published sweep tail
fffonion Nov 24, 2026
1b20b4d
feat(lua/heap): step one private cycle from a saved mark to its tail
fffonion Nov 24, 2026
cdd6a35
feat(lua/heap): retire one top root frame during a published sweep tail
fffonion Nov 24, 2026
1bc5e20
test(lua/heap): refill a published gap during a partial root scan
fffonion Nov 24, 2026
be2a8ae
test(lua/heap): require late_nodes zero on the roots refill receipt
fffonion Nov 24, 2026
26f3782
feat(lua): retire one callee frame on a published scalar return
fffonion Nov 24, 2026
dc160b1
fix(lua): refuse a published tail table before the callee retires
fffonion Nov 24, 2026
a8e8a54
feat(lua): publish one returned table into the caller root during Rel…
fffonion Nov 24, 2026
8689ec2
Wire omitted-data GC step in the opt-in Lua test candidate
fffonion Nov 24, 2026
a0b760a
fix(lua/heap): mark new UTF-8 table edges during a parked mark
fffonion Nov 24, 2026
686fb29
test(lua): opt in to guest GC stop, restart, and isrunning
fffonion Nov 24, 2026
d995c3c
Accept explicit default data on the opt-in Lua GC step
fffonion Nov 24, 2026
39c6648
Record mixed weak-group publication on the opt-in Lua GC step
fffonion Nov 24, 2026
1de5a9f
Join runtime step data with guest run control
fffonion Nov 24, 2026
5e87baa
Prove runtime data and run control on one catalog
fffonion Nov 24, 2026
cd9af05
Replay the parked UTF-8 replacement barrier onto runtime step data
fffonion Nov 24, 2026
a79f3d7
Replay the parked number replacement barrier onto runtime step data
fffonion Nov 24, 2026
2e6e443
Replay the reviewed idle empty-local step onto runtime step data
fffonion Nov 24, 2026
44cae19
Replay the reviewed due-gather gate onto runtime step data
fffonion Nov 24, 2026
4a034ce
Replay the reviewed gray allocation finish onto runtime step data
fffonion Nov 24, 2026
f12c5fd
Replay the reviewed root-batch capacity onto the runtime union
fffonion Nov 24, 2026
092fd1b
Replay the reviewed new number-key barrier onto the capacity union
fffonion Nov 24, 2026
599f163
Replay the reviewed existing object-key barrier onto the new-number u…
fffonion Nov 24, 2026
f2522a7
Replay the reviewed new table-object key barrier onto the root union
fffonion Nov 24, 2026
ccac89e
Replay the reviewed ordinary gap refill barrier onto the new table-ke…
fffonion Nov 24, 2026
fbea45c
Replay the reviewed unused-mut removal on the ordinary gap refill resume
fffonion Nov 24, 2026
7c3771c
Replay the reviewed automatic release allocation onto the barrier union
fffonion Nov 25, 2026
a8cb17e
Replay the reviewed automatic release handoff evidence onto the barri…
fffonion Nov 25, 2026
f96a118
Replay the reviewed gray, runtime step, and number replacement onto t…
fffonion Nov 25, 2026
1342941
Replay the reviewed self-cycle file entry onto the three-line GC union
fffonion Nov 25, 2026
28815f5
Replay reviewed function-tail rawlen onto the file-entry union
fffonion Nov 25, 2026
65c70c7
Replay the reviewed metatable write barrier onto the rawlen union
fffonion Nov 25, 2026
45823d0
Replay the reviewed closed cell barrier onto the file union
fffonion Nov 25, 2026
b0494a6
Shade the closure written into a scanned closed cell
fffonion Nov 25, 2026
9a183f5
Replay the reviewed rawlen host trace onto the closed-cell closure ba…
fffonion Nov 25, 2026
aae1648
Replay the reviewed unread host-step allow onto the rawlen trace union
fffonion Nov 25, 2026
9c6a990
Replay the reviewed weak-value strengthen onto the rawlen closure union
fffonion Nov 25, 2026
203d00e
Replay the reviewed rescan-cursor repair onto the strengthen union
fffonion Nov 25, 2026
e53c908
Replay the reviewed bare userdata onto the owner-rescan union
fffonion Nov 25, 2026
18e2932
Replay Lua single-owner weak-key strengthening onto userdata union
fffonion Nov 25, 2026
1f82d1c
Grow weak-owner rescan bits for mid-gray table slots
fffonion Nov 25, 2026
4f62f8d
Budget weak-owner rescan per target slot
fffonion Nov 25, 2026
c2bc6f0
lua52 heap: replay shared-mode delete onto gray union (pre-fix)
fffonion Nov 25, 2026
989f2d8
lua52 heap: keep started owners across direct __mode delete
fffonion Nov 25, 2026
36a9718
lua52 heap: cover same-metatable reset during parked rescan
fffonion Nov 25, 2026
0f2ba1c
lua52 heap: skip same-tuple setter rescan after mode delete
fffonion Nov 25, 2026
97b7db9
lua52 heap: cover bare userdata weak-key rescan after metatable setter
fffonion Nov 25, 2026
d16a28e
lua: read late-grown metatable weak modes within the mark budget
fffonion Nov 25, 2026
4ea1adf
lua: key late mode reads to write identity and coalesce deferred work
fffonion Nov 26, 2026
0248456
lua: clear late queue tags on release and sync batch docs
fffonion Nov 26, 2026
ba3c944
lua: stamp late modes by round and bound deferred replay
fffonion Nov 26, 2026
6ca8874
lua: fix late-metatable behaviors and move replay off the gray vector
fffonion Nov 26, 2026
d046213
lua: skip first-attach reread of reset-checked strong modes
fffonion Nov 26, 2026
aebd7eb
lua: treat a finished late strong mode as inspected, not cached
fffonion Nov 26, 2026
ae33310
tests: witness Core active-parent CallValue completion arms
fffonion Nov 26, 2026
e02aa62
tests: bind the active parent held argument to the executed callee
fffonion Nov 26, 2026
98e85c0
tests: execute Lua dynamic completion through the real file entry
fffonion Nov 26, 2026
3ceea54
tests: pin pcall callable admission and completion exit RED
fffonion Nov 26, 2026
e3285bb
lua: propagate possible non-Lua call arguments through pcall forwarding
fffonion Nov 26, 2026
c47cf32
tests: return the typed uncaught guest error from the completion exit
fffonion Nov 26, 2026
50ce60d
tests: observe the candidate lowering refusal for admission controls
fffonion Nov 26, 2026
53da303
lua: record malformed transport and keep the admission fixpoint clean
fffonion Nov 26, 2026
32d5ce8
lua: copy a captured callable so the original binding stays usable
fffonion Nov 26, 2026
8fc0f39
lua completion: read callable captures without consuming the binding
fffonion Nov 26, 2026
86c7960
Add the private typed userdata resource lifecycle
fffonion Nov 26, 2026
f2f695e
lua completion: hand the error table across real heap root frames
fffonion Nov 26, 2026
4cc90f8
Check typed userdata owners before close and gate bound sweeps
fffonion Nov 26, 2026
78941ff
Retain typed userdata reservations across GC and recover on publish
fffonion Nov 26, 2026
24ad2b1
lua completion: decode root completions and consume discarded pcall r…
fffonion Nov 26, 2026
2670f9a
Index only the selected slot in the shared sweep Select unit
fffonion Nov 26, 2026
c57aea5
lua completion: refuse chunk table exits and require the exact temp root
fffonion Nov 26, 2026
fdb418d
Select raw-__gc userdata as pending finalizers before weak publish
fffonion Nov 26, 2026
9eb77a4
Merge accepted userdata lifecycle base 2670f9a into protected-call co…
fffonion Nov 26, 2026
3b01dcc
Verify pending finalizers before commit and meter raw __gc lookup
fffonion Nov 26, 2026
07cfa35
Cover stored cursor gaps in the raw __gc selection lookup
fffonion Nov 26, 2026
481536e
Add Core pre-close callback and shutdown witness tests
fffonion Nov 26, 2026
bd2eae2
Meter pending queue reads and raw __gc pulse edges
fffonion Nov 26, 2026
8aa7994
Account a pending-queue split once under cfg(test)
fffonion Nov 26, 2026
e049304
Merge commit '8aa7994532469acc3f4b0f2817d14964f81e2c2d' into subagent…
fffonion Nov 26, 2026
5fb0c31
Settle white userdata with no raw __gc before the second mark
fffonion Nov 26, 2026
a64435f
Journal settlement per slot and clear k-only hash finalized values
fffonion Nov 26, 2026
4e8cf89
Clear k-only finalized values under guest __mode and deterministic nu…
fffonion Nov 26, 2026
4b501c5
Cap numeric hash keys at LuaJIT's last array index
fffonion Nov 26, 2026
d6c40d9
Take one published pending userdata into a root slot
fffonion Nov 26, 2026
02020ca
Witness a typed host callable invoked inside its Lua parent frame
fffonion Nov 26, 2026
51efa5e
Resolve the current raw finalizer when dequeuing one pending head
fffonion Nov 26, 2026
9c048cc
Preserve finalizer target types and userdata receivers at dequeue
fffonion Nov 27, 2026
63e1fba
Carry an exact Core callable on a Lua closure generation
fffonion Nov 27, 2026
a4b3a43
Order userdata finalizers by live allocation chain
fffonion Nov 27, 2026
ef3c55d
Close raw callable admission behind the guest import
fffonion Nov 27, 2026
078e00b
Witness reverse-cohort owner rollback and live-chain release
fffonion Nov 27, 2026
4a48a54
Merge accepted closure carrier registration with pending userdata coh…
fffonion Nov 27, 2026
0289bd6
lua52: slot-linked pending queue with generation cursors and checkpoi…
Nov 27, 2026
1381f3a
Hand a fresh closure generation into an existing raw call field
fffonion Nov 27, 2026
64d6fbb
Carry a typed lua.userdata argument through a host-returned callable
fffonion Nov 27, 2026
4e54422
Merge accepted raw call carrier field into pending slot queue
fffonion Nov 27, 2026
f122ca7
Record typed callback entry before probes and bind B to the native di…
fffonion Nov 27, 2026
4f2554d
Witness a published raw-call dequeue across a guest replacement
fffonion Nov 27, 2026
7e1ad7d
Scope the raw-call file-entry witness to its own VM
fffonion Nov 27, 2026
fce876e
Add a narrowed typed precommit borrow seam witness
Rafa-Ross Nov 27, 2026
0f0966e
Isolate typed transport compile and run scopes
Rafa-Ross Nov 27, 2026
ff40032
Use a slot-linked LIFO for ordinary Gray work
fffonion Nov 27, 2026
b626eca
Merge accepted published raw-call dequeue into typed precommit isolation
fffonion Nov 27, 2026
c2b2dc0
Keep ordinary Gray links inert when a round stamp is reused
fffonion Nov 27, 2026
4646211
Commit the published typed head from the active parent frame
fffonion Nov 27, 2026
2dd3574
Keep the typed published commit inside the heap owner
fffonion Nov 27, 2026
1eae54c
Fix Lua rescan epoch reuse across abandoned rounds
fffonion Nov 27, 2026
9e7ff8a
Source the typed published head from its raw call chain
fffonion Nov 27, 2026
c753a41
Fix Lua late-target stamp reuse on release
fffonion Nov 27, 2026
3c91625
Merge typed published-head closure with late-target stamp release
fffonion Nov 27, 2026
a3ef11b
Retire the synchronous typed callback root inside the parent frame
fffonion Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
455 changes: 455 additions & 0 deletions src/frontends/lua/ast.rs

Large diffs are not rendered by default.

1,737 changes: 1,737 additions & 0 deletions src/frontends/lua/control.rs

Large diffs are not rendered by default.

2,007 changes: 2,007 additions & 0 deletions src/frontends/lua/heap.rs

Large diffs are not rendered by default.

200 changes: 200 additions & 0 deletions src/frontends/lua/heap/handle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
//! Private handles. They are not VM values and have no bare-integer ABI.

/// Kind carried by a private handle. Table, closure, upvalue, and bare
/// userdata nodes share one heap. An operation rejects a live node of a
/// different kind.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum HandleKind {
/// A table node.
Table,
/// A closure node. It is not a callable value.
Closure,
/// A shared upvalue node. Its current edge holds a table, a closure, or a
/// scalar (boolean, binary64, string, or bytes), or is absent (nil). It has
/// no open or closed flag.
Upvalue,
/// A bare userdata node. It has no guest carrier and no Core resource
/// token. The private pending-finalizer slice can attach one metatable
/// reference with `set_userdata_metatable`; that reference is a strong
/// edge only in the private slice and is not a guest metamethod surface.
Userdata,
}

/// Domain-checked reference to one table node.
///
/// `domain` ties the handle to the heap that allocated it. `slot` and
/// `generation` are checked against that heap on every use. A copied handle
/// is an alias only when those fields still match a live node. Guest values
/// are not built from these fields.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct TableRef {
domain: u64,
slot: u32,
generation: u32,
kind: HandleKind,
}

impl TableRef {
/// Field construction stays inside the heap. A guest `Value` is not a
/// `TableRef` and cannot be assembled from these fields.
pub(super) fn table(domain: u64, slot: u32, generation: u32) -> Self {
Self {
domain,
slot,
generation,
kind: HandleKind::Table,
}
}

/// Heap domain that allocated this handle.
pub fn domain(self) -> u64 {
self.domain
}

/// Stable slot index. Collection does not move it.
pub fn slot(self) -> u32 {
self.slot
}

/// Generation observed when the handle was issued.
pub fn generation(self) -> u32 {
self.generation
}

/// Handle kind. Table operations reject any other kind.
pub fn kind(self) -> HandleKind {
self.kind
}
}

/// Domain-checked reference to one closure node.
///
/// Construction stays inside the heap. A guest `Value` is not a `ClosureRef`.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct ClosureRef {
domain: u64,
slot: u32,
generation: u32,
kind: HandleKind,
}

impl ClosureRef {
pub(super) fn closure(domain: u64, slot: u32, generation: u32) -> Self {
Self {
domain,
slot,
generation,
kind: HandleKind::Closure,
}
}

/// Heap domain that allocated this handle.
pub fn domain(self) -> u64 {
self.domain
}

/// Stable slot index. Collection does not move it.
pub fn slot(self) -> u32 {
self.slot
}

/// Generation observed when the handle was issued.
pub fn generation(self) -> u32 {
self.generation
}

/// Handle kind. Closure operations reject any other kind.
pub fn kind(self) -> HandleKind {
self.kind
}
}

/// Domain-checked reference to one shared upvalue node.
///
/// Construction stays inside the heap. The node has no open or closed flag.
/// Its current edge is a table, a closure, a scalar (boolean, binary64, string,
/// or bytes), or missing (nil).
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct UpvalueRef {
domain: u64,
slot: u32,
generation: u32,
kind: HandleKind,
}

impl UpvalueRef {
pub(super) fn upvalue(domain: u64, slot: u32, generation: u32) -> Self {
Self {
domain,
slot,
generation,
kind: HandleKind::Upvalue,
}
}

/// Heap domain that allocated this handle.
pub fn domain(self) -> u64 {
self.domain
}

/// Stable slot index. Collection does not move it.
pub fn slot(self) -> u32 {
self.slot
}

/// Generation observed when the handle was issued.
pub fn generation(self) -> u32 {
self.generation
}

/// Handle kind. Upvalue operations reject any other kind.
pub fn kind(self) -> HandleKind {
self.kind
}
}

/// Domain-checked reference to one bare userdata node.
///
/// Construction stays inside the heap. A guest `Value` is not a
/// `UserdataRef`. A bare node has no environment or payload. The private
/// pending-finalizer slice stores one optional metatable reference on the
/// slot and can retain the node for a future finalizer consumer; it still has
/// no guest carrier.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct UserdataRef {
domain: u64,
slot: u32,
generation: u32,
kind: HandleKind,
}

impl UserdataRef {
pub(super) fn userdata(domain: u64, slot: u32, generation: u32) -> Self {
Self {
domain,
slot,
generation,
kind: HandleKind::Userdata,
}
}

/// Heap domain that allocated this handle.
pub fn domain(self) -> u64 {
self.domain
}

/// Stable slot index. Collection does not move it.
pub fn slot(self) -> u32 {
self.slot
}

/// Generation observed when the handle was issued.
pub fn generation(self) -> u32 {
self.generation
}

/// Handle kind. Userdata operations reject any other kind.
pub fn kind(self) -> HandleKind {
self.kind
}
}
87 changes: 87 additions & 0 deletions src/frontends/lua/heap/resource.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//! Typed resource token for a private table handle.
//!
//! The token crosses the host boundary as `resource<lua.table>`. Its physical
//! VM carrier is the existing resource handle, validated by arena, type, and
//! key. It does not store table fields and is not a GC root.

use vm::ResourceTypeKey;
use vm::host_extension::HostResourceType;
use vm::resource::HostResource;

use super::handle::{TableRef, UserdataRef};

/// Public object capability for one private table node.
#[derive(Debug)]
pub struct LuaTableResource {
table: TableRef,
}

impl LuaTableResource {
pub(super) fn new(table: TableRef) -> Self {
Self { table }
}

/// The private handle stored in this token.
pub fn table(&self) -> TableRef {
self.table
}

/// Catalog key used by `typed_resource_with_key`.
pub fn key() -> ResourceTypeKey {
ResourceTypeKey::new(Self::KEY).expect("lua.table is a valid resource key")
}
}

impl HostResource for LuaTableResource {
fn resource_type_key() -> Option<ResourceTypeKey> {
Some(Self::key())
}
}

impl HostResourceType for LuaTableResource {
const KEY: &'static str = "lua.table";
const DESCRIPTION: &'static str = "Lua table";
}

/// Public object capability for one private typed userdata node.
///
/// This is a separate concrete resource type and catalog key from
/// [`LuaTableResource`]. A table token is not accepted for a userdata slot.
/// The payload carries the exact Lua domain, kind, slot, and generation that
/// the heap bound. A same-type token for another userdata has the same key but
/// a different payload, so the checked borrow rejects it.
///
/// It uses the default synchronous close, which returns
/// [`CloseProgress::Ready`](vm::resource::CloseProgress). No path of this type
/// starts an asynchronous close.
#[derive(Debug)]
pub struct LuaUserdataResource {
userdata: UserdataRef,
}

impl LuaUserdataResource {
pub(crate) fn new(userdata: UserdataRef) -> Self {
Self { userdata }
}

/// The exact private handle stored in this token.
pub fn userdata(&self) -> UserdataRef {
self.userdata
}

/// Catalog key used by `typed_resource_with_key`.
pub fn key() -> ResourceTypeKey {
ResourceTypeKey::new(Self::KEY).expect("lua.userdata is a valid resource key")
}
}

impl HostResource for LuaUserdataResource {
fn resource_type_key() -> Option<ResourceTypeKey> {
Some(Self::key())
}
}

impl HostResourceType for LuaUserdataResource {
const KEY: &'static str = "lua.userdata";
const DESCRIPTION: &'static str = "Lua userdata";
}
Loading
Loading