Skip to content

Lua hot reload: removed closures, classes and callbacks apply with a warning - #1556

Merged
Frotty merged 3 commits into
masterfrom
lua-hot-reload-removal-warns
Oct 24, 2026
Merged

Frotty merged 3 commits into
masterfrom
lua-hot-reload-removal-warns

Conversation

@Frotty

@Frotty Frotty commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Removing a closure, a class or a callback no longer needs a restart: the payload applies and warns what keeps the old body. This changes what a payload refuses, so it is a PR of its own.

Before

A payload refused when something a running map may still hold was no longer bound by any function of the edit:

  • "function X was removed but is stored as a value (in register), which keeps the old body": a removed callback registered through a native, or a removed closure whose class table objects still hold.
  • "function X lost bindings which may remain stored (in class-table slot C.s), which keeps the old body": a class-table slot nothing binds any more, typically because its class was removed. One shared function then loses the slot of every removed class: destroyForGroupCallback lost the __wurst_destroy slots of the ForGroup closures an edit removed.

In Castle Fight's history this was in 7 of the commits still refused, so removing any closure, class or callback meant a restart.

Now

The payload applies, with a warning per function in payload.warnings(), which the editor shows:

  • function <name> was removed, but what the map made before keeps its old body (<places>): restart the map to drop it.
  • function <name> changed, but what the map made before keeps its old body (<places>): restart the map to drop it. for a surviving function whose body changed and which left a slot.

What the map made before (a timer's or listener's closure object, a callback registered with the engine) keeps running the old body until it is gone or the map restarts; the new code cannot reach it. A class table is flat (every inherited method is assigned, no __index chain), so a slot no function binds is never dispatched by the new program. This is how the payload already treats what it cannot apply, such as a changed package init: a warning to restart, not a refusal.

The editor (the language server's hot reload) shows a payload's warnings as one note (LuaHotReloadSession.warningNote, payloadWarningsAreOneNote): removing a class warns once for each of its methods, which were as many notifications.

Unchanged: every check about closures told apart by their order (moves, removals within an order group), and the refusal of a changed function which a running version stores as a value, since the new code still reaches that value. A surviving function whose body is unchanged warns of nothing: the slots it left still hold that very body (it was refused before).

Evidence

Replaying Castle Fight's last 30 commits which change Wurst code: 23 accepted, up from 21 on master with #1555; the two commits refused only for removed closures (and the slots the removed classes left) now apply with the warning. Of the 7 still refused, 6 insert a closure before others told apart by their order and 1 changes a global's type. The docs' "Edits of a real project" now has the replay with each of today's changes, and BACKLOG.md a proposal for the order-group insertions, which need a decision on a trade-off.

In the game, on the 3.0.1.24371 client, single player: the test map's suite with a fourteenth payload, PASS 67 of 67. The payload removes a function whose closure the map stored at the start, with its one call; the compiler warns that the stored closure keeps its old body, the map applies the payload and prints nothing it could not apply, and the stored closure still returns its old 42.

Tests: removedStoredFunctionWarnsFromBaselineAndHistory, removedCallbackAdapterWarns, removedMethodWarnsUnlessItsSlotIsRebound, survivingFunctionWhichAbandonsOldSlotsWarns (four cases), sessionRemembersSlotsOfAnEarlierPayload, closureOwnerDistinguishesSameNamedNestedParameterTypes now assert the warnings; new unchangedFunctionWhichAbandonsASlotWarnsOfNothing, and removedClosureKeepsRunningItsOldBodyInTheMap, which applies such a payload in Lua: the closure kept in a global still returns its old body, the rest of the map runs the new code.

Unit tests, Windows, on master with #1555: LuaHotReloadTests (127), LuaBackendAuditTests (300), LuaTranslationTests (152), DeterministicChecks (38), HotReloadPipelineTests (6). Linux is covered by PR CI; macOS is unverified.

…warning

A removed function a running version stored as a value, or a class-table slot nothing binds any more, keeps its old body only for what the map made before; the new code cannot reach it. The payload now applies and warns, instead of refusing, as it does for package init it cannot run again. A surviving function which leaves a slot warns when its body changes. Order-group checks and the rejection of a changed stored function are unchanged.
…cklog item for closures inserted among others
@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-24T16:12:23.497538Z 28d4a91 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

Copy link
Copy Markdown

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

Reviewed commit: 28d4a91c9d

ℹ️ 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 e4509a4 into master Oct 24, 2026
2 checks passed
@Frotty
Frotty deleted the lua-hot-reload-removal-warns 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