Repository navigation
Lua: shared allocator and init error handler, class metadata only when read - #1493
Merged
Merged
Conversation
Each package init passed its own copy of the same two-closure error handler to xpcall. The handler is now one function, __wurst_init_error, defined once and passed by name; its text is unchanged.
Every class got a create method holding its own copy of the allocator. A class whose allocation only takes an id and records its class (no array field to make a table for, no default which survived at an allocation) now has none: its allocations call __wurst_allocObject(C), a main-chunk local like __wurst_deallocObject. A class which writes fields on allocation keeps its own create, so it gains no extra call.
Every class table got a __wurst_supertypes table and a __typeId__, read only by instanceof and by the type id of an object. The translator now looks for those two reads in the program and emits the supertypes (with isInstanceOf) and the type ids only when it has them.
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. |
Frotty
added a commit
that referenced
this pull request
Oct 20, 2026
A compile-time object kept its id on Jass only. The Lua compile-time state allocated each object from the shared allocator, so it got the next free id, and a compile-time value which had captured the id (castTo int, a stored id, an old-generics slot) pointed at another object or at none. The compile-time interpreter now hands out ids from one space on the Lua target, as Lua does, and the Lua compile-time state replays them the way the Jass one does: before each gap it empties the free list and sets the next id (__wurst_resumeObjectIds, printed as the two assignments to the allocator's chunk locals), and after the last object it continues after the highest id used at compile time. Jass output is unchanged. Present since class instances became integer ids on Lua (#1264), not from the shared allocator (#1493): the replay always set Jass's per-class maxIndex, which Lua never reads.
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.
Three changes to what the Lua backend emits. None changes what a Wurst program does; each removes code the script carried for every class or every package.
Changes
xpcall. It is now one function,__wurst_init_error, passed by name. Its text is unchanged.createmethod with its own copy of the allocator. A class whose allocation only takes an id and records its class (no array field needs its table, no field default survived at an allocation) now has none. Its allocations call__wurst_allocObject(C), a main-chunk local like__wurst_deallocObject. A class which writes fields on allocation keeps its owncreate, so it gains no extra call.__wurst_supertypestable and a__typeId__. Onlyinstanceofand the type id of an object read them. The translator now looks for those two reads (ImInstanceof,ImTypeIdOfObj, both made before Lua emission) and emits the supertypes (withisInstanceOf) and the type ids only when the program has them.Only the three Lua translation files change, so Jass output is not affected.
Effect on two large maps
Built with
-lua -inline -localOptimizations:On map A, 1,140 fewer tables are built at init. Map A reads no class metadata, so all of it goes. Map B uses
instanceof, so it keeps its supertypes; it reads no object type id, so its type ids go.For both maps, the old output was rewritten the way the change should rewrite it: shared-allocator classes lose
createand their calls become__wurst_allocObject(C), the inline handlers become the shared one, and unread metadata goes. After that rewrite, the only remaining differences from the new output are the two new helper definitions and renumberedcreateNnames (plus a build timestamp).luacaccepts both scripts.Verification
packageInitsShareOneErrorHandler,classesWhichOnlyAllocateShareOneAllocator(allocation, destroy, id reuse, dispatch and array fields at run time),classMetadataIsEmittedOnlyForTheReadsWhichNeedIt(with and withoutinstanceofand type ids, at run time).__wurst_allocObject(C). Three tests whose subject is acreatemethod or the metadata placement got programs that need them (an array field, aninstanceof, an object type id).LuaBackendAuditTests,LuaTranslationTests,ObservableEffectsTests,FastHashMapTests,TypeClassTests,DeterministicChecks,FieldIterationTests,LuaKeyedMapTests,ClassesTests,NewFeatureTests,GenericsTests,GenericsWithTypeclassesTests,CompiletimeTestspass locally (Windows). The full suite and the other platforms are left to CI.Behaviour note
Raw Lua bundled with a map which reads a class table's
create,__wurst_supertypesor__typeId__would no longer find them where they are not needed. These are internal to the emitted script, and foreign code touching emitted structures is outside what the backend supports.