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
20 changes: 10 additions & 10 deletions BACKLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,11 @@ Notes; finished-work narrative does not.
cannot distinguish simultaneous additions/removals and body edits between the same unchanged anchors; make
those edits in separate payloads. A removed closure may still have live objects, so reusing table names its old
bodies read is refused even after intermediate payloads remove the whole group. Do not weaken that guard.
Replay the real-map histories again to measure acceptance after the closure fixes; the recorded 27/30 Castle
Fight result was from an intermediate branch, not the final implementation.
- Replay Castle Fight's addition of `ArrayList<TickCandidates>` beside `ArrayList<UnitStat>` to check the
recorded specialization field-storage refusal. Shared canonical field tables must have one source-field
identity in the manifest, independent of the specialization discovery order. Minimize any remaining refusal
before changing storage ownership: specialized and erased accesses deliberately share those tables.
Old-generics conversion bridges which still share an anonymous source owner form order groups too; ambiguous
A 6 Nov replay matched independent fresh builds for three recent commits per map. Castle Fight accepted
two of three and Zombie Defense accepted all three. Castle Fight `bd77dc0` still needs a restart because
one MultiboardComponents closure group combines additions/removals with edits between unchanged anchors.
Minimize that group before changing closure matching. See [the replay results](docs/MAP_COMMIT_REPLAY.md).
- Old-generics conversion bridges which still share an anonymous source owner form order groups too. Ambiguous
edits still need a restart. Materialized compile-time expressions without distinct bindings also retain an
order-group count; changing that count requires a restart. Dependency-owned object graphs preserve direct and
nested aliases. Independent roots can share objects only while established ownership stays fixed; migrating
Expand All @@ -246,9 +244,11 @@ Notes; finished-work narrative does not.
- The first reload after a command-line start checks the whole model again (about 47 s on Castle Fight).
Generated object-data functions ship whole. Measure smaller representations without splitting effectful
initialization incorrectly.
- Run the in-game suite again: it last ran on #1556, before #1558 through #1566, including closure lineage remaps
and compile-time snapshot replay. Also exercise `grill run --hot` launching a map and picking up a payload.
Stock Lua and CI do not verify Warcraft's preload channel or numeric runtime.
- The 6 Nov harness smoke run proved VS Code save, refusal, recovery and matching game receipts on
Reforged 3.0.1.24371. The published Grill `14252b3` also staged and activated its own hot run, then
reloaded and recovered from a refusal in the harness-managed game. Still rerun the broader in-game matrix
for closure lineage remaps and compile-time snapshot replay. Stock Lua and CI do not verify Warcraft's
preload channel or numeric runtime.
- **Lua hot reload: a reload translates the whole program.** Proposal, measured on 24 Oct 2026 in the language
server on Castle Fight (`wurst.hotreload` after a body edit, a constant edit and a declaration edit, four of each):
a warm request took 14 to 30 s on a loaded machine, the first after a command-line start about 47 s (it checks the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@ public static String warningNote(LuaHotReload.Payload payload) {
* attempt takes the number the map is waiting for.
*/
public static Sent send(Path buildDir, Path customMapData, LuaHotReload.Manifest current)
throws IOException, LuaHotReload.Rejected {
return send(buildDir, customMapData, current, "");
}

static Sent send(Path buildDir, Path customMapData, LuaHotReload.Manifest current, String receiptToken)
throws IOException, LuaHotReload.Rejected {
if (Files.exists(stagedFile(buildDir))) {
throw new LuaHotReload.Rejected(List.of("a hot reload launch is prepared: activate or abort it before sending a payload"));
Expand Down Expand Up @@ -377,7 +382,7 @@ state.groupLayout, orEmpty(state.lineageOrigins),
pending.lineageTypes = new LinkedHashMap<>(payload.lineageTypes());
pending.tableReaders = new LinkedHashMap<>(payload.tableReaders());
writeAtomically(pendingFile(buildDir), GSON.toJson(pending));
Path delivered = deliver(customMapData, payload);
Path delivered = deliver(customMapData, payload, receiptToken);
record(state, pending);
save(buildDir, state);
Files.deleteIfExists(pendingFile(buildDir));
Expand Down Expand Up @@ -495,9 +500,11 @@ private static Path pendingFile(Path buildDir) {
* Writes the payload's file by renaming a complete temporary file: the game reads a file once, so a poll which met a
* file half written would never see the rest.
*/
private static Path deliver(Path customMapData, LuaHotReload.Payload payload) throws IOException {
private static Path deliver(Path customMapData, LuaHotReload.Payload payload, String receiptToken) throws IOException {
Path file = customMapData.resolve(LuaHotReload.preloadFile(payload.version()).replace('\\', '/'));
writeAtomically(file, preloadFile(payload.source()));
String source = receiptToken.isEmpty() ? payload.source()
: "-- " + LuaHotReload.RECEIPT_MARKER + receiptToken + "\n" + payload.source();
writeAtomically(file, preloadFile(source));
return file;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

import static de.peeeq.wurstio.languageserver.ProjectConfigBuilder.FILE_NAME;

Expand Down Expand Up @@ -68,7 +69,7 @@ public Object execute(ModelManager modelManager) throws IOException {
WurstGui gui = createGui(modelManager, "Running Wurst map");
try {
warnAboutRunOptimizations(gui);
String ok = compileMap(modelManager, gui, projectConfig);
Object ok = compileMap(modelManager, gui, projectConfig);
if (ok != null) return ok;
} catch (CompileError e) {
WLogger.info(e);
Expand Down Expand Up @@ -102,7 +103,7 @@ private void warnAboutRunOptimizations(WurstGui gui) {
}

@Nullable
private String compileMap(ModelManager modelManager, WurstGui gui, WurstProjectConfigData projectConfig) throws Exception {
private Object compileMap(ModelManager modelManager, WurstGui gui, WurstProjectConfigData projectConfig) throws Exception {
if (map.isPresent() && !map.get().exists()) {
throw new RequestFailedException(MessageType.Error, map.get().getAbsolutePath() + " does not exist.");
}
Expand All @@ -128,8 +129,7 @@ private String compileMap(ModelManager modelManager, WurstGui gui, WurstProjectC
CompilationResult result = compileScript(modelManager, gui, testMap, projectConfig, buildDir, false);

if (runArgs.isHotReload() && runArgs.isLua()) {
sendLuaHotReloadPayload(gui, buildDir);
return "ok";
return sendLuaHotReloadPayload(gui, buildDir);
}

if (runArgs.isHotReload()) {
Expand Down Expand Up @@ -439,14 +439,18 @@ protected enum MismatchChoice {
* Sends the running Lua map the payload of the edits since it started (docs/LUA_HOT_RELOAD.md). The map polls the
* CustomMapData folder for it; an edit a payload cannot carry fails here, with the reasons, and changes nothing.
*/
private void sendLuaHotReloadPayload(WurstGui gui, File buildDir) throws IOException {
public record ReloadReceipt(String token, String receiptFile, int version) {}

private ReloadReceipt sendLuaHotReloadPayload(WurstGui gui, File buildDir) throws IOException {
if (luaHotReloadManifest == null) {
throw new RequestFailedException(MessageType.Error, "Lua hot reload needs a Lua build;"
+ " start the map with hot run first.");
}
Path customMapData = getCustomMapDataPath();
String token = UUID.randomUUID().toString().replace("-", "");
LuaHotReloadSession.Sent sent;
try {
sent = LuaHotReloadSession.send(buildDir.toPath(), getCustomMapDataPath(), luaHotReloadManifest);
sent = LuaHotReloadSession.send(buildDir.toPath(), customMapData, luaHotReloadManifest, token);
} catch (LuaHotReload.Rejected e) {
throw new RequestFailedException(MessageType.Warning, e.getMessage());
}
Expand All @@ -456,6 +460,8 @@ private void sendLuaHotReloadPayload(WurstGui gui, File buildDir) throws IOExcep
if (note != null) {
gui.showInfoMessage(note);
}
return new ReloadReceipt(token, customMapData.resolve(LuaHotReload.RECEIPT_FILE).toAbsolutePath().toString(),
sent.payload().version());
}

private void callJhcrUpdate(File mapScript) throws IOException, InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public final class LuaHotReload {
* file created during the game was read within 0.5 s.
*/
public static final String PRELOAD_FILE_PREFIX = "Wurst\\hotreload-";
public static final String RECEIPT_FILE = "Wurst/hotreload-receipt.txt";
public static final String RECEIPT_MARKER = "wurst-hot-reload-receipt:";

/** The file of payload {@code version}, relative to CustomMapData, with Windows separators. */
public static String preloadFile(int version) {
Expand Down Expand Up @@ -2493,6 +2495,16 @@ private static void appendRuntime(LuaTranslator tr, LuaCompilationUnit model, St
" __wurst_hotreload_lastStatus = \"rejected: \" .. tostring(err)",
" end",
" BJDebugMsg(\"Wurst hot reload: \" .. __wurst_hotreload_lastStatus)",
// The optional transport comment leaves the compiled payload unchanged. Only a fixed outcome and a
// validated identifier cross back to the editor, so game error text cannot become preload source.
" local receipt = source:match(\"^%-%- " + RECEIPT_MARKER.replace("-", "%-") + "([0-9a-f]+)\\n\")",
" if receipt and #receipt == 32 then",
" local outcome = ok and (#" + WARNINGS + " > 0 and \"applied-with-warnings\" or \"applied\") or \"rejected\"",
" PreloadGenClear()",
" PreloadGenStart()",
" Preload(\"" + RECEIPT_MARKER + "\" .. receipt .. \":\" .. outcome)",
" PreloadGenEnd(\"" + RECEIPT_FILE + "\")",
" end",
"end")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4226,9 +4226,9 @@ public void pollReadsEachPayloadFileOnceInOrder() throws Exception {
LuaHotReload.Payload second = LuaHotReload.payload(baseline, manifest(program("x + 100", "side * side", INIT)), Set.of(luaName(baseline, "score")), 2);
java.nio.file.Path dir = java.nio.file.Files.createTempDirectory("luaHotReloadPoll");
java.nio.file.Files.writeString(dir.resolve("hotreload-1.pld"),
de.peeeq.wurstio.languageserver.requests.LuaHotReloadSession.preloadFile(first.source()));
de.peeeq.wurstio.languageserver.requests.LuaHotReloadSession.preloadFile("-- wurst-hot-reload-receipt:0123456789abcdef0123456789abcdef\n" + first.source()));
java.nio.file.Files.writeString(dir.resolve("hotreload-2.pld"),
de.peeeq.wurstio.languageserver.requests.LuaHotReloadSession.preloadFile("return ("));
de.peeeq.wurstio.languageserver.requests.LuaHotReloadSession.preloadFile("-- wurst-hot-reload-receipt:fedcba9876543210fedcba9876543210\nreturn ("));
java.nio.file.Files.writeString(dir.resolve("hotreload-3.pld"),
de.peeeq.wurstio.languageserver.requests.LuaHotReloadSession.preloadFile(second.source()));
String runtime = "src/test/resources/luaruntime/";
Expand All @@ -4249,12 +4249,18 @@ public void pollReadsEachPayloadFileOnceInOrder() throws Exception {
" local text = f:read('a') f:close()",
" assert(load(text:match('//!beginusercode%s(.-)%s//!endusercode')))()",
"end",
"local receipts = {}",
"PreloadGenClear = function() end",
"PreloadGenStart = function() end",
"Preload = function(text) receipts[#receipts + 1] = text end",
"PreloadGenEnd = function(path) assert(path == 'Wurst/hotreload-receipt.txt') end",
"local scores = {}",
"for i = 1, 4 do " + LuaHotReload.POLL_FUNCTION + "() scores[i] = " + luaName(baseline, "score") + "(1) end",
"print(table.concat(requested, ' '))",
"print(table.concat(scores, ' '))",
"print(" + LuaHotReload.STATUS_FUNCTION + "())",
"print(BlzGetAbilityTooltip(0, 0))");
"print(BlzGetAbilityTooltip(0, 0))",
"print(table.concat(receipts, ' '))");
java.io.File driverFile = new java.io.File("test-output/lua/LuaHotReloadTests_pollDriver.lua");
java.nio.file.Files.writeString(driverFile.toPath(), driver);
Process p = new ProcessBuilder(getLuaExecutable(), driverFile.getPath()).redirectErrorStream(true).start();
Expand All @@ -4265,6 +4271,8 @@ public void pollReadsEachPayloadFileOnceInOrder() throws Exception {
assertEquals("the broken file changes nothing, the next one applies", "11 11 101 101", lines[1]);
assertEquals("applied payload 2", lines[2]);
assertEquals("the poll puts the ability's tooltip back", "Attribute Bonus", lines[3]);
assertEquals("wurst-hot-reload-receipt:0123456789abcdef0123456789abcdef:applied "
+ "wurst-hot-reload-receipt:fedcba9876543210fedcba9876543210:rejected", lines[4]);
}

/** The preload file hands the payload over unchanged, whatever characters and length it has. */
Expand Down
17 changes: 17 additions & 0 deletions docs/LUA_HOT_RELOAD.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,16 @@ Editor side (implemented, `LuaHotReloadSession`, `RunMap`):
with the reasons as its error message; the VS Code extension shows the first line and writes the rest to its
output. While a hot run is active, the VS Code extension sends it on every save of a Wurst file.

For a Lua project, VS Code's Run button offers **Run** and **Hot Run**. The direct commands stay
available in the Command Palette. The editor first reports **reload payload sent**, then waits up to
ten seconds for a matching game receipt. It can report application, application with warnings,
rejection, or no game response. The game still prints detailed warnings and rejection reasons.

The language server adds a random receipt token in a Lua comment at delivery time. The running map
echoes the token and a fixed outcome in `CustomMapData/Wurst/hotreload-receipt.txt` after processing
the payload. The editor checks the token so a receipt from an earlier payload or session cannot
confirm the current reload. With an older compiler, the editor reports delivery only.

Without the editor, a map built with `-build ... -luaHotReload` (which takes the run arguments of `wurst_run.args`, not
its build-only `+` lines: `-luaHotReload` refuses `-inline` and `-opt`) takes payloads from the compiler's command line,
which is how the in-game test drives it. Setting `-luaHotReload` on a shared line in `wurst_run.args` selects the same
Expand Down Expand Up @@ -668,6 +678,13 @@ a map command's failure now carries its own text (`BuildDiagnosticsTests`).
Not measured: whether the preload file's Lua section sees the map's globals (it does not need to); multiplayer, which
is refused.

### 6 Nov 2026: game receipts in VS Code

The Warcraft III E2E harness ran a single-player test on Windows with Reforged `3.0.1.24371`.
VS Code saves applied payloads 1 and 2 and the game wrote a matching receipt for each. Between them
the compiler refused an existing field type change without publishing a payload. The timer advanced
from tick 1 to 14 and an object created before either edit kept its field value of 79.

## Probe for other clients

The probe is `profiling/lua-opportunities/hot-reload-probe.lua`, plus the file `hot-reload-probe.pld` next to it,
Expand Down
25 changes: 25 additions & 0 deletions docs/MAP_COMMIT_REPLAY.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,31 @@ On this base, 696 targeted checks pass with ownership checks and both backend va
insertion enabled passed: 1,257 applied payloads, 242 expected refusals, one permitted ambiguous refusal, zero
failures. Execution/timings remain Windows-only; current game application and macOS remain unverified.

## 6 Nov 2026 compatibility spot check

The compiler at `179169de7` with the editor receipt patch replayed three recent first-parent commits per
map on Windows. Every measured child matched independent fresh Lua and its manifest. The fixtures froze
map data and dependencies. Castle Fight used WurstStdlib2 `eac3824` for `UnitLifecycleTrace`. Zombie
Defense's last pair used Frentity `5bddf50` for the new height-sampling API.

| Map | Commit | Payload | Warnings | Host seconds |
| --- | --- | --- | ---: | ---: |
| Castle Fight | `f71b7d0` | accepted | 0 | 18.92 |
| Castle Fight | `6d9d077` | accepted | 1 | 15.12 |
| Castle Fight | `bd77dc0` | restart | 1 | 15.84 |
| Zombie Defense | `36f8e7f` | accepted | 14 | 10.47 |
| Zombie Defense | `6a22737` | accepted | 4 | 8.57 |
| Zombie Defense | `ad0e118` | accepted | 0 | 11.29 |

The Castle Fight refusal came from the `withParent` closures in `MultiboardComponents.ResourceRow` with both additions or removals
and edits between the same unchanged closures. The Zombie Defense boss callback changes were accepted
with warnings for existing captures and removed callbacks. The offline timings end at host publication or
refusal and exclude Warcraft III pickup.

The targeted Castle Fight replay of `2b7e0acb`, which added the `TickCandidates` specialization,
also matched the fresh oracle and published its payload in 14.82 s with 22 warnings. The earlier
specialization field-storage refusal did not reproduce.

## Running another campaign

From the repository root, export into a **new** fixture directory. The template directory must contain
Expand Down
Loading