Skip to content

Jass: field instanceof/typeId in generic classes, and type ids compile-time code read stay - #1520

Closed
Frotty wants to merge 5 commits into
masterfrom
jass-generic-type-ids
Closed

Frotty wants to merge 5 commits into
masterfrom
jass-generic-type-ids

Conversation

@Frotty

@Frotty Frotty commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Split out of #1519, which this replaces together with #1521 and #1522. The changes are unchanged; #1519's four Codex rounds reviewed them.

Problem

  1. On Jass, a field read inside instanceof or typeId in a new-generic class failed translation ("Could not find field array for this.G_held"). The same happened for a local captured by a closure. The collector of generic uses in EliminateGenerics overrode the visits of ImInstanceof, ImTypeIdOfObj and ImDealloc without visiting their operand.
  2. Generic elimination left the program's cached type ids and subclass lists in place after adding classes. A type id read by compile-time code then crashed Jass class elimination ("Could not get type-id for G⟪integer⟫").
  3. Renumbering after the generics would make a type id stored at compile time (compiletime(new Plain().typeId)) stale. That happens on Jass when instantiations sort before the class, and on Lua when an unused class before it is dropped.
  4. A type id of a new-generic class read at compile time can be right on Lua, where instantiations share their class's id, but never on Jass, which makes a class of each instantiation after compile time. Master crashed on it.

Change

  • The three visits recurse, and both generics entries clear the class caches when they finish.
  • The interpreter records whether the program read a type id (a typeId, or a Reflection native). Only when compile-time code did, ImTranslator keeps the ids the classes had then. The classes the generics add are numbered after them (TypeId.keeping), on Jass in EliminateClasses and the allocators, and on Lua in LuaTranslator.typeIds(). Jass instanceof and dispatch take id lists, so the ids need not be contiguous. Programs whose compile-time code reads no type id keep their numbering.
  • On Jass, a type id of a new-generic class read at compile time is a compile error at the read, telling the user to read it at run time.
  • GenericSpecialisationMatrixTests reads the field directly in its instanceof cases. BACKLOG.md drops the Jass entry and rewrites the GetHandleId entry to claim only what is shown. docs/WC3_RUNTIME.md records the kept ids.

Tests

GenericsTests gains 8 regressions, each failing without its fix: field instanceof, a captured local, field typeId, a compile-time typeId read, a stored id against instantiations, a stored id against an unused class, and the generic instantiation case (an error on Jass, correct on Lua).

Validation: see the results at the end.

Validation (Windows, bundled Lua 5.3, -PallBackends): GenericsTests 81, LuaTranslationTests 149, CompiletimeTests 50, NewFeatureTests 42, GenericSpecialisationMatrixTests 384, InterpreterTests 29, LuaBackendAuditTests 285, DeterministicChecks 29, ClassesTests 128, GenericsWithTypeclassesTests 119, all passing. On #1519 (this change plus the other two): the full suite, 3,259 tests, and the full specialisation matrix, 36,864 cases with no failures. Not done: Linux and macOS (PR CI covers Ubuntu only).

…ic class

The collector of generic uses overrode the visits of ImInstanceof, ImTypeIdOfObj and ImDealloc without
visiting their operand, so in a generic class `held instanceof Box<T>`, `held.typeId` and a captured local
in a closure kept the unspecialised field and Jass class elimination found no field array for it.

Generic elimination also left the program's cached type ids and subclass lists as they were before it
added the specialised classes. Compile-time code fills them (a typeId read through the interpreter), so
the Jass build then found no type id for an instantiation's class. Both generics entries now clear them.

The specialisation matrix reads the field in its instanceof cases directly instead of through a local
copy. BACKLOG.md drops the fixed Jass entry, and the GetHandleId entry says what is and is not shown: the
remap's desync reason was never measured, and the game's ids are no contract a program can index by.
Clearing the cached type ids made Jass number every class again after the generics, so a type id which
compile-time code had stored as a constant (`compiletime(new Plain().typeId)`) no longer matched the class
when the instantiations of a generic class sort before it. Before, the stale cache crashed the build
instead.

The interpreter now records whether the program read a type id (a typeId, or a Reflection native). When
compile-time code did, the translator keeps the ids the classes had then, numbers the classes the generics
add after them (TypeId.keeping), and class elimination and the allocators take that numbering. A program
whose compile-time code reads no type id keeps the numbering it had. The Jass instanceof checks and the
dispatch take a list of ids, so the ids need not be contiguous.
The Lua translation numbered its classes again from the ones the script keeps, so a type id compile-time
code had stored no longer matched its class when a class sorting before it was dropped as unused. Lua now
takes the ids remembered when compile-time code read them, as Jass does (TypeId.keeping along the nominal
superclasses).
Compile-time code sees one class for all the instantiations of a new-generic class, as Lua does; Jass makes
a class of each instantiation after compile time. A type id compile-time code read of such a class is so the
id of none of them, and the Jass build put it into the script as if it were. (Before the type ids were
kept, the build crashed on it.) The interpreter now records where compile-time code first read the type id
of a new-generic class, and the Jass numbering stops with an error there when the generics replaced the
class. Lua keeps one class for the instantiations, so the id stays right there, which a test pins.
@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-21T14:03:42.785432Z 1534b6c 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 commented Oct 21, 2026

Copy link
Copy Markdown
Member Author

Superseded by #1519, which was merged with the same changes before this split was finished.

@Frotty Frotty closed this Oct 21, 2026
@Frotty
Frotty deleted the jass-generic-type-ids branch October 21, 2026 14:01

@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: 1534b6c8b3

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



public ILconstString typeIdToTypeName(ILconstInt typeId) {
interpreter.noteTypeIdsRead();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject generic IDs discovered through reflection

When compile-time code discovers an ID by iterating through maxTypeId() and calling typeIdToTypeName(i), this records only the blanket read flag and never adds the resolved ImClass to genericTypeIdReads. For a new-generic Box<T:>, Jass therefore misses the intended diagnostic: TypeId.keeping leaves the pre-specialization Box ID as an unused gap and assigns Box<int> a later ID, so a discovered and stored constant silently refers to no runtime class. Record the resolved class via noteTypeIdRead (or otherwise reject this indirect read).

AGENTS.md reference: AGENTS.md:L67-L70

Useful? React with 👍 / 👎.

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