Repository navigation
Keep a compile-time object of a new-generic class out of its class's statics - #1528
Merged
Merged
Conversation
…statics An object of a new-generic class made at compile time (class Box<T:> with a field T value, kept by compiletime(build()) or a @compiletime global) was lost on both targets. Jass stopped with "Variable Box<integer>_compiletime not attached" in initCompiletimeState, and the Lua translation with "initCompiletimeState_0 uses the erased generic static Box<integer>_compiletime" in unit-test mode. A non-generic class worked. The global holding the object was traced to the object's trace, its allocation, which lies in class Box. EliminateGenerics.identifyGenericGlobals takes every global traced into a generic class for a static field of that class, so the holding global was specialised (and the original detached on Jass) while the compile-time state still wrote the original. The holding global is now traced to the program, as the globals for compile-time handles are: it holds one object and is no static of the object's class. The replay of the object's fields and allocation keeps the object's trace. testPersistCompiletimeNewGenericClass, which could only check the translation because of this, now runs the program on both targets. New tests cover the object kept by an expression and by a @compiletime global, a class with a @compiletime static T, two instantiations, a subclass of a generic class, an object held by an old-generic object, -inline -localOptimizations, and on Lua the id kept after dropped objects (#1504).
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. |
This was referenced Oct 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A compile-time object of a new-generic class broke both targets. With
class Box<T:>having a fieldT value, an@compiletimefunction returnsnew Box<int>withvalue = 5, thenlet kept = compiletime(build()), and the run time readskept.value:initCompiletimeState).CompiletimeFunctionRunner.globalForObject.initForcreated the global holding the object with the object's trace, which is its allocation inside classBox.EliminateGenerics.identifyGenericGlobalstreats a global traced into a generic class as one of its statics, so it specialised the holding global (and on Jass detached the original), while the compile-time state replay still wrote the original.Change
The holding global is traced to the program, as the globals for compile-time hashtables already are (
globalForHandle). The replay of the object's fields and its allocation still uses the object's trace. Nothing is filtered by name, and the classifier is unchanged.Tests
In
CompiletimeTests, on Jass and Lua, each failing without the change unless noted:testPersistCompiletimeObjectOfNewGenericClass);@compiletimeglobal holding such an object, with astatic int made, which takes theemitCompiletimeStatepath;testPersistCompiletimeNewGenericClass, which had only checked translation, "pending a separate attachment fix", and now runs the program;static Tper instantiation;Box<int>,Box<string>);-inline -localOptimizations;IntBox extends Box<int>), which already passed and is kept as coverage.Windows, bundled Lua 5.3,
-PallBackends: CompiletimeTests 64 (on master after #1525), GenericsTests 81, GenericsWithTypeclassesTests 119, LuaBackendAuditTests 285, LuaTranslationTests 149, NewFeatureTests 42, GenericSpecialisationMatrixTests 384, DeterministicChecks 29, all passing. Two large real maps compile to byte-identical optimised Lua, and one also to byte-identical Jass, with and without the change. Not done: Linux and macOS.Found, not fixed
Box<int>andBox<string>share one counter. The replay writes the erased class's allocator, while the specialisedBox⟪integer⟫gets allocator variables of its own. So a kept object'scastTo intat run time differs from its id at compile time. Lua keeps them (Lua: keep the ids of compile-time objects #1504). Fixing it needs one id space per instantiation in the interpreter and a replay of the specialised allocator.class Holder<T>andT itemholding aBox<int>, a chained readkept.item.valuefails in class elimination with "Could not find field array for Holder_item[...].Box_value". Reading through a local works.Found by a defect audit of the 19-21 Oct merges.