Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
df1cc5f
Lua hot reload: name declarations from their identity
Frotty Oct 22, 2026
c1829da
WIP: structural hot reload payloads
Frotty Oct 22, 2026
5bef3d5
Lua hot reload: method ids with the implementation's signature, so ov…
Frotty Oct 22, 2026
13007b2
Merge branch 'lua-hot-reload-stable-names' into lua-hot-reload-struct…
Frotty Oct 22, 2026
e9aa23e
Lua hot reload: long hashes for colliding identities, locals numbered…
Frotty Oct 22, 2026
8f7105e
Merge branch 'lua-hot-reload-stable-names' into lua-hot-reload-struct…
Frotty Oct 22, 2026
e77cdb2
Lua hot reload: fixed-width identity hashes, body-time names avoid ev…
Frotty Oct 22, 2026
ad0ae94
Lua hot reload: document structural payloads
Frotty Oct 22, 2026
f185615
Merge branch 'lua-hot-reload-stable-names' into lua-hot-reload-struct…
Frotty Oct 22, 2026
1ef3c23
Lua hot reload: declare the local names before the field initialisers…
Frotty Oct 22, 2026
c859df3
Merge branch 'lua-hot-reload-stable-names' into lua-hot-reload-struct…
Frotty Oct 22, 2026
66ec5d2
Lua hot reload: reject adding or removing a closure beside another of…
Frotty Oct 22, 2026
3cfbddb
Lua hot reload: a new package's globals initialised once, kept array …
Frotty Oct 22, 2026
e496ea4
Merge remote-tracking branch 'origin/master' into lua-hot-reload-stru…
Frotty Oct 22, 2026
0739c01
Lua hot reload: the map records what payloads ran, a failed new packa…
Frotty Oct 22, 2026
dd75f62
Lua hot reload: run-once records keyed by what a statement assigns, c…
Frotty Oct 22, 2026
f6fe91a
Merge remote-tracking branch 'origin/master' into lua-hot-reload-stru…
Frotty Oct 22, 2026
419b26a
Lua hot reload: refuse a changed declaration an earlier payload insta…
Frotty Oct 22, 2026
0043bc8
Unify hot-reload package initialization in dependency order
Frotty Oct 23, 2026
7b70ce4
Warn when payloads change an already-run package init
Frotty Oct 23, 2026
3096302
Preserve hot-reload initializer units and installed type identities
Frotty Oct 23, 2026
3e55249
Reject removal of hot-reload callbacks that may remain registered
Frotty Oct 23, 2026
75666c8
Track surviving reload slots and diagnose removed initialization
Frotty Oct 23, 2026
33954b6
Compare hot-reload initialization as ordered sequences
Frotty Oct 23, 2026
3ea0253
Record actual hot-reload initializer completion order
Frotty Oct 23, 2026
9135612
Validate retained reload slots even when functions survive
Frotty Oct 23, 2026
ac637c0
Preserve live globals when adding source initializers
Frotty Oct 23, 2026
e3e54d7
Reject initializer units spanning old and new storage
Frotty Oct 23, 2026
ed6e7b9
Anchor hot-reload closure classes to source variable bindings
Frotty Oct 23, 2026
1368563
Distinguish closure owners and protect ambiguous definitions
Frotty Oct 23, 2026
ed7c7be
Include nested source scopes in closure signature identities
Frotty Oct 23, 2026
fdee052
Merge squash-merged hot reload base from master
Frotty Oct 24, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.hash.Hashing;
import de.peeeq.wurstscript.ast.*;
import de.peeeq.wurstscript.ast.Element;
import de.peeeq.wurstscript.attributes.CompileError;
Expand All @@ -13,6 +14,7 @@
import de.peeeq.wurstscript.parser.WPos;
import de.peeeq.wurstscript.utils.Utils;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -252,7 +254,43 @@ private ImClass createClass() {
}

private String makeClassName(ImClassType superClass) {
return superClass.getClassDef().getName() + makeNameSuffix();
String name = superClass.getClassDef().getName() + makeNameSuffix();
if (tr.getRunArgs().isLuaHotReload()) {
// A local/global binding anchors this source closure independently of sibling translation order.
// Include outer bindings too, so identically named locals in different enclosing closures stay apart.
for (Element scope = e.getParent(); scope != null; scope = scope.getParent()) {
if (scope instanceof GlobalOrLocalVarDef variable) {
String binding = variable.getName();
name += "_bound" + binding.length() + "_" + binding;
Comment thread
Frotty marked this conversation as resolved.
Resolved
} else if (scope instanceof TranslatedToImFunction callable && !(scope instanceof ExprClosure)) {
// Resolve the actual source owner; an enclosing closure's generated implementation is not its
// owner identity. Parameter types distinguish overloads, including same-named imported classes.
name += "_owner" + hotReloadOwnerIdentity(callable);
}
}
}
return name;
}

private String hotReloadOwnerIdentity(TranslatedToImFunction callable) {
StringBuilder identity = new StringBuilder(callable instanceof ConstructorDef ? "constructor"
: callable instanceof OnDestroyDef ? "destructor" : callable instanceof ExtensionFuncDef ? "extension" : "function");
for (Element scope = callable; scope != null; scope = scope.getParent()) {
if (scope instanceof NamedScope named) {
String segment = named.getName();
identity.append(segment.length()).append(':').append(segment);
}
}
ImFunction owner = tr.getFuncFor(callable);
identity.append('<').append(owner.getTypeVariables().size()).append('>')
.append(owner.hasFlag(FunctionFlagEnum.IS_VARARG) ? "vararg" : "fixed");
for (ImVar parameter : owner.getParameters()) {
String type = LuaDispatchPreparation.qualifiedTypeKey(parameter.getType());
identity.append(type.length()).append(':').append(type);
}
String result = LuaDispatchPreparation.qualifiedTypeKey(owner.getReturnType());
identity.append("returns:").append(result.length()).append(':').append(result);
return Hashing.sha256().hashString(identity, StandardCharsets.UTF_8).toString();
}

private String makeNameSuffix() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,40 @@ public static String typeKey(ImType type) {
*/
private static final char OWNERS = '';

/** A structural type key including packages and enclosing source scopes, before nested classes are lowered. */
public static String qualifiedTypeKey(ImType type) {
StringBuilder result = new StringBuilder(typeKey(type)).append(OWNERS);
appendOwners(type, result);
Comment thread
Frotty marked this conversation as resolved.
Resolved
type.accept(new Element.DefaultVisitor() {
@Override
public void visit(ImClassType t) {
super.visit(t);
appendSourceScopes(t.getClassDef().getTrace(), result);
}

@Override
public void visit(ImTypeVarRef t) {
super.visit(t);
Element owner = t.getTypeVariable().getParent() instanceof ImTypeVars vars ? vars.getParent() : null;
if (owner instanceof de.peeeq.wurstscript.jassIm.ElementWithTrace traced) {
appendSourceScopes(traced.getTrace(), result);
}
}
});
return result.toString();
}

private static void appendSourceScopes(de.peeeq.wurstscript.ast.Element trace, StringBuilder result) {
result.append('[');
for (de.peeeq.wurstscript.ast.Element scope = trace; scope != null; scope = scope.getParent()) {
if (scope instanceof de.peeeq.wurstscript.ast.NamedScope named) {
String segment = named.getName();
result.append(segment.length()).append(':').append(segment);
}
}
result.append(']');
}

/**
* The packages of the classes and of the owners of the type variables {@code type} names, in order. Two packages may
* each declare a class of the same name, and {@link #typeKey} names a class by its name only: without these, the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.peeeq.wurstscript.translation.lua.translation;

import de.peeeq.wurstscript.ast.ExprClosure;
import de.peeeq.wurstscript.ast.PackageOrGlobal;
import de.peeeq.wurstscript.ast.WPackage;
import de.peeeq.wurstscript.jassIm.*;
Expand Down Expand Up @@ -174,6 +175,21 @@ static Manifest install(LuaTranslator tr, Map<LuaFunction, ImFunction> reloadabl
Map<LuaFunction, List<String>> slots = new IdentityHashMap<>();
Map<LuaFunction, List<String>> captures = new IdentityHashMap<>();
collectFunctionValues(model, slots, captures);
Map<String, List<LuaFunction>> closureIdentities = new LinkedHashMap<>();
for (Map.Entry<LuaFunction, ImFunction> entry : reloadable.entrySet()) {
if (entry.getValue().getTrace() instanceof ExprClosure) {
closureIdentities.computeIfAbsent(functionId(entry.getValue()), ignored -> new ArrayList<>()).add(entry.getKey());
}
}
for (List<LuaFunction> siblings : closureIdentities.values()) {
if (siblings.size() > 1) {
// Numbering cannot tell which live object belongs to which source closure after a reorder. Freeze
// these definitions through the same baseline/history protection as other stored function values.
for (LuaFunction sibling : siblings) {
captures.computeIfAbsent(sibling, ignored -> new ArrayList<>()).add("with an ambiguous closure identity");
}
}
}
// Only an assignment to one of these gives a global its value; one to a local of a function body does not.
Set<LuaVariable> globals = Collections.newSetFromMap(new IdentityHashMap<>());
for (ImVar global : tr.prog.getGlobals()) {
Expand Down Expand Up @@ -365,7 +381,7 @@ public static Payload payload(Manifest baseline, Manifest current, History histo
for (String id : identities) {
int before = oldCounts.getOrDefault(id, 0);
int after = newCounts.getOrDefault(id, 0);
if (before != after && Math.max(before, after) > 1) {
if (before > 0 && before != after && Math.max(before, after) > 1) {
reasons.add("declarations which share the identity " + id + " (closures of one interface method in one function)"
+ " were added or removed; they are told apart by their order, so restart the map");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@ public void hotReloadInitializerUnitsAreDeterministic() {
assertEquals(repeated, first);
}

@Test
public void hotReloadNamedClosureBindingsAreDeterministic() {
CU closures = compilationUnit("NamedClosures.wurst", "package NamedClosures", "interface Op",
" function apply(int value) returns int", "public function run(int seed) returns int",
" Op a = (int value) -> seed + value", " Op b = (int value) -> seed * value",
" let result = a.apply(2) + b.apply(3)", " destroy a", " destroy b", " return result",
"public function run(string text, int seed) returns int", " Op a = (int value) -> seed - value",
" let result = a.apply(1)", " destroy a", " return result",
"public class A", " public static class N", " int value",
" static function create() returns N", " return new N()",
"public class B", " public static class N", " int value",
" static function create() returns N", " return new N()",
"public function run(A.N item) returns int", " Op a = (int value) -> item.value + value",
" let result = a.apply(2)", " destroy a", " return result",
"public function run(B.N item) returns int", " Op a = (int value) -> item.value - value",
" let result = a.apply(3)", " destroy a", " return result");
CU main = compilationUnit("Main.wurst", "package Main", "import NamedClosures", "init", " run(4)", " run(\"x\", 5)",
" let a = A.create()", " let b = B.create()", " run(a)", " run(b)", " destroy a", " destroy b");
RunArgs args = new RunArgs().with("-lua", "-luaHotReload");
var first = compileLuaHotReloadManifest(false, args, closures, main);
assertEquals(compileLuaHotReloadManifest(false, args, main, closures), first);
assertEquals(compileLuaHotReloadManifest(false, args, closures, main), first);
}

@Test
public void branchNullFactsIgnoreCompilationUnitOrder() throws IOException {
CU program = compilationUnit("NullFacts.wurst",
Expand Down
Loading
Loading