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: 12 additions & 8 deletions BACKLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ Notes; finished-work narrative does not.
- **Run every executing test on Lua on master CI (`-PallBackends`).** Forcing `translateAndTestLua`
after the Jass runs of every `executeProg` test that does not opt into Lua (686 tests, October 2026)
passed 645 on plain Lua and 644 with `-inline -localOptimizations`; the failures found the
generic-static and type-id items below, three defects with their own fixes (compile-time object ids,
old-generic tuple arguments, a direct `wurstKeyOf` call) and 24 tests stopped by natives missing from `wc3shim.lua`. The two Lua variants
generic-static item below, four defects with their own fixes (compile-time object ids, old-generic
tuple arguments, a direct `wurstKeyOf` call, the `Reflection` natives) and 24 tests stopped by natives missing from `wc3shim.lua`. The two Lua variants
cost about 300 s of test time each over the suite. Proposal: `-PallBackends` (master CI only, PR CI
unchanged) runs Lua after Jass for every executing test, `-PallBackends=full` adds the inlined
variant. A test that cannot hold on Lua says why with `.luaExempt(LuaExemption.X)` instead of
Expand All @@ -263,12 +263,16 @@ Notes; finished-work narrative does not.
`ExprTranslation.translateEquals` typing `a.iterator().next()`. Fix in `EliminateGenerics`, where the
store is split, and turn on `testLua(true).luaOnly(false)` for both tests.

- **`typeIdToTypeName`, `maxTypeId`, `instanceCount` and `maxInstanceCount` answer defaults on Lua.**
Only `EliminateClasses` implements them, on the Jass path. On Lua they compile to the generic native
fallback, which returns `""` or 0 without a diagnostic, so `NewFeatureTests.typeName`, `typeName2`,
`maxTypeId`, `instanceCount` and `instanceMaxCount` hold only with `testLua(false)`. Nothing documents
this as a backend difference. Implement them on Lua (one id space for every class, docs/WC3_RUNTIME.md
"Objects and memory", so `instanceCount` counts one class's live descriptors) or reject them there.
- **The `Reflection` natives answer otherwise on Jass for a number which is no type id, and in the
interpreter.** `EliminateClasses` searches the type ids without bounds, so on Jass
`typeIdToTypeName(0)` is the first class's name and a number above `maxTypeId()` answers for the last
class, where the search's own default (`"unknown"`, 0) and Lua answer the default. The interpreter
(`WurstflectionProvider`, `ILInterpreter.getInstanceCount`) counts the objects of the class alone, not
of its allocator group, gives as `maxInstanceCount` the number of objects ever made, and raises in
`typeIdToTypeName` for an unknown number. Compile-time code sees that, and the parity tests run the
interpreter only on the translated program (`LuaTranslationTests.reflectionNativesAnswerAsOnJass`).
Bound the Jass search and make the interpreter answer as the backends do (docs/WC3_RUNTIME.md
"Objects and memory").

- **Represent raw Lua helper bindings structurally.** Lua name compression now runs after backend
lowering so it includes descriptors, field storage and resolved dispatch slots. `LuaLiteral` still
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ public static int calculateMaxTypeId(ImProg prog) {
return calculateMaxTypeId(TypeId.calculate(prog));
}

private static int calculateMaxTypeId(Map<ImClass, Integer> classId) {
/** The largest type id, -1 when there is no class. */
public static int calculateMaxTypeId(Map<ImClass, Integer> classId) {
boolean seen = false;
int best = 0;
for (Integer x : classId.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
import de.peeeq.wurstscript.jassIm.ImProg;
import org.eclipse.jdt.annotation.Nullable;

import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.stream.Collectors;

public class TypeId {
Expand All @@ -27,16 +29,29 @@ public class TypeId {
.thenComparing(TypeId::sourceKey);

public static Map<ImClass, Integer> calculate(ImProg prog) {
return calculate(prog.getClasses(), TypeId::superClassDefs);
}

/**
* Type ids for {@code classesToNumber}, numbered along the superclass edges {@code superClasses} gives, which
* must lead to classes among them.
*/
public static Map<ImClass, Integer> calculate(Collection<ImClass> classesToNumber,
Function<ImClass, List<ImClass>> superClasses) {
AtomicInteger count = new AtomicInteger();
Map<ImClass, Integer> result = Maps.newLinkedHashMap();

List<ImClass> classes = prog.getClasses().stream()
List<ImClass> classes = classesToNumber.stream()
.sorted(class_comparator)
.collect(Collectors.toList());
assignIds(count, result, classes);
assignIds(count, result, classes, superClasses);
return result;
}

private static List<ImClass> superClassDefs(ImClass c) {
return c.getSuperClasses().stream().map(ImClassType::getClassDef).collect(Collectors.toList());
}

private static String packageName(ImClass ic) {
Element c = ic.attrTrace();
if (c == null) {
Expand All @@ -63,22 +78,22 @@ private static String sourceKey(ImClass ic) {
}

private static void assignIds(AtomicInteger count, Map<ImClass, Integer> result,
List<ImClass> classes) {
Multimap<ImClass, ImClass> subClasses = calculateSubclasses(classes);
List<ImClass> classes, Function<ImClass, List<ImClass>> superClasses) {
Multimap<ImClass, ImClass> subClasses = calculateSubclasses(classes, superClasses);

// start with the classes that do not have any super classes (preorder traversal)
for (ImClass c : classes) {
if (c.getSuperClasses().isEmpty()) {
if (superClasses.apply(c).isEmpty()) {
assignId(count, result, c, subClasses);
}
}
}

private static Multimap<ImClass, ImClass> calculateSubclasses(List<ImClass> classes) {
private static Multimap<ImClass, ImClass> calculateSubclasses(List<ImClass> classes,
Function<ImClass, List<ImClass>> superClasses) {
Multimap<ImClass, ImClass> subClasses = LinkedHashMultimap.create();
for (ImClass c : classes) {
c.getSuperClasses().stream()
.map(ImClassType::getClassDef)
superClasses.apply(c).stream()
.sorted(class_comparator).forEach(superClass ->
subClasses.put(superClass, c)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,16 @@ public static LuaExpr translate(ImBoolVal e, LuaTranslator tr) {
}

public static LuaExpr translate(ImDealloc e, LuaTranslator tr) {
return LuaAst.LuaExprFunctionCall(tr.objectDealloc,
return LuaAst.LuaExprFunctionCall(tr.deallocFor(e.getClazz().getClassDef()),
LuaAst.LuaExprlist(e.getObj().translateToLua(tr)));
}

public static LuaExpr translate(ImFuncRef e, LuaTranslator tr) {
if (LuaReflection.isReflectionNative(e.getFunc())) {
// It has no definition (LuaReflection), as on Jass, where the class elimination replaces only its calls.
throw new CompileError(e.attrTrace().attrSource(),
"Lua backend: " + e.getFunc().getName() + " can only be called, not used as a function reference.");
}
return LuaAst.LuaExprFuncRef(tr.callbackAdapterFor(e.getFunc()));
}

Expand All @@ -89,6 +94,14 @@ public static LuaExpr translate(ImFunctionCall e, LuaTranslator tr) {
// function now (see LuaEnsureFunctions), so it needs no special-casing
// here - the generic function-call translation below handles it, the same
// way it handles any other Wurst-internal function.
if (LuaReflection.isReflectionNative(e.getFunc())) {
LuaReflection reflection = tr.reflection();
if (reflection == null) {
throw new IllegalStateException("A call of " + e.getFunc().getName()
+ " was not seen before the translation: " + e);
}
return reflection.translateCall(e);
}
String tcFunc = tr.getTypeCastingFunctionName(e.getFunc());
if (tcFunc != null && !e.getArguments().isEmpty()) {
LuaExpr arg = e.getArguments().get(0).translateToLua(tr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,25 +443,8 @@ public class LuaNatives {
f.getBody().add(LuaAst.LuaLiteral("return __wurst_objectToIndex(h)"));
});

addNative("typeIdToTypeName", f -> {
f.getParams().add(LuaAst.LuaVariable("typeId", LuaAst.LuaNoExpr()));
f.getBody().add(LuaAst.LuaLiteral("return \"\""));
});

addNative("maxTypeId", f -> {
f.getBody().add(LuaAst.LuaLiteral("return 0"));
});

addNative("instanceCount", f -> {
f.getParams().add(LuaAst.LuaVariable("typeId", LuaAst.LuaNoExpr()));
f.getBody().add(LuaAst.LuaLiteral("return 0"));
});

addNative("maxInstanceCount", f -> {
f.getParams().add(LuaAst.LuaVariable("typeId", LuaAst.LuaNoExpr()));
f.getBody().add(LuaAst.LuaLiteral("return 0"));
});

// typeIdToTypeName, maxTypeId, instanceCount and maxInstanceCount are printed where they are called
// (LuaReflection).
}

private static void addNative(String name, Consumer<LuaFunction> g) {
Expand Down
Loading
Loading