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
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

@SuppressWarnings("ucd") // ignore unused code detector warnings, because this class uses reflection
public class CompiletimeNatives extends ReflectionBasedNativeProvider implements NativesProvider {
public static final String BUILD_DATE_PROPERTY = "wurst.compiletime.buildDate";

private final boolean isProd;
private final ProgramStateIO globalState;
private final WurstProjectConfigData projectConfigData;
Expand Down Expand Up @@ -188,7 +190,9 @@ public ILconstString getMapName() {
}

public ILconstString getBuildDate() {
return ILconstString.fromText(LocalDateTime.now().truncatedTo(ChronoUnit.MINUTES).toString());
String configured = System.getProperty(BUILD_DATE_PROPERTY);
LocalDateTime date = configured == null ? LocalDateTime.now() : LocalDateTime.parse(configured);
return ILconstString.fromText(date.truncatedTo(ChronoUnit.MINUTES).toString());
}

public ILconstBool isProductionBuild() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@

public class CompiletimeNativesTest {

@Test
public void buildDateCanBePinnedForReplay() {
String property = "wurst.compiletime.buildDate";
String previous = System.getProperty(property);
try {
System.setProperty(property, "2001-02-03T04:05:59");
assertEquals(new CompiletimeNatives(null, null, false).getBuildDate().text(), "2001-02-03T04:05");
} finally {
if (previous == null) {
System.clearProperty(property);
} else {
System.setProperty(property, previous);
}
}
}

@Test
public void modifyObjectKeepsDifferentDataPointers() throws Exception {
CompiletimeNatives natives = new CompiletimeNatives(null, null, false);
Expand Down
10 changes: 5 additions & 5 deletions docs/MAP_COMMIT_REPLAY.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ A build failure or fresh/retained mismatch fails the task after recording the ro
`-PprofileContinueOnError` continues collecting failures; inspect every row before treating the task
as successful validation. A rejected payload is a measured `restart` result, rather than a build failure.

`getBuildDate()` observes the current minute. When unequal oracle outputs straddle a wall-clock minute,
the harness retries the **entire** independent-child / warmed-parent / edited-child sequence at most twice.
It records the retries and still requires exact output equality. It never rewrites timestamps, reuses
compile-time results, or ignores mismatching output. Other changing external inputs must be controlled by
the fixture owner; an unstable oracle is not evidence of a cache defect or proof of correctness.
The replay pins the compile-time `getBuildDate()` input to the minute when the campaign starts. The
fresh child, baseline, and retained child all receive that timestamp, and each result records it as
`buildDate`. Pass `-PprofileBuildDate=2026-11-06T22:00` to repeat a campaign with a specific local
timestamp. The oracle compares the complete Lua and manifests. The fixture owner still controls other
external inputs that can vary between builds.
113 changes: 55 additions & 58 deletions docs/profiling/MapCommitHotReloadProfile.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import de.peeeq.wurstio.TimeTaker;
import de.peeeq.wurstio.intermediateLang.interpreter.CompiletimeNatives;
import de.peeeq.wurstio.languageserver.*;
import de.peeeq.wurstio.languageserver.requests.*;
import de.peeeq.wurstscript.RunArgs;
Expand Down Expand Up @@ -127,7 +128,7 @@ private List<String> args() {
return result;
}

private void run() throws Exception {
private void run(String buildDate) throws Exception {
Corpus corpus = JSON.fromJson(Files.readString(fixture.resolve("corpus.json")), Corpus.class);
int limit = Integer.parseInt(System.getProperty("profile.commitLimit", Integer.toString(corpus.pairs.size())));
if (limit <= 0) throw new IllegalArgumentException("profile.commitLimit must be positive");
Expand All @@ -139,64 +140,56 @@ private void run() throws Exception {
row.put("production", pair.production); row.put("paths", pair.paths);
row.put("runtimePaths", pair.runtimePaths); row.put("testPaths", pair.testPaths); row.put("otherPaths", pair.otherPaths);
row.put("publicCompilerAdjustment", Boolean.getBoolean("profile.publicCompiler"));
int clockRetries = 0;
while (true) {
LocalDateTime clockWindow = LocalDateTime.now().truncatedTo(ChronoUnit.MINUTES);
row.put("buildDate", buildDate);
try {
// Build the expected child before creating the parent's warmed model. The reference cannot
// inherit any retained translator, body artifact or AST lookup from the measured edit.
if (manager != null) manager.clean();
manager = null;
install(pair.commit);
if (manager.hasErrors()) throw new IllegalStateException(manager.getFirstErrorDescription());
Build expected = new Probe(root, args()).compile(manager, root);
manager.clean();
manager = null;
install(pair.parent);
if (manager.hasErrors()) throw new IllegalStateException(manager.getFirstErrorDescription());
List<String> beforeArgs = args();
Build before = new Probe(root, beforeArgs).compile(manager, root);
Path session = root.resolve("_build/commit-session"), delivery = root.resolve("_build/commit-delivery");
LuaHotReloadSession.start(session, before.manifest);
long total = System.nanoTime();
row.put("reconcileMillis", install(pair.commit));
List<String> afterArgs = args(); row.put("args", afterArgs);
Build after = new Probe(root, afterArgs).compile(manager, root);
if (!expected.script.equals(after.script) || !expected.manifest.equals(after.manifest)) {
Files.writeString(fixture.resolve("expected.lua"), expected.script);
Files.writeString(fixture.resolve("actual.lua"), after.script);
Files.writeString(fixture.resolve("expected-manifest.json"), JSON.toJson(expected.manifest));
Files.writeString(fixture.resolve("actual-manifest.json"), JSON.toJson(after.manifest));
throw new IllegalStateException("Fresh/retained output differs for " + pair.commit);
}
row.put("freshOracle", "equal Lua and manifest");
row.put("compileMillis", after.millis); row.put("backendWork", after.work);
row.put("phases", after.phases);
row.put("frontend", manager.incrementalImTranslation().statistics());
row.put("backendReason", manager.incrementalImTranslation().scalarBackendReason());
long sending = System.nanoTime();
try {
// Build the expected child before creating the parent's warmed model. The reference cannot
// inherit any retained translator, body artifact or AST lookup from the measured edit.
if (manager != null) manager.clean();
manager = null;
install(pair.commit);
if (manager.hasErrors()) throw new IllegalStateException(manager.getFirstErrorDescription());
Build expected = new Probe(root, args()).compile(manager, root);
manager.clean();
manager = null;
install(pair.parent);
if (manager.hasErrors()) throw new IllegalStateException(manager.getFirstErrorDescription());
List<String> beforeArgs = args();
Build before = new Probe(root, beforeArgs).compile(manager, root);
Path session = root.resolve("_build/commit-session"), delivery = root.resolve("_build/commit-delivery");
LuaHotReloadSession.start(session, before.manifest);
long total = System.nanoTime();
row.put("reconcileMillis", install(pair.commit));
List<String> afterArgs = args(); row.put("args", afterArgs);
Build after = new Probe(root, afterArgs).compile(manager, root);
if (!expected.script.equals(after.script) || !expected.manifest.equals(after.manifest)) {
// getBuildDate() intentionally observes wall time. Retry the complete independent oracle and
// warmed edit if they straddled a minute; never normalize a generated value or accept a mismatch.
if (!clockWindow.equals(LocalDateTime.now().truncatedTo(ChronoUnit.MINUTES)) && clockRetries++ < 2) continue;
Files.writeString(fixture.resolve("expected.lua"), expected.script);
Files.writeString(fixture.resolve("actual.lua"), after.script);
Files.writeString(fixture.resolve("expected-manifest.json"), JSON.toJson(expected.manifest));
Files.writeString(fixture.resolve("actual-manifest.json"), JSON.toJson(after.manifest));
throw new IllegalStateException("Fresh/retained output differs for " + pair.commit);
}
row.put("freshOracle", "equal Lua and manifest");
row.put("clockRetries", clockRetries);
row.put("compileMillis", after.millis); row.put("backendWork", after.work);
row.put("phases", after.phases);
row.put("frontend", manager.incrementalImTranslation().statistics());
row.put("backendReason", manager.incrementalImTranslation().scalarBackendReason());
long sending = System.nanoTime();
try {
var sent = LuaHotReloadSession.send(session, delivery, after.manifest);
row.put("status", "accepted"); row.put("payloadBytes", Files.size(sent.file()));
row.put("functions", sent.payload().functions().size()); row.put("warnings", sent.payload().warnings());
// Acceptance only establishes that the payload can be delivered. Warnings can describe
// initialization/state changes that require restart; do not count those as full commit coverage.
row.put("coverage", sent.payload().warnings().isEmpty() ? "accepted without warnings" : "accepted with state limitations");
} catch (LuaHotReload.Rejected rejected) {
row.put("status", "restart"); row.put("reasons", rejected.getReasons());
}
row.put("sendMillis", elapsed(sending)); row.put("totalMillis", elapsed(total));
} catch (Exception failure) {
row.put("status", "build-failed"); row.put("error", failure.toString());
failure.printStackTrace();
if (manager != null) manager.clean();
manager = null;
var sent = LuaHotReloadSession.send(session, delivery, after.manifest);
row.put("status", "accepted"); row.put("payloadBytes", Files.size(sent.file()));
row.put("functions", sent.payload().functions().size()); row.put("warnings", sent.payload().warnings());
// Acceptance only establishes that the payload can be delivered. Warnings can describe
// initialization/state changes that require restart; do not count those as full commit coverage.
row.put("coverage", sent.payload().warnings().isEmpty() ? "accepted without warnings" : "accepted with state limitations");
} catch (LuaHotReload.Rejected rejected) {
row.put("status", "restart"); row.put("reasons", rejected.getReasons());
}
break;
row.put("sendMillis", elapsed(sending)); row.put("totalMillis", elapsed(total));
} catch (Exception failure) {
row.put("status", "build-failed"); row.put("error", failure.toString());
failure.printStackTrace();
if (manager != null) manager.clean();
manager = null;
}
rows.add(row);
Files.writeString(fixture.resolve("results.json"), JSON.toJson(rows));
Expand All @@ -210,6 +203,10 @@ private void run() throws Exception {
private static double elapsed(long start) { return (System.nanoTime() - start) / 1_000_000.0; }

public static void main(String[] args) throws Exception {
new MapCommitHotReloadProfile(Path.of(args[0]).toAbsolutePath().normalize()).run();
String configured = System.getProperty("profile.buildDate");
LocalDateTime date = configured == null ? LocalDateTime.now() : LocalDateTime.parse(configured);
String buildDate = date.truncatedTo(ChronoUnit.MINUTES).toString();
System.setProperty(CompiletimeNatives.BUILD_DATE_PROPERTY, buildDate);
new MapCommitHotReloadProfile(Path.of(args[0]).toAbsolutePath().normalize()).run(buildDate);
}
}
1 change: 1 addition & 0 deletions docs/profiling/runmap-profile.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ allprojects {
if (project.hasProperty('profileContinueOnError')) jvmArgs '-Dprofile.continueOnError=true'
maxHeapSize = '6g'
jvmArgs '-XX:+UseParallelGC'
if (project.hasProperty('profileBuildDate')) jvmArgs '-Dprofile.buildDate=' + project.property('profileBuildDate')
}
tasks.register('symbolHotReloadProfile', JavaExec) {
dependsOn tasks.named('compileRunMapProfile')
Expand Down
Loading