fix(stdlib): route cache_module_result through Table.put so required modules appear in pairs(package.loaded)#356
Merged
Conversation
… modules are visible to pairs The package.loaded cache wrote the required module's key directly into loaded_table.data via Map.put, bypassing Table.put and its iteration-order bookkeeping. Key-access (package.loaded[name]) still worked, but the key never entered the order/memo maps, so a freshly required module was invisible to `for k in pairs(package.loaded)`. This was fixed on the perf/table-hash-iteration branch but the PR (#349) was squash-merged from a stale head that predated the fix, shipping the bug to main. Re-applies the one-line stdlib fix plus the pairs-visibility regression test, the table-iteration memo-invalidation/replace_data coverage, and the pairs_hash benchmark, all of which were stranded on the merged branch. Co-authored-by: Dave Lucia <dave@tvlabs.ai>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Route
Lua.VM.Stdlib.cache_module_result/3throughTable.put/3instead of writingTable.datadirectly, so a freshlyrequire()d module is visible tofor k in pairs(package.loaded).Why this is a separate PR
This fix was developed on the
perf/table-hash-iterationbranch (#349) during review, but #349 was squash-merged from a stale head (128c73e) that predated the fix commit, so the correction never reachedmain. The bug is therefore live inmaintoday:cache_module_result/3was the only writer ofTable.dataoutsidetable.ex. The direct map write bypasses theorder/order_tailand memoized iteration-order bookkeeping that #349 introduced, so the new module key is reachable by direct index (package.loaded.foo) but never enumerated bypairs.The fix
One line — route the write through the single maintained mutation path:
Coverage
test/lua/vm/stdlib/package_test.exs— load-bearing regression test: a newlyrequired module is seen by a fullpairs(package.loaded)walk (fails on the direct-write form, passes throughTable.put).test/lua/vm/table_iteration_test.exs— memo-invalidation / absorb-after-flush /replace_datareset coverage for the iteration-order machinery.benchmarks/table_ops.exs— apairshash-arm benchmark exercising the O(1)-per-step advance path.Scope is deliberately limited to the stranded fix; unrelated commits that were on the perf branch (and already in
main) are excluded.🤖 Surfaced by an adversarial multi-lens review pass.