Skip to content

Jass: keep the ids of compile-time objects of new-generic classes - #1532

Merged
Frotty merged 2 commits into
masterfrom
fix-jass-compiletime-generic-object-ids
Oct 21, 2026
Merged

Frotty merged 2 commits into
masterfrom
fix-jass-compiletime-generic-object-ids

Conversation

@Frotty

@Frotty Frotty commented Oct 21, 2026

Copy link
Copy Markdown
Member

Problem

On Jass, a compile-time object of a new-generic class did not keep its compile-time id: at run time kept castTo int differed 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.emitCompiletimeObjectAllocs wrote firstFree/maxIndex of 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 makes ImTranslator.clearStaleClassManagementVars drop all allocator variables. getClassManagementVars then builds fresh ones for every group, so the replay wrote variables nothing read, and dead-code removal deleted the writes.

Change

  • The Jass replay names the class of each allocator write instead of its variables: two intrinsics, __wurst_clearObjectFreeList(C.typeId) and __wurst_setObjectIdMax(C.typeId, n), pinned until used. The generics specialise their class argument like any other, and EliminateClasses replaces each call with the write to that class's group (freeCount, maxIndex), once the groups exist.
  • The interpreter still numbers objects per erased group. The groups after the generics only divide those, so ids stay unique within each. With a new-generic class in the erased group, gaps are tracked per instantiation (class plus 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.
  • The Lua replay moves into its own method with identical output. docs/WC3_RUNTIME.md gets 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:

  • an id kept after dropped objects, and the next run-time id following the compile-time maximum (this replaces the Lua-only test);
  • two instantiations with interleaved allocations and destroys, checked against run-time objects, also with -inline -localOptimizations;
  • Box<int> and Box<string> joined to a plain class by an interface, including dispatch and run-time ids;
  • a stdlib HashMap<int, Box<int>> keyed by an id;
  • a plain class's compile-time object next to a new-generic class.

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/LLEntry now get the free-list reset and maxIndex writes, 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).

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 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-21T19:16:34.890901Z dc89f2a Manual request
ℹ️ 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 commented Oct 21, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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.
@Frotty

Frotty commented Oct 21, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: dc89f2aa96

ℹ️ 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".

@Frotty
Frotty merged commit f5001f1 into master Oct 21, 2026
2 checks passed
@Frotty
Frotty deleted the fix-jass-compiletime-generic-object-ids branch November 25, 2026 08:54
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