Repository navigation
Fix Jass field instanceof/typeId in generic classes, stable compile-time type ids, Reflection parity - #1519
Conversation
…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.
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. |
There was a problem hiding this comment.
💡 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.
|
@codex review |
There was a problem hiding this comment.
💡 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).
|
@codex review |
There was a problem hiding this comment.
💡 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.
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! 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". |
Fixes the open type-id and reflection defects from
BACKLOG.md, in three commits.1. Jass: a field read inside
instanceofandtypeIdin 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 inEliminateGenericsoverrode the visits ofImInstanceof,ImTypeIdOfObjandImDeallocwithout 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 matchedPlainat 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 (atypeId, or aReflectionnative). Only when compile-time code did,ImTranslatorkeeps the ids the classes had then and numbers the classes the generics add after them (TypeId.keeping).EliminateClassesand the allocators take that numbering. Jassinstanceofand 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)
typeIdToTypeName/instanceCount/maxInstanceCountused a binary search whose leaf never checked the id, so 0 answered for the first class andmaxTypeId() + 1for the last. Each leaf now checks it and any other number gets"unknown"/ 0, as on Lua.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.mdloses the three fixed entries. TheGetHandleIdentry 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.mdis updated.Validation
GenericsTests(five) and the reflection tests inLuaTranslationTests, which now also run in the interpreter and on Jass. Each fails without its fix.-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.Not done: Linux and macOS (PR CI covers Ubuntu only).