Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions BACKLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,18 @@ Notes; finished-work narrative does not.
change; the handle-keyed `FastKeyedMap` work is separate. Do not start the old-container migration
autonomously.

- **Lua hot reload: closures inserted among others told apart by their order.** Closures of one interface
method in one function with no binding (several `doAfter` or event-listener callbacks) are named by their
position, so editing one's body reaches the objects made from it before. Inserting one before the others
renames every one after it, and the payload refuses that as a move: in Castle Fight's last 30 commits it
is 6 of the 7 still refused, the only cause in 3 (`docs/LUA_HOT_RELOAD.md`, "Edits of a real project").
Naming them by their source instead keeps an insertion's others, but an edited body would then be a new
closure, and objects made before (a running timer's callback) would keep the old body, which is the case
hot reload is most for. Keeping names across an insertion means the build takes them from the running
session's manifest (match closures by source, keep matched names, give new ones fresh ones), so the output
of a hot-reload build would depend on the session, not only the source, against the determinism rule in
AGENTS.md. Decide the trade-off before starting; until then such an edit needs a restart.

## Notes

- **Do not revisit early class-metadata pruning without new evidence.** Closed PR [#1457](https://github.com/wurstscript/WurstScript/pull/1457)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,22 @@ private static final class Pending {
public record Sent(LuaHotReload.Payload payload, Path file) {
}

/**
* What the editor shows of a payload's warnings, as one message: an edit which removes a class warns once for each
* of its methods, which would be as many notifications. Null for a payload without warnings.
*/
public static String warningNote(LuaHotReload.Payload payload) {
List<String> warnings = payload.warnings();
if (warnings.isEmpty()) {
return null;
}
if (warnings.size() == 1) {
return warnings.get(0);
}
return "Hot reload payload " + payload.version() + " applies with " + warnings.size() + " notes:\n"
+ String.join("\n", warnings);
}

/**
* Writes the next payload for the running map where its poll reads it, under the game's CustomMapData folder, and
* only then records it as sent: a payload which could not be written leaves the session as it was, so the next
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,9 @@ private void sendLuaHotReloadPayload(WurstGui gui, File buildDir) throws IOExcep
}
gui.sendProgress("Hot reload payload " + sent.payload().version() + " (" + String.join(", ", sent.payload().functions())
+ ") written to " + sent.file());
for (String warning : sent.payload().warnings()) {
gui.showInfoMessage(warning);
String note = LuaHotReloadSession.warningNote(sent.payload());
if (note != null) {
gui.showInfoMessage(note);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
* Payloads are cumulative from the start of the map. The map records each statement a payload ran
* ({@link #RAN_TABLE}), only once it ran, so a later payload runs what an earlier one did not reach and nothing twice.
* A function stored as a value anywhere but a class table keeps the body it was taken from, so a change to one is
* rejected.
* rejected. One which is removed, or a class-table slot nothing binds any more, keeps its old body for what the map
* made before, which the new code cannot reach: that warns that a restart drops it.
*/
public final class LuaHotReload {

Expand Down Expand Up @@ -544,14 +545,28 @@ public static Payload payload(Manifest baseline, Manifest current, History histo
}
}

// What a running version stores which no function of the edit binds any more: a removed function stored as a
// value (a registered callback, a closure object's class table), or a class-table slot nothing binds now. The
// map keeps such a value with its old body, and only what it made before reaches it: a slot no class binds is
// never dispatched by the new code, and a removed function is not called by it. So the payload applies, and
// says what keeps the old body until the map restarts, as it does for package init it cannot run again.
// A surviving function which abandons a slot is the same case: objects of a class which no longer binds that
// slot run the body it held, and nothing else does. Only a function whose body is redefined here can differ
// from what the slot holds, so one which stays as it was warns of nothing. Changing a function which remains
// stored as a value is another case, refused below: the new code still reaches that value.
Set<String> previousFunctions = new TreeSet<>(baseline.functions().keySet());
previousFunctions.addAll(history.captured().keySet());
previousFunctions.addAll(history.slots().keySet());
Set<String> reboundSlots = new HashSet<>();
current.functions().values().forEach(f -> reboundSlots.addAll(f.slots()));
for (String name : previousFunctions) {
Function old = baseline.functions().get(name);
boolean removed = !current.functions().containsKey(name);
Function now = current.functions().get(name);
boolean removed = now == null;
if (!removed && old != null && old.definition().equals(now.definition()) && !history.reloaded().contains(name)) {
// Not redefined: every slot it left still holds this very body.
continue;
}
List<String> stored = new ArrayList<>(!removed || old == null ? List.of() : old.captures());
if (removed && history.captured().containsKey(name)) {
stored.add("by an earlier payload");
Expand All @@ -563,9 +578,8 @@ public static Payload payload(Manifest baseline, Manifest current, History histo
stored.add("in class-table slot " + slot);
}
if (!stored.isEmpty()) {
reasons.add("function " + name + (removed ? " was removed but is stored as a value ("
: " lost bindings which may remain stored (")
+ String.join(", ", new LinkedHashSet<>(stored)) + "), which keeps the old body");
warnings.add("function " + name + (removed ? " was removed" : " changed") + ", but what the map made before"
+ " keeps its old body (" + String.join("; ", new LinkedHashSet<>(stored)) + "): restart the map to drop it.");
}
}

Expand Down
Loading
Loading