Repository navigation
Add the Lua test-runtime natives executing tests call, and run five more tests on Lua - #1503
Conversation
…ore tests on Lua
wc3shim.lua gains CreateUnit, GetUnitTypeId, CreateDestructable, GetRandomInt,
SquareRoot, BlzBitOr/And/Xor, GetHandleId, Set/GetPlayerState,
Set/GetPlayerTechMaxAllowed and R2SW, each following the interpreter's mock,
and S2I now reads like strtol as measured (S2I(" -4x") is -4). With the
standard library a common.j native gets no generated fallback, so these
programs stopped at the first missing native.
The four OptimizerTests inliner/null-set tests and the BitSet reversePows
repro now run on Lua as well.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 91235b38b3
ℹ️ 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".
| local id = handleIds[h] | ||
| if id == nil then | ||
| id = nextHandleId | ||
| nextHandleId = nextHandleId + 1 | ||
| handleIds[h] = id |
There was a problem hiding this comment.
Share opaque handle IDs with the generated helper
When a Lua test compares GetHandleId(u) with GetHandleIdBJ(u) for the same unit, native lowering routes the direct call through __wurst_GetHandleId/__wurst_objectToIndex, whose IDs start at 1, while the preloaded Blizzard.j wrapper reaches this separate map, whose IDs start at 0x100000. The values therefore differ even though Jass and the interpreter use one native identity, potentially invalidating tests or keys that mix the two APIs; non-enum handles should use the generated identity store.
AGENTS.md reference: AGENTS.md:L316-L322
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changed. The shim models the game's GetHandleId native, and that is what Blizzard.j's GetHandleIdBJ calls in the game too. The split comes from the compiler: LuaNativeLowering routes Wurst's own GetHandleId calls on opaque handles to __wurst_GetHandleId by design. Sharing that store in the test runtime would hide a difference that exists in the game. Whether Wurst calls to GetHandleIdBJ should get the same rewrite is a compiler question that predates this PR, which leaves the compiler alone.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: db797b02ac
ℹ️ 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".
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Summary
With the standard library, the generated Lua defines no fallback for a common.j native (the game defines them), so a test program that calls one the test runtime lacks stops with
attempt to call a nil value. Forcing every executing test onto Lua showed 24 failures of that kind. Each of those programs is unverified on Lua past the first missing native.This adds the missing natives to
src/test/resources/luaruntime/wc3shim.lua, each following the interpreter's mock. It also opts five compiler tests that failed only on these natives into Lua runs, alongside their existing interpreter and Jass runs. The compiler is unchanged.Natives added
Following measured mock values (the mocks record them as measured on the 3.0.0 client):
S2Inow reads like C'sstrtol: it skips leading whitespace, reads a sign and digits, and saturates at the integer limits.S2I(" -4x")is -4; the oldtonumber-based shim gave 0.R2SWputs the sign first, then the integer part padded towidth - precision, then the fraction rounded half up. The test Lua computes in double, so the last digits can differ from the game's float.SquareRootof a negative value is 0.GetHandleId: a null handle is 0, and a converted enum handle is its value. Any other handle gets the next id from0x100000.SetPlayerState/GetPlayerState: a null state is the game result, which reads 3 while unset. Gold and lumber are clamped to 0.Following the interpreter only (not measured in game):
GetRandomIntreturns any value from the first bound up by|high - low|. That range shape is the interpreter generator's. The game's sequence is not modelled.BlzBitOr,BlzBitAndandBlzBitXoruse Lua's 64-bit operators on sign-extended 32-bit values.BlzBitAndandBlzBitXorare included because the BitSet repro calls them right afterBlzBitOr.SetPlayerTechMaxAllowed/GetPlayerTechMaxAlloweddefault to 0, as the mock does.CreateUnit,GetUnitTypeIdandCreateDestructablereturn plain records of their arguments.optimizeDuplicateNullSetsreads the unit type id.Tests now also run on Lua
OptimizerTests.optimizeDuplicateNullSetsOptimizerTests.inlinerGuardClauseAssignsTheResultOnEveryPathOptimizerTests.inlinerLocationLocalsAreInitializedBeforeUseOptimizerTests.inlinerMultiReturnRewriteIsExplicitInInlAndInloptOutputBitSet_Pows_Standalone_ReproTest.highestBit_reset_should_clear_with_buggy_reversePowsAll five pass on Lua. Nothing failed beyond the missing natives.
The
InterpreterTests.*AsMeasuredtests keep their opt-out: they check the interpreter's mocks, and on Lua the game's natives would answer. The twoKeyedTableTeststhat neededCreateUnitare not switched either, because they then reach the directwurstKeyOfcall, which answers its placeholder on Lua.Verification
common.j.luaandblizzard.j.luain the same Lua and checked it against the measuredS2I,R2SW,SquareRoot,GetHandleIdand player-state values fromInterpreterTests.lua5.3from PATH, which CI runs) and macOS (whateverbrew install luainstalls). The shim uses only Lua 5.3 operators and thestringandmathlibraries, with no host-specific paths.