Repository navigation
Lua: keep the ids of compile-time objects - #1504
Merged
Merged
Conversation
A compile-time object kept its id on Jass only. The Lua compile-time state allocated each object from the shared allocator, so it got the next free id, and a compile-time value which had captured the id (castTo int, a stored id, an old-generics slot) pointed at another object or at none. The compile-time interpreter now hands out ids from one space on the Lua target, as Lua does, and the Lua compile-time state replays them the way the Jass one does: before each gap it empties the free list and sets the next id (__wurst_resumeObjectIds, printed as the two assignments to the allocator's chunk locals), and after the last object it continues after the highest id used at compile time. Jass output is unchanged. Present since class instances became integer ids on Lua (#1264), not from the shared allocator (#1493): the replay always set Jass's per-class maxIndex, which Lua never reads.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This was referenced Oct 20, 2026
Frotty
added a commit
that referenced
this pull request
Oct 21, 2026
…statics (#1528) An object of a new-generic class made at compile time (class Box<T:> with a field T value, kept by compiletime(build()) or a @compiletime global) was lost on both targets. Jass stopped with "Variable Box<integer>_compiletime not attached" in initCompiletimeState, and the Lua translation with "initCompiletimeState_0 uses the erased generic static Box<integer>_compiletime" in unit-test mode. A non-generic class worked. The global holding the object was traced to the object's trace, its allocation, which lies in class Box. EliminateGenerics.identifyGenericGlobals takes every global traced into a generic class for a static field of that class, so the holding global was specialised (and the original detached on Jass) while the compile-time state still wrote the original. The holding global is now traced to the program, as the globals for compile-time handles are: it holds one object and is no static of the object's class. The replay of the object's fields and allocation keeps the object's trace. testPersistCompiletimeNewGenericClass, which could only check the translation because of this, now runs the program on both targets. New tests cover the object kept by an expression and by a @compiletime global, a class with a @compiletime static T, two instantiations, a subclass of a generic class, an object held by an old-generic object, -inline -localOptimizations, and on Lua the id kept after dropped objects (#1504).
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.
On Lua, an object made at compile time got a new id at run time, so a compile-time value which had captured its id (
castTo int, a stored id, an old-generics slot) pointed at another object or at none. Jass kept the id.Repro (interpreter and Jass pass, Lua failed):
Cause
CompiletimeFunctionRunner.emitCompiletimeObjectAllocsreplays each compile-time allocation by setting the class group'smaxIndexbefore it. Lua never reads those variables: all classes allocate from one counter and one free list (__wurst_objectMax,__wurst_objectFreeCount). The Lua state init was therefore justA_compiletime = A:create(), which took the next free id. The compile-time interpreter also handed out ids per inheritance group, as Jass does, so ids of unrelated classes would have collided in Lua's single id space anyway.This dates from #1264, when Lua class instances became integer ids. It was not introduced by the shared allocator (#1493), which already used the one counter.
Fix
ProgramState.useOneObjectIdSpace), matching the runtime.__wurst_resumeObjectIds(n), a backend intrinsic matched by node identity, like the otherluaRaw*stubs. The backend prints it as__wurst_objectFreeCount = 0followed by__wurst_objectMax = n. After the last object it continues after the highest id used at compile time. This is what the Jass replay does per allocator.Intentional difference
On Lua, an object made at run time comes after the highest compile-time id of any class. On Jass it comes after the highest id in its own inheritance group.
testCompiletimeObjectIdMigrationSharesOneIdSpaceOnLuacovers the Lua side; the existing...MigrationStressstill covers Jass's per-group allocators.Tests
testCompiletimeObjectKeepsIdAfterDroppedObject(Jass + interpreter + Lua). It also checks the emitted Lua replay: the id stored at compile time is__wurst_objectMax + 1at thecreate.testCompiletimeObjectIdMigrationnow also runs on Lua.testCompiletimeObjectIdMigrationSharesOneIdSpaceOnLua: two classes, 200 rounds with recycling, ids kept and distinct across classes, and new objects at max + 1 and max + 2.CompiletimeTests(50),LuaBackendAuditTests(242),LuaTranslationTests(144),DeterministicChecks(27) andImTranslatorPinnedFunctionsTests(2), all green.