Repository navigation
Jass: keep the ids of compile-time objects of new-generic classes - #1532
Conversation
On Jass a compile-time object of a new-generic class (Box<int>) did not keep its id: at run time `kept castTo int` differed from the id it had stored at compile time, so an id held by a compile-time hashtable or old-generic map pointed at another object. A compile-time object of a plain class lost its id too as soon as the program had any new-generic class. The replay of the compile-time objects wrote the allocator variables (firstFree, maxIndex) of the erased class's inheritance group before the generics were eliminated. The generics then make a class of each instantiation, and the class management variables are built anew for the groups after them, so every write went to a variable nothing read any more and was removed as dead, and each object took the next free id of its group. The replay now names the class of each write instead of its variables: __wurst_clearObjectFreeList(C.typeId) and __wurst_setObjectIdMax(C.typeId, n), whose class the generics specialise like any other, and the class elimination writes the variables of that class's group in their place. The interpreter still numbers the objects in the erased class's group, which the groups after the generics divide, so the ids stay unique; for a group with a new-generic class the gaps are tracked for each instantiation, and each allocator continues after the highest id of the erased group. Jass output is unchanged for programs without a new-generic class, and Lua output is unchanged. New CompiletimeTests run on Jass and Lua: the id kept after dropped objects, two instantiations with interleaved allocations and destroys (also with -inline -localOptimizations), instantiations joined to a plain class by an interface, run-time objects after the replay, a compile-time HashMap keyed by the ids, and a plain class's object next to a new-generic class.
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. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7375c8fa61
ℹ️ 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".
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".
The replay of compile-time objects advanced only the allocators of the instantiations it replayed an object of. Compile-time code numbers the objects of all instantiations of a new-generic class together, so a dropped temporary Box<string> could take id 1 while a kept Box<int> took id 2. Box<string>'s allocator then started from 0 on Jass, and the first run-time Box<string> got id 1, which a compile-time scalar could hold, where Lua's shared allocator gives it 3. An instantiation which only the run time allocates was not advanced either. Which classes the generics make of an erased group is known only after them, so the replay of a group with a new-generic class now ends with a call of an intrinsic of its own, __wurst_advanceObjectIds(n), for which the translator keeps the group's erased classes. The class elimination replaces the call by setting the maxIndex of each group that holds one of those classes or a class specialised from one (ImTranslator.canonical), in the order of the program's classes. Programs without compile-time objects of such a group get no call; groups without a new-generic class are replayed as before. testCompiletimeDroppedObjectOfOtherInstantiationKeepsItsIdUnused, on Jass and Lua, records a dropped Box<string>'s id at compile time and checks that the run-time Box<string> and Box<real> come after the compile-time ids.
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. 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". |
Problem
On Jass, a compile-time object of a new-generic class did not keep its compile-time id: at run time
kept castTo intdiffered from the id compile-time code stored, and the next run-time object could take an id a kept one already had. A compile-time hashtable or old-generic map keyed by such an id pointed at the wrong object. The same happened to a plain class's compile-time objects as soon as the program contained any new-generic class.CompiletimeFunctionRunner.emitCompiletimeObjectAllocswrotefirstFree/maxIndexof the erased class's group directly, before the generics are eliminated. Generic elimination then makes a class of each instantiation and removes the erased class, which makesImTranslator.clearStaleClassManagementVarsdrop all allocator variables.getClassManagementVarsthen builds fresh ones for every group, so the replay wrote variables nothing read, and dead-code removal deleted the writes.Change
__wurst_clearObjectFreeList(C.typeId)and__wurst_setObjectIdMax(C.typeId, n), pinned until used. The generics specialise their class argument like any other, andEliminateClassesreplaces each call with the write to that class's group (freeCount,maxIndex), once the groups exist.GenericTypes); otherwise per group, as before. Each allocator ends at the erased group's highest id, so ids dropped or destroyed at compile time, or taken by another instantiation, are never handed out again.docs/WC3_RUNTIME.mdgets one clause.Jass's runtime model is unchanged: one allocator per inheritance group.
Tests
New tests in
CompiletimeTests, on Jass and Lua, each failing on Jass without the change:-inline -localOptimizations;Box<int>andBox<string>joined to a plain class by an interface, including dispatch and run-time ids;HashMap<int, Box<int>>keyed by an id;Windows, bundled Lua 5.3,
-PallBackends: CompiletimeTests 69, GenericsTests 101, GenericsWithTypeclassesTests 119, ClassesTests 128, LuaBackendAuditTests 285, LuaTranslationTests 149, NewFeatureTests 42, DeterministicChecks 30, ImTranslatorPinnedFunctionsTests 2 and TreeShakerTests 25. The whole suite passed: 3,290 tests. CompiletimeTests' Jass outputs: 220 byte-identical, and the 45 that differ all come from programs with a new-generic class. Lua outputs are all identical.Real maps. Two large maps compile to byte-identical optimised Lua. One map's Jass changes as intended: its compile-time objects of the stdlib's new-generic
LinkedList/LLEntrynow get the free-list reset andmaxIndexwrites, which master silently dropped. That map shipped wrong ids for those objects on Jass. pjass accepts the new script.Not done: Linux and macOS.
Found while fixing the defects from the 19-21 Oct audit (#1528).