Skip to content

Lua hot reload: real edits (constants first read, array literals, new generic specialisations); maps without InitBlizzard - #1553

Merged
Frotty merged 16 commits into
masterfrom
lua-hot-reload-real-edits
Oct 24, 2026
Merged

Frotty merged 16 commits into
masterfrom
lua-hot-reload-real-edits

Conversation

@Frotty

@Frotty Frotty commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Edits a real map makes now hot reload, and hot reload now works in a map whose main skips InitBlizzard. Replaying Castle Fight's history as hot reloads ranked the causes of refusals (#1551, docs/LUA_HOT_RELOAD.md "Edits of a real project"); this fixes the largest, and one found running Castle Fight with hot reload in the game. Design and limits: docs/LUA_HOT_RELOAD.md.

A map whose main skips InitBlizzard read no payload

The poll returned unless bj_isSinglePlayer was set, which only blizzard.j's InitBlizzardGlobals sets. Castle Fight's own main never calls InitBlizzard, so in the game a payload was written and never read, and nothing said so. The poll now counts the users playing itself, as InitBlizzardGlobals does; in a game with more than one it prints once that hot reload is off, and the status says why (pollIsOffInAGameOfMoreThanOneUser). The tests set bj_isSinglePlayer themselves before each poll, which is how this was missed; they now stub one user playing instead, so every executing hot reload test covers it.

Constants first read, or no longer read

A hot-reload build keeps the storage of every global of the source (ImTranslator.isHotReloadSourceGlobal, a root of the tree shaker, the optimiser's garbage removal and the Lua garbage removal). The dead-code removal dropped the storage of a global nothing read, so starting or stopping to read one changed its initializer's storage between [] and [x], and the payload refused it (startingToReadAGlobalKeepsItsStorage, stoppingToReadAGlobalKeepsItsStorage). A newly read constant has the value the map gave it at the start. Builds without -luaHotReload are unchanged (unreadGlobalsAreRemovedWithoutTheFlag).

Array literals

An array constant's identity has its dimensions, not their sizes: a Lua array is a table of any length, so string[74] to string[75] is no change of type, while an entry type change still is. An edited literal runs again like a tuned constant, rewriting its entries in the table the map has and clearing indices past its new length (the payload knows the last length the map ran, __wurst_hotreload_constantLengths; no pairs). An array other code writes keeps its value with the warning (ConstantInitializers.writtenElsewhere). Tests: editedArrayLiteralsReachTheRunningMap (with and without -stacktraces), arrayConstantHoldsTheEntriesOfEachPayload, arrayLiteralEntryTypeChangeIsRefused, arrayConstantCodeWritesKeepsItsValue.

A new type argument of a generic class with statics

Each specialisation of a generic static is an initializer unit of its own, made where generic elimination creates the specialised storage (ImTranslator.addSpecializedGlobalInitializer). A first use with another type argument is a new unit which runs once; the others keep their values (newSpecializationOfAGenericStaticIsInitializedAlone, removedSpecializationOfAGenericStaticKeepsTheOthers). The initial values are computed as before, the same number of times and in the same order: an initializer of several values of which one has an effect (an array literal of calls) stays one unit, since units would compute all of one specialisation first (effectfulGenericArrayInitializerKeepsItsOrder); without -luaHotReload there are no units and the output is unchanged (1,565 of 1,567 emitted files of the generics test classes byte-identical, the two others the never-comparable im1.j/im2.j).

Faster hot-reload builds

The manifest looked up the storage of each initializer through every specialisation and every global (loweredGlobalStorage), and the constant analysis did so twice more: quadratic in a large map. The storage is now indexed once per pass (ImTranslator.GlobalStorage). A -lua -luaHotReload build of Castle Fight took 154 s, 105 s of it in "translate to lua" (71% of the samples of a profile in that lookup); it now takes 39 s, 4.4 s of it in that phase, and its Lua and manifest are byte-identical. The lookup was quadratic before this PR too: master builds it in 117 s, 62.5 s in that phase. Keeping every global's storage costs Castle Fight's hot-reload script 2.7 MB (23.5 to 26.3 MB; development builds only).

Evidence

The replay of Castle Fight's last 30 commits with this branch is running; its results follow in this description.

In the game, on the 3.0.1.24371 client, single player:

  • The test map's suite with an eleventh payload: a constant nothing read is read, an array literal grows and has an entry changed, and a generic class with a static is used with a new type argument. PASS, 58 of 58 checks across eleven payloads in one game: the constant read for the first time has the value the map gave it at the start (33), the grown and changed literal sums to 64, and the new specialisation's static was initialised alone (the count 2, the int store kept its 101). Every payload which applied printed nothing it could not apply.
  • Castle Fight itself, built with -lua -luaHotReload -dev (with the compiler of Lua hot reload: callbacks told apart by their order reload, @onHotReload hooks, smaller payloads #1551, before this PR, and bj_isSinglePlayer set by the map's probe): four payloads in one game, all applied and printing nothing they could not apply: a function body (652 bytes, in the map 0.5 s after the file was written), two tuned constants in gameplay packages (2,285 bytes, the production function reading one returned the new value), an added @onHotReload function (2,940 bytes, ran once), and the first edit undone (the original body back, the constants kept). Almost all of the 90 to 143 s from asking to applying was the build.

Unit tests, Windows: LuaHotReloadTests (120), DeterministicChecks (38), LuaBackendAuditTests (297), LuaTranslationTests (152), GenericsWithTypeclassesTests (128), NewFeatureTests (42), TreeShakerTests (25), HotReloadPipelineTests (6), LuaExemptionTests (6). Each new test fails before its change.

Not covered

  • Closures removed, or inserted before others told apart by their order, still need a restart.
  • The editor's part (the language server's hot run) was not measured again.
  • Linux is covered by PR CI; macOS is unverified.

Frotty added 14 commits October 24, 2026 13:34
…oad hooks, smaller payloads

- Closures which share an identity are no longer frozen: editing their bodies and appending one reload; a move (a
  closure now with another's source) and a removal still need a restart. Identities name enclosing classes.
- Functions annotated @onHotReload run after each payload installed everything else; static, no parameters. Entry
  points only in -luaHotReload builds. With -stacktraces the payload passes them a position.
- A payload lists the initializer order only when an edit swaps the started map's initializers, and guards storage only
  for units with storage the started map lacks: a no-change Castle Fight payload went from 403,624 to 93 bytes.
A hot-reload build's garbage removal, tree shaker and Lua garbage removal
dropped the storage of a global nothing reads but kept its initializer unit,
so an edit which starts or stops reading a constant (or a variable only
updated from itself) changed the unit's storage between [] and [x], and the
payload refused it. Such globals are now roots in all three passes
(ImTranslator.isHotReloadSourceGlobal), only with -luaHotReload. The test
runtime gains the two frame natives the stdlib's Framehandle initializers
call, which now run in a hot-reload build.
An array literal's length was part of its identity (string[74] to
string[75]), so adding an entry to a configuration table refused the
payload. The identity now keeps the dimensions and the entry type, not
the sizes. An array constant whose initializer writes one dimension at
constant indices is tuned like any other constant: the payload runs its
initializer again in place and clears, by index, the entries past the
new length which the map's last run wrote (recorded in the map, else the
baseline's). Constants computed from its elements follow. An array
constant which other code writes is listed with the variables and keeps
its value, with the warning.
…its of their own

A static of a new-generic class had one source initializer unit which initialised the storage of every
specialisation, so a first use of the class with another type argument (or the removal of the last use of
one) changed that unit's storage and the payload was refused. Generic elimination now gives each
specialisation's initial value a unit of its own where it makes the specialised storage, called right after
the source unit in discovery order, so values are computed once per specialisation in the same order as
before (and as on Jass). Builds without -luaHotReload are unchanged.
…eal-edits

# Conflicts:
#	docs/LUA_HOT_RELOAD.md
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 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-24T13:53:05.497596Z 9f19322 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.

@Frotty

Frotty commented Oct 24, 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: a0e0b613ad

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

… effect stays one unit, in the order the program computes them
@Frotty

Frotty commented Oct 24, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 9f19322914

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

@Frotty
Frotty merged commit e94e3c3 into master Oct 24, 2026
2 checks passed
@Frotty
Frotty deleted the lua-hot-reload-real-edits 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