Skip to content

Fuzz client-local code; merge locals across locality - #1483

Merged
Frotty merged 10 commits into
masterfrom
local-merger-without-locality
Oct 17, 2026
Merged

Frotty merged 10 commits into
masterfrom
local-merger-without-locality

Conversation

@Frotty

@Frotty Frotty commented Oct 17, 2026

Copy link
Copy Markdown
Member

Builds on #1482 (its commits are in this branch until it is merged; merge that first).

Differential fuzzing of client-local code

LocalPlayerFuzzTests generates random programs full of client-local values: GetLocalPlayer(), plus BlzGetLocalClientWidth() and BlzIsLocalClientActive(), which the locality analysis treats as client-local the way it treats UI state. The programs branch, loop, break and return early on those values, and mix in copies, globals, fields, allocations and calls. Each program is compiled to Lua without optimisations, with -localOptimizations, and with -inline -localOptimizations. Every build runs in Lua once per simulated client (4 clients), with the client-local natives answering for that client. On every client, an optimised build must make the same calls with the same arguments as the unoptimised one. Allocations (CreateGroup) are logged too, so an optimisation that moved, dropped or duplicated one per client would show.

  • CI runs 25 programs (about 6 s). WURST_FUZZ_PROGRAMS / WURST_FUZZ_SEED run a campaign; a failing seed keeps its program and both scripts in test-output/fuzz.
  • The fuzzer sees bugs: planted ones are caught in 35 of 60 programs (copy propagation keeping facts at a join where the predecessors disagree, often on a single client), and in 118 and 46 of 120 builds (the merger merging int or boolean locals whose live ranges overlap).
  • On this branch (with Propagate copies of values which depend on the local player #1482): about 5,300 programs, no difference. In nearly all of them the clients do different things, and nearly all optimised builds differ from the reference.

Merge locals across locality

The local merger kept client-local and synchronised locals in separate variables only so that the locality analysis, built before it, stayed true for the passes reading it later in the sweep. After #1482 no pass does. A merged local holds on every client the values the separate ones held, so the merger becomes an ordinary pass and the local optimisations no longer build the analysis at all.

Optimised Lua of a large map, two alternating runs each:

before after
local optimisations 7.2 s / 6.7 s 5.5 s / 5.6 s
whole build 37.6 s / 37.0 s 35.4 s / 35.5 s
static instructions 482,115 482,275 (+0.03%)

A second large map: -0.01% instructions. No new locals-table spills.

The inliner's Lua register budget still counts client-local and synchronised locals as separate classes. That over-estimates now, which is safe. I measured counting per type instead: more arithmetic helpers then fit, the late helper phase re-runs the local optimisations (+3.2 s), and the main inliner's decisions shift (+0.17% instructions). So that is left out and recorded in BACKLOG.

Tests

  • LuaTranslationTests.luaLocalMergerReusesSlotsAcrossLocality: a GetLocalPlayer() local and a Player(0) local with disjoint live ranges share one Lua local; on Propagate copies of values which depend on the local player #1482 they get two.
  • The LocalMerger unit tests call optimize(translator); LocalPlayerAwareOptimizerPass has no implementations left and is removed.
  • Run locally (Windows): OptimizerTests, LuaBackendAuditTests, LuaTranslationTests, LocalPlayerContextAnalyzerTests, ObservableEffectsTests, DeterministicChecks, CompiletimeTests, BugTests, ClassesTests, the Lua backend classes and LocalPlayerFuzzTests, 995 tests.

Constant and copy propagation refused every value the local-player
analysis marks as dependent, "deliberately conservative" since #1207. A
propagation replaces a read of a local by the local or constant it is known
to hold at that point: on every client the replaced read sees the value the
original read saw, and no computation moves, appears or disappears, so it
cannot make clients diverge. The passes which do move code (the local merger,
the branch merger) keep their locality checks.

In UI code, where most values derive from client-local frame state, the
guard kept almost every copy the inliner makes. Without it the pass needs no
locality analysis and is an ordinary pass; the function splitter builds the
analysis for the local merger only, after the propagation.
LocalPlayerFuzzTests generates random programs full of client-local values
(GetLocalPlayer(), the client's width and activity, as UI code reads them):
branches, loops, breaks and early returns on them, copies, globals, fields,
allocations and calls. Each program is compiled to Lua without
optimisations and with -localOptimizations, with and without -inline, and
every build runs in Lua once per simulated client. On every client an
optimised build has to make the same calls with the same arguments as the
unoptimised one. CI runs 25 programs; WURST_FUZZ_PROGRAMS and
WURST_FUZZ_SEED run a campaign. A failing seed keeps its program and both
scripts in test-output/fuzz.

Planted bugs it catches: copy propagation keeping facts at a join where
the predecessors disagree (35 of 60 programs), the local merger merging
int or boolean locals whose live ranges overlap (118 and 46 builds of 120).
The local merger kept client-local and synchronised locals apart only so
that the locality analysis, made before it, stayed true for the passes
which read it later in the sweep. Since copy propagation reads it no
longer, no pass does, and merging two locals with disjoint live ranges
holds on every client the values the two held. The merger is an ordinary
pass now, and the local optimisations build no locality analysis: on an
optimised Lua build of a large map they take 5.5 s instead of 6.7 to 7.2 s
and the build about 2 s less, with the script within 0.03%. The function
splitter and the old-generics cast merge call the merger without one.

The inliner's register budget still counts the two as separate classes,
which over-estimates now; counting per type changes what is inlined and
costs more build time than it saves (BACKLOG).
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-17T16:58:08.708802Z ef288b0 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 351026bdd5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty

Frotty commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f967932ca5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty

Frotty commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 41ef89eb71

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty

Frotty commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: d66576b359

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…t-locality

# Conflicts:
#	de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/intermediatelang/optimizer/FunctionSplitter.java
#	de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/intermediatelang/optimizer/LocalPlayerContextAnalyzer.java
#	de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/translation/imoptimizer/ImOptimizer.java
@Frotty

Frotty commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6eb3befe31

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty

Frotty commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: ef288b03fd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty
Frotty merged commit 6bb0ac3 into master Oct 17, 2026
2 checks passed
@Frotty
Frotty deleted the local-merger-without-locality branch October 17, 2026 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant