Skip to content

Check in unit tests that live Lua code uses no erased generic static - #1500

Merged
Frotty merged 1 commit into
masterfrom
lua-generic-static-coherence-check
Oct 20, 2026
Merged

Frotty merged 1 commit into
masterfrom
lua-generic-static-coherence-check

Conversation

@Frotty

@Frotty Frotty commented Oct 20, 2026

Copy link
Copy Markdown
Member

Follow-up to #1498.

What

After the Lua generics phase and the tree shaker (transformProgToLua), a function that is live through allocated classes must not read or write a generic static through its erased original once that static has specialised copies. If it does, one instantiation has two backing stores, and one is written where the other is read: the #1498 miscompile.

ImTranslator.assertNoLiveErasedGenericStatic() asserts this in unit-test mode only, like assertFlat and assertNoGarbage. It reports a violation as an internal CompileError naming the function and the static.

  • Where: right after TreeShaker.removeUnreachableFunctions. Later, the garbage removal deletes the write-only erased store, so the split shows up only as a dropped write, and a check at that point catches fewer cases.
  • Live: RemoveGarbage.reachableFunctions (allocation-based, same style as reachableMethods). Tree-shaker presence would report dead dispatch, for example the erased Box_read in tupleSpecializedInterfaceDispatchDoesNotRootErasedStaticInitializer.
  • Cost: it returns immediately when no generic static has a specialised copy. Over 316 Lua test compiles the median was 0.003 ms, 0.30 ms median when it walked, and 0.54 % of transformProgToLua time overall. Builds outside unit tests skip it.

Evidence

  • New test LuaBackendAuditTests.liveErasedGenericStaticFailsTheUnitTestCheck: it adds a read of the erased static to main and expects the error. It fails without the hook.
  • With Fix concrete generic stores behind erased Lua dispatch #1498's EliminateGenerics fix reverted to its previous version, all 26 failing GenericStore* tests stop at compile time with this error (Store_put/Store_read/Store_add/Store_pop on Store_values) instead of producing wrong output.
  • With the fix in place, all 613 tests of LuaBackendAuditTests, GenericStore*, TypeClassTests, FieldIterationTests, FastHashMapTests, LuaTranslationTests and DeterministicChecks pass. Run on Windows only; nothing in the change depends on the host.

After the Lua generics phase and the tree shaker, a function which is live
through allocated classes must not read or write a generic static through
its erased original once the static has specialised copies: one
instantiation would then have two stores (#1498). The check runs in unit-test
mode only, before the garbage removal hides the split as a dropped write, and
uses RemoveGarbage's allocation-based reachability so dead dispatch kept by
the tree shaker is not reported.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T13:58:42.004268Z 1dd0e7e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Frotty
Frotty merged commit a951412 into master Oct 20, 2026
2 checks passed
@Frotty
Frotty deleted the lua-generic-static-coherence-check branch October 20, 2026 14:27
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.

1 participant