Repository navigation
Lua hot reload: tuned constants take their new values; fixes from an in-game run - #1550
Conversation
…in-game run A changed initial value of a constant which only computes its value runs again in the running map, and so do the constants computed from it; variables, allocating or impure initializers and array constants keep their values with the warning as before. Running every kind of edit in the game found four defects, each fixed with a test: - a closure in a package's init block crashed every -luaHotReload build (the standard library's Preloader has one); - a closure in a constructor crashed it the same way; - with -stacktraces a moved line counted as a change of closures told apart by their order, so any edit above them was refused; - a global added to a package which starts before another made every later payload warn that the initializer order changed. A session can be driven without the editor (LuaHotReloadSession start/send), and a payload's status carries what it printed it could not apply.
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ab3a4da6d8
ℹ️ 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".
…eeps a constant's value Code may assign an element of a constant array, so a constant computed from one keeps its value. A variable need not have an initializer, so former variables are tracked by their storage (Manifest.variables, History.variables) rather than by initializer.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 09d49666f8
ℹ️ 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".
…ariable keeps its value A constant computed by a pure function runs again when that function changes: the manifest lists the functions each constant's initializer calls, and their shapes are part of the revision the map records. A constant whose own storage was a variable in a version the map ran keeps its value, as the constants computed from it already did.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5b53be90f6
ℹ️ 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".
…rguments alone The optimiser's list of pure natives has getters of game state (GetPlayerTeam, GetWorldBounds, GetUnitDefault*), which a payload could find changed since the start. Hot reload allows only natives whose result depends on their arguments, and the conversions to constant handles.
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! 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". |
Tuning a constant now reaches the running map, and four hot reload defects found by running every kind of edit in the game are fixed. Design and limits:
docs/LUA_HOT_RELOAD.md("Constants", "Measured in the game").Tuned constants
A changed initial value of a constant (
constant,let, a@configoverride of one, astatic constant) runs again in the running map when it only computes its value, and so does every constant computed from it, in initialisation order. Nothing but its initializer writes a constant, so it gets the value a restarted map would give it.ConstantInitializersdecides which initializers may run again: they read their own locals, constants initialised before them and the game's constants, write only their own global, and call natives whose result depends on their arguments alone (not getters of game state such asGetPlayerTeam), the backend's operator intrinsics and functions which follow the same rules. The stack-trace bookkeeping does not count. A constant also runs again when a function it calls changes: the functions are part of the revision the map records.__wurst_hotreload_constants), so an undone edit runs the original again, a missed payload changes nothing the map has, and a constant a payload added follows later edits. A constant whose storage the baseline or an earlier payload declared as a variable, initialised or not, keeps its value, and so does every constant computed from one (Manifest.variables,History.variables).Fixes found in the game
Each has a test which fails before its fix:
initblock crashed every-luaHotReloadbuild with "unhandled case: InitBlockImpl" (from Lua hot reload: preserve named closure identities across sibling additions #1549). The standard library'sPreloaderhas one, so hot run of a Lua map with the standard library did not build. The owner of such a closure is now its package (closuresInAnInitBlockAreNamedAndReloaded).closuresInAConstructorAreNamedAndReloaded).-stacktraces, a call passes its source position, so a moved line changed the bodies below it. Closures told apart by their order alone have protected bodies (Lua hot reload: preserve named closure identities across sibling additions #1549), so any edit above them was refused. Comparisons of what must not change or what already ran now leave the positions out (Function.shape); the payload still ships the new positions (movedLinesDoNotFreezeClosuresToldApartByOrder).addedGlobalBeforeALaterPackageIsNoReorder).Also:
LuaHotReloadSession start|send <build dir> <CustomMapData>after a-build ... -luaHotReload.__wurst_hotreload_status()) carries what it printed it could not apply, and the kept-value message names the global rather than its initializer function.Evidence
Measured on the 3.0.1.24371 client, single player, in a test map built with
-build ... -lua -luaHotReloadand a project's default run arguments (-runcompiletimefunctions -injectobjects -stacktraces), its session driven by the new command line. Nine payloads in one game, 44 checks, all passed:ondestroy, string escapes, staticI2S"lvl7", the real 250; the variable kept 5A thread waiting in
TriggerSleepActionthrough phase 1 resumed in its old body and then called the new one by name. Every payload which applied printed nothing but "applied payload n". A payload arrived 25 to 51 s after the map asked for it, almost all of it the build.The runs, in order: before the fixes the map did not build (the
initblock crash, then the constructor one); with those fixed, phases 5 to 9 were refused (moved lines); with that fixed, every payload from phase 5 printed the order warning; then 44 of 44. After the review rounds below, the suite ran again on the final head (bef18f1f4): 44 of 44.Unit tests, Windows:
LuaHotReloadTests(91) andDeterministicChecks(37, including the constants manifest across unit orders) on the final head;LuaBackendAuditTests(297),LuaTranslationTests(152),ClosureTests(68),HotReloadPipelineTests(6) andRunArgsTests(5) on5b53be90f, before the last change, which only narrows the natives a constant may call.Review
Codex found five more cases where a constant could run again from a value a restart would not give it, each fixed with a test which fails before the fix: a read of a constant array's element, a former variable declared without an initializer, a variable made a constant (now it keeps its value, as the constants computed from it already did), a constant computed by a function whose body changed (it did not follow), and getters of game state in the optimiser's list of pure natives. That list is unchanged here, since the optimiser uses it.
Builds without
-luaHotReloadare unchanged by construction: every change is behind the flag (the stack-trace globals are only recorded). No large-map byte comparison was run for this PR.Not covered
wurst.hotreload) was not measured again; the in-game run builds from the command line. Linux is covered by PR CI; macOS is unverified.init, a timer's period): that needs the library reload hook.doAfter(...) ->callbacks, say) is still refused, by Lua hot reload: preserve named closure identities across sibling additions #1549's protection against swaps. Allowing it when the group's size is unchanged and only one of its closures changed (a swap changes two) would keep that protection; left for a decision.