Repository navigation
Lua hot reload: real edits (constants first read, array literals, new generic specialisations); maps without InitBlizzard - #1553
Conversation
…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.
…trace depth as it was
…apart by their order
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
…t kept as they are added
… main skips InitBlizzard read no payload
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. |
…large map was quadratic
|
@codex review |
There was a problem hiding this comment.
💡 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
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! 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". |
Edits a real map makes now hot reload, and hot reload now works in a map whose
mainskipsInitBlizzard. 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_isSinglePlayerwas set, which only blizzard.j'sInitBlizzardGlobalssets. Castle Fight's ownmainnever callsInitBlizzard, so in the game a payload was written and never read, and nothing said so. The poll now counts the users playing itself, asInitBlizzardGlobalsdoes; in a game with more than one it prints once that hot reload is off, and the status says why (pollIsOffInAGameOfMoreThanOneUser). The tests setbj_isSinglePlayerthemselves 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-luaHotReloadare 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]tostring[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; nopairs). 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-luaHotReloadthere 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-comparableim1.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 -luaHotReloadbuild 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:
intstore kept its 101). Every payload which applied printed nothing it could not apply.-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, andbj_isSinglePlayerset 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@onHotReloadfunction (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