Skip to content

feat(lua): comparehensive luajit + lua52 support - #3

Draft
fffonion wants to merge 231 commits into
masterfrom
subagent/lua52-active-typed-callback-0e1deef6
Draft

fffonion wants to merge 231 commits into
masterfrom
subagent/lua52-active-typed-callback-0e1deef6

Conversation

@fffonion

Copy link
Copy Markdown
Contributor

No description provided.

Add a private lexer, parser and resolver for pinned LuaJIT
96f7b297 with LUAJIT_ENABLE_LUA52COMPAT. The production .lua entry
is unchanged; accept/reject is checked with load(..., "t").
Require an explicit LUAJIT_ORACLE and a strict ACCEPT/REJECT protocol.
Reject triple-equals assignment, repeat continues that enter later
locals, LL/ULL values above 2^64-1, and binary literals over 64 bits.
Count syntax levels the way the locked parser does, including long
left-associative chains that stay shallow.
Collapse nested conditions that already had the same predicates, call
stmt_span directly, and enumerate statements instead of a range.
The line scanner has no lexical state, so require text in a string,
comment, or uncalled function becomes a static module edge. Keep that
scanner on production LuaPlugin. The private walk only emits an
unshadowed chunk-level local require of a .rss spec, with the existing
namespace or named clause and the require( line.
The candidate list was a public export used only by tests, and a named
require stored the export as the local binding. Core binds that local
name. Keep the scan in the test include, and do not treat the old
lowerer as a dynamic require engine.
A test plugin compiles real .lua through the existing parser and resolver.
Gotos and a non-tail return become a private state loop. A source loop
with no jump stays a Core while, so break and continue bind to that loop.
The compiler test already loads control.rs through a path attribute.
A library module declaration compiled that uncalled candidate into the crate.
Core Brfalse and Not require a bool, so if 0, while 1, and not 0 compiled and then failed in the interpreter. if, elseif, while, and not all compare the operand with false once before the branch.
Floor remainder binds each operand once and uses math::floor, because
Core Mod is truncating and does not match LuaJIT. Not wired into the parser.
Remainder temps use builder-local names outside the Lua identifier grammar, so a guest local and a nested remainder no longer share slots. ClassifiedNumber rejects a directly visible Int or other non-float literal instead of letting Core Div truncate it. Sequential remainder slot growth is measured and left for the future lowerer.
The source seam lowers only grammar-proven floats and locals in the same
trusted scope. Chains are hoisted onto the existing kernel temps; Core still
owns slot compaction.
An arbitrary Core slot is no longer float evidence. Arithmetic stays on
ClassifiedNumber until the consuming statement, and %a subnormals keep
their exact bits. The claimed literal and remainder edges are compared
with locked LuaJIT, including LL/ULL/i type categories.
Each lowering scanned occupied `$lua.number.*` names from zero, so
resolve_local_expr calls grew with the square of the temps. The
lowering now keeps a monotonic ordinal and resumes there. A later
lowering on the same builder still starts at zero.

Private plugin counts, not a wall-clock gate. 12 remainders: probes
156 to 24, logical 36, frame 3. A 128-mod flat chain: probes 24640 to
383, logical 383, frame 3, depth 6. Operand rebinds stay: they are
most of those logical slots but color to the same 3 frame slots, and
skipping them would drop the two-lowering collision witness.

Same-name Let reads the old binding (7/2 then x+1 is 4.5). -(-0.0)
is bit-exact. The always-Err slot stub is gone. The source-test AST
allow is on that path module only.
Hex floats and hex integers share a guard/sticky conversion. A wide
significand is not truncated to u64 and then scaled again. Syntax
rejections and LL/ULL/i stay outside that path.

Private plugin only. Locked LuaJIT %a compared 51 finite, 8 signed
zero, 7 non-finite, and 1 empty result. Stops are syntax 9, cdata 3,
and unsupported 7. An ordinary hex float and 2^64 do not share bits.
prepare_runnable_corpus deleted the shared scratch parent while a diagnostic probe was being written. Stage each corpus call in a newly created child and leave the diagnostics directory in place.
Keep the heap unwired from the Lua entry. Guest values are typed
resource<lua.table> tokens, not GC roots and not bare integers.
A full resource table now refuses push_resource after the Lua slot is
reserved, then rolls that slot back so existing roots stay and the same
slot is reused at the next generation. Host collect closes the exact typed
tokens of swept tables through the scope close contract and returns their
quota in the same VM. Tokens stay on the heap and are not GC roots.
A stored lua.table token already removed by close or take aborted
collection and stayed in the node. For that stored token only, treat
ResourceAlreadyClosed and ResourceStale as retired and continue the sweep.
Mark once from explicit roots, walk a temporary outgoing index, and
filter the edge vector once. Host close checks the slot captured at
mark time, so a retired token does not scan every slot or close a
successor.
Record the node-slot and root-slot visits a full collect already makes,
and the scratch requests those passes measure. A close failure keeps the
closed prefix, leaves the suffix open, and a later collect marks again
from the current roots.
End non-Drop host borrows with a block, pass the existing call
reference, enumerate host indexes, and group meter expectations.
Assertions, collection order, and argument evaluation stay the same.
Combine the live-slot match and the unmarked test into one let-chain. An unmarked live slot is still marked, queued, and counted once.
Lower an uncaptured local function through Core CallScript and Ret.
The nested return is still one value: a private ordered array. The
candidate publishes the caller root, then leaves the callee frame.
The ordered array stays a private transport. The caller reads each
known slot into a local, and nil assignment writes nil. A result
frame is released only when that local owns one.

Core Ret and the callee Lua frame stay separate: publish happens
while the Lua frame is still current, then retire leaves it.
fffonion and others added 30 commits November 27, 2026 06:04
…mbers

Claim the reserved guest __mode field and negative/non-integer number
keys in the k-only hash value rule. Keep zero, negative zero, and
positive integers on the unmodeled array/hash branch, and keep internal
field ids out of guest iteration. A cleared value under the guest-visible
__mode field stays as a cursor gap so a real next cursor continues past
it.
LuaJIT bounds the array part at LJ_MAX_ASIZE = 2^27 + 1 slots including the zero slot, and inarray requires index < asize. Integer keys above 2^27 are therefore always hash keys, so a finalized value under such a k-only key must clear. 2^27 remains on the unmodeled array/hash branch.
Compile one real Lua fixture through the locked Core and run five separate
VMs. The positive arm returns the exact SharedCallable the VM produced, calls
it from the still-active parent frame with an issued table and a real
lua.userdata token, and checks the child formal slots, the resumed CallValue
and the parent's continuation. Omit, different-prototype and wrong-arity arms
refute the instance and call assertions. The fifth arm has the host select the
other capture instance of the factory prototype; this pin attaches no callable
schema to a nested closure prototype, so the typed return check refuses it and
the guest call is recorded as not achieved rather than claimed. The fixture
also records the production admission refusal for a host-returned callee.
Store the exact guest-written SharedCallable Arc in the existing closure slot carrier, admitted only with zero compiled capture slots, and return it through a generation-checked lookup. Release drops the slot's Arc and a reused generation starts unbound; mark still follows only roots and edges.

The file-entry witness runs one real Lua VM, registers two distinct top-level closures, proves exact Arc identity, keeps the explicitly rooted node through real collections while the unrooted node is reclaimed, and measures exactly one Arc released by each retired slot. It covers rebinding, foreign domain, wrong kind, stale generation, and a captured callable refusal. A release-clearing RED exits 101 and the restored bytes rerun green.
Link each userdata at the live-chain head on allocation and unlink it in constant work before release advances the generation. Walk that chain for pending-finalizer selection, so one cohort selects newest-first while an older published batch stays in front. Add qualification for reverse allocation, cross-batch FIFO, per-pulse chain reads, and release/rollback neighbours.
Make the closure-slot callable store private to the heap storage module. A real .lua guest can now admit a callable only through the heap-owned note import: the dispatch function is module-private, derives the capture count from the callable's prototype in the invoking VM, refuses any nonzero capture before allocating, and reports a boolean to the guest. No crate-visible entry accepts an Arc<CallableValue> plus a caller-chosen count, a Value plus a VM, or a bare capture count.

The file-entry witness compiles the heap-owned schema into its test catalog and registers the heap-owned import. Its real captured callable returns false and receives no closure generation; the two zero-capture callables still carry the exact guest Arcs, survive or are collected by real mark/sweep, release exactly one slot Arc, and reuse the slot at the next unbound generation. Pure slot refusals (same-generation rebind, store-level capture refusal, foreign domain, wrong kind, reuse binding, existing table carrier) move to the storage module's own cfg(test) units; the dead-code-only surface test is removed.

A RED against the previous raw entry fed the same real captured callable with a bare 0 and was admitted (exit 101, captures=1, handle-bound=true). The fixed business exact, three slot units, fmt, and both strict Clippy drivers exit 0.
…ort order

Fresh two-parent merge of ef3c55d (private Lua callable registration and
generation release) with a4b3a43 (in-allocation reverse userdata order and
cross-batch FIFO). The only shared path is src/frontends/lua/heap/table.rs;
its merge is the exact clean three-way combination of both accepted lines.
All other union paths are inherited byte-for-byte from their owning parent.
No behavior is added beyond the two accepted parents: default RSS, Cargo
manifest and lock, CLI, and lowering remain unchanged.
First parent: 0289bd6
  tree b20c855
  accepted pending slot queue (unique parent 078e00b)

Second parent: 1381f3a
  tree 9acafce
  accepted raw __call carrier field (unique parent 4a48a54)

Common base: a4b3a43

Only the two frozen path sets are combined. The shared
src/frontends/lua/heap/table.rs was replayed independently in both
three-way directions before the merge and the result is byte-identical
in both directions. The other paths are one-sided and keep the sole
changing parent's blob. No slot-1 commit 64d6fbb is included.
Replace the ordinary Gray Vec with an intrusive doubly linked LIFO on the
slot records. Push, pop, and release write a constant number of neighbour
links and never allocate or copy. Release unlinks the exact node before the
slot generation advances, so a middle item cannot cut off its successors and
a reused slot cannot inherit a chain position. The head records the exact
slot generation.

Add test-only chain snapshots and access counters. Cover a filled push, a
pop, middle rollback with same-slot reuse, head/tail retirement, round-stamp
wrap, and abandon across rounds. Replace the late-boundary Vec shape check
with a real ordinary chain snapshot.
Reset now clears the rescan epoch, queued bit, and neighbour links of each slot in the existing per-slot unit, so a reused stamp cannot suppress a new round weak-to-strong rescan. The release path unlinks only a node that the current header or predecessor really names; a stale abandoned head clears only its own slot and never adopts its old successor. Add adjacent-epoch reuse tests for the skipped value and the empty-chain rollback.
Fresh two-parent merge of 9e7ff8a (Lua typed published-head closure read from
the raw call chain) with c753a41 (Lua late-target stamp reuse on release). The
only shared path is src/frontends/lua/heap/table.rs; its merge is the exact
clean three-way combination of both accepted lines, replaying 1 + 6
non-overlapping hunks. All other union paths are inherited byte-for-byte from
their owning parent. No behavior is added beyond the two accepted parents:
the Cargo manifest and lock, the production CLI, the Core consumer guard, and
both Cargo test harness entries remain unchanged.

Parent list after this identity transition: [9e7ff8a, c753a41]
The test plugin calls leave_roots on this commit's full RootFrameId after parent-after still borrows A and before the parent returns. The later guest sweep collects. The omission arm reaches that sweep without the exit call, so A and the root frame stay.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants