Skip to content

Fix Jass field instanceof/typeId in generic classes, stable compile-time type ids, Reflection parity - #1519

Merged
Frotty merged 5 commits into
masterfrom
jass-field-instanceof-generic
Oct 21, 2026
Merged

Frotty merged 5 commits into
masterfrom
jass-field-instanceof-generic

Conversation

@Frotty

@Frotty Frotty commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Fixes the open type-id and reflection defects from BACKLOG.md, in three commits.

1. Jass: a field read inside instanceof and typeId in a generic class (ad37505)

held instanceof Box<T>, held.typeId, and a local captured by a closure in a generic class failed Jass translation ("Could not find field array for this.G_held"). The collector of generic uses in EliminateGenerics overrode the visits of ImInstanceof, ImTypeIdOfObj and ImDealloc without visiting their operand. They now recurse, like every other visit there.

Generic elimination also left the program's cached type ids and subclass lists as they were before it added classes, so a type id read at compile time crashed Jass class elimination ("Could not get type-id for G⟪integer⟫"). Both generics entries now clear those caches.

2. Keep the type ids compile-time code read (d7097fd, for the Codex finding)

With the cache cleared, Jass numbered every class again, so compiletime(new Plain().typeId) no longer matched Plain at run time when instantiations sorting before it were added. Master crashed on the same program. The interpreter now 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 and numbers the classes the generics add after them (TypeId.keeping). EliminateClasses and the allocators take that numbering. Jass instanceof and dispatch use explicit id lists, so non-contiguous ids are fine there. Programs whose compile-time code reads no type id keep their numbering, which the existing reflection tests pin.

3. Reflection natives agree everywhere; a dead helper goes (8c4d4e5)

  • Jass typeIdToTypeName / instanceCount / maxInstanceCount used a binary search whose leaf never checked the id, so 0 answered for the first class and maxTypeId() + 1 for the last. Each leaf now checks it and any other number gets "unknown" / 0, as on Lua.
  • The interpreter counted one class's objects, gave the number ever made as the peak, and raised for an unknown id. It now keeps live and peak counts per allocator group, which is what both targets count, and answers the defaults.
  • EliminateGenerics.fillMissingTypeArgsFromScope (matching type variables by name) never filled anything in the whole suite while made to throw (3,256 tests), so it is removed.

BACKLOG.md loses the three fixed entries. The GetHandleId entry now says only what is shown: the remap's desync reason (#1181) was never measured, and the game's ids are no contract a program can index by. docs/WC3_RUNTIME.md is updated.

Validation

  • New regressions in GenericsTests (five) and the reflection tests in LuaTranslationTests, which now also run in the interpreter and on Jass. Each fails without its fix.
  • Windows, bundled Lua 5.3, with -PallBackends: Generics 78, LuaTranslation 149, Compiletime 50, NewFeature 42, the specialisation matrix PR tier 384, Interpreter 29, LuaBackendAudit 285, GenericsWithTypeclasses 119, TypeClass 72, Closure 68, DeterministicChecks 29, Classes 128, Interface 40, GenericsModule 6, GenericStoreGenerated 48, plus Optimizer 179, Bug 132, Module 37, FieldIteration 44, FastHashMap 15 and GenericStoreSpecialization 21 on the second commit. All pass.
  • Full suite with the helper made to throw: 3,256 tests, all pass.
  • Full specialisation matrix (36,864 cases) on the first commit: 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.
@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-21T13:08:03.260434Z 7d8b502 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.

@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: ad37505354

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

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.
…r; drop a dead helper

Jass's typeIdToTypeName, instanceCount and maxInstanceCount searched the type ids without bounds: the
search narrows to one id even for a number below the first or above the last, so 0 answered for the first
class and maxTypeId() + 1 for the last. Each leaf now checks the id, so any other number gets the default
("unknown", 0), as on Lua; it also covers the ids the generics leave unused when compile-time code read
type ids.

The interpreter counted the objects of the class alone and gave as maxInstanceCount the objects ever made,
and raised for an unknown number. It now keeps the live objects and their peak per allocator group, the
classes joined by inheritance, which is what both targets count, and answers the defaults for an unknown
number. reflectionNativesAnswerAsOnJass and reflectionAnswersDefaultsForNumbersWhichAreNoTypeId run in the
interpreter and on Jass too; each fails without its part of the change.

EliminateGenerics.fillMissingTypeArgsFromScope filled a type's missing type arguments from type variables
of the same name. Made to throw whenever it filled one, the whole suite (3,256 tests) never reached it, so
it goes with its call.
@Frotty Frotty changed the title Jass: specialise a field read inside instanceof and typeId in a generic class Fix Jass field instanceof/typeId in generic classes, stable compile-time type ids, Reflection parity Oct 21, 2026
@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: 8c4d4e5430

ℹ️ 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 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).
@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: 2310d49c26

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

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.
@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. Hooray!

Reviewed commit: 7d8b50207b

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

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