Skip to content

Keep a compile-time object of a new-generic class out of its class's statics - #1528

Merged
Frotty merged 1 commit into
masterfrom
fix-compiletime-generic-object
Oct 21, 2026
Merged

Frotty merged 1 commit into
masterfrom
fix-compiletime-generic-object

Conversation

@Frotty

@Frotty Frotty commented Oct 21, 2026

Copy link
Copy Markdown
Member

Problem

A compile-time object of a new-generic class broke both targets. With class Box<T:> having a field T value, an @compiletime function returns new Box<int> with value = 5, then let kept = compiletime(build()), and the run time reads kept.value:

  • Jass: the generated script read a global that was no longer in the program ("Variable Box_compiletime… not attached" in initCompiletimeState).
  • Lua: translation stopped at the unit-test check "initCompiletimeState_0 uses the erased generic static Box_compiletime".

CompiletimeFunctionRunner.globalForObject.initFor created the global holding the object with the object's trace, which is its allocation inside class Box. EliminateGenerics.identifyGenericGlobals treats 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:

  • the repro (testPersistCompiletimeObjectOfNewGenericClass);
  • an @compiletime global holding such an object, with a static int made, which takes the emitCompiletimeState path;
  • testPersistCompiletimeNewGenericClass, which had only checked translation, "pending a separate attachment fix", and now runs the program;
  • a static T per instantiation;
  • two instantiations (Box<int>, Box<string>);
  • held by an old-generic container;
  • with -inline -localOptimizations;
  • a Lua-only check that Lua: keep the ids of compile-time objects #1504's id replay still works for a generic class;
  • a subclass of a generic class (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

  • Jass loses the compile-time ids of new-generic objects. The interpreter numbers ids per inheritance group of the erased class, so Box<int> and Box<string> share one counter. The replay writes the erased class's allocator, while the specialised Box⟪integer⟫ gets allocator variables of its own. So a kept object's castTo int at 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.
  • Jass, unrelated to compile time: with class Holder<T> and T item holding a Box<int>, a chained read kept.item.value fails 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.

…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).
@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-21T16:51:31.432004Z 497ddbc 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 merged commit 80d8032 into master Oct 21, 2026
2 checks passed
@Frotty
Frotty deleted the fix-compiletime-generic-object 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