Skip to content

Add the Lua test-runtime natives executing tests call, and run five more tests on Lua - #1503

Merged
Frotty merged 4 commits into
masterfrom
claude/wonderful-moore-b7495a
Oct 20, 2026
Merged

Frotty merged 4 commits into
masterfrom
claude/wonderful-moore-b7495a

Conversation

@Frotty

@Frotty Frotty commented Oct 20, 2026

Copy link
Copy Markdown
Member

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):

  • S2I now reads like C's strtol: it skips leading whitespace, reads a sign and digits, and saturates at the integer limits. S2I(" -4x") is -4; the old tonumber-based shim gave 0.
  • R2SW puts the sign first, then the integer part padded to width - precision, then the fraction rounded half up. The test Lua computes in double, so the last digits can differ from the game's float.
  • SquareRoot of 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 from 0x100000.
  • 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):

  • GetRandomInt returns 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, BlzBitAnd and BlzBitXor use Lua's 64-bit operators on sign-extended 32-bit values. BlzBitAnd and BlzBitXor are included because the BitSet repro calls them right after BlzBitOr.
  • SetPlayerTechMaxAllowed/GetPlayerTechMaxAllowed default to 0, as the mock does.
  • CreateUnit, GetUnitTypeId and CreateDestructable return plain records of their arguments. optimizeDuplicateNullSets reads the unit type id.

Tests now also run on Lua

  • OptimizerTests.optimizeDuplicateNullSets
  • OptimizerTests.inlinerGuardClauseAssignsTheResultOnEveryPath
  • OptimizerTests.inlinerLocationLocalsAreInitializedBeforeUse
  • OptimizerTests.inlinerMultiReturnRewriteIsExplicitInInlAndInloptOutput
  • BitSet_Pows_Standalone_ReproTest.highestBit_reset_should_clear_with_buggy_reversePows

All five pass on Lua. Nothing failed beyond the missing natives.

The InterpreterTests.*AsMeasured tests keep their opt-out: they check the interpreter's mocks, and on Lua the game's natives would answer. The two KeyedTableTests that needed CreateUnit are not switched either, because they then reach the direct wurstKeyOf call, which answers its placeholder on Lua.

Verification

  • The touched tests pass on Windows 11 with the bundled Lua 5.3, on a tree up to date with master.
  • I loaded the shim with common.j.lua and blizzard.j.lua in the same Lua and checked it against the measured S2I, R2SW, SquareRoot, GetHandleId and player-state values from InterpreterTests.
  • Not verified: Linux (lua5.3 from PATH, which CI runs) and macOS (whatever brew install lua installs). The shim uses only Lua 5.3 operators and the string and math libraries, with no host-specific paths.

…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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 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-20T14:52:43.620067Z 6c5f686 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: 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".

Comment on lines +42 to +46
local id = handleIds[h]
if id == nil then
id = nextHandleId
nextHandleId = nextHandleId + 1
handleIds[h] = id

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@Frotty

Frotty commented Oct 20, 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: 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".

@Frotty

Frotty commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 6c5f686e17

ℹ️ 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 00b95ce into master Oct 20, 2026
2 checks passed
@Frotty
Frotty deleted the claude/wonderful-moore-b7495a branch November 25, 2026 08:53
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