Repository navigation
Lua: skip the nil test of a native's enum argument which is a common.j constant - #1541
Conversation
…j constant The nil-safety wrapper of a native was built once per native, so it tested every argument, including common.j constants such as UNIT_STATE_MAX_LIFE, which are never nil. The guards are now chosen per call: a constant argument is not tested, and a native given only constants is called directly. An enum parameter which a function only hands on to natives' enum parameters (unit.getState, unit.isType in the standard library) is tested by the function's callers instead, where a constant needs no test; only when every call of the function is seen and nothing else reads the parameter.
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: 6a75186577
ℹ️ 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".
Testing a forwarded enum parameter at the callers is an interprocedural rewrite which wants a decision of its own, so this change keeps only the choice per call. BACKLOG.md records the gameplay tests it leaves and the two candidate roots. A wrapper which tests only some parameters names them before the native (__wurst_safe_whichPlayer_SetPlayerState), so its call still reads as a call of the native: WurstBuildMapOutputTests looks for SetPlayerState(Player(0), ...) in the generated config script.
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! 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". |
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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". |
On Lua every native with a handle parameter is called through a nil-safety wrapper. For an enum parameter the wrapper turns null into the handle of id 0, as the engine reads it:
The wrapper was built once per native, so it tested every argument, including common.j constants such as
UNIT_STATE_MAX_LIFE, which the game defines before any script runs and nothing can assign.Change (
LuaNativeLowering)__wurst_safe_whichUnit_GetUnitStatetests only the unit; the tested parameters are named before the native, so the call still reads as a call of the native.ConvertX(<int>).Measurement (a large real map)
Built with
-lua -inline -localOptimizations -runcompiletimefunctions -injectobjects, masteree2c6b66bagainst this branch. Opcodes are counted with the bundledluac53 -l -p.if x == nil then x = ConvertX(0) end)Removed (305), counted by the function the test sat in:
InitCustomTeams136,config123,SetPlayerAllianceStateBJ26, other init 8.Left (166 given a constant), including every gameplay one:
IsUnitType46,BlzFrameSetTextAlignment34,GetUnitState29,GetPlayerState13,TriggerRegisterPlayerEvent13,SetUnitState12. The constant reaches these natives through a standard library parameter that only forwards it (unit.getState(unitstate state)callsGetUnitState(this, state)). The constant appears only after the inliner has removed that function, which happens after the lowering has chosen the test. The two candidate fixes are written up inBACKLOG.md("Lua enum nil tests on gameplay paths…") for a decision; this PR leaves them out.Static Lua instructions: 269,561 → 267,667 (−1,894, −0.7 %).
All the other opcodes moved by 8 or fewer. Script size went from 4,840,803 to 4,815,291 bytes. These are static counts, mostly in code that runs once. The test runtime's Lua is not the game's Lua, and nothing here was timed in game.
Tests
LuaBackendAuditTests:aCommonJConstantArgumentIsNotTestedForNil: shape test. A constant gets the unit-only wrapper. A local and a global of the program's own keep the full guard. A native given only constants is called directly with no wrapper. It fails on master.anInlinedCommonJConstantArgumentIsNotTestedForNil: shape test under-inline -localOptimizations.aCommonJConstantArgumentReadsTheSameAsAGuardedOne: runs on Jass, the interpreter and Lua (testLua(true).luaOnly(false)). It covers a constant, a global of the program's own, a parameter, null, a null local and a null player.Run locally on Windows:
LuaBackendAuditTests,LuaTranslationTests,InterpreterTests,DeterministicChecks. The change makes no host assumptions; Linux and macOS are covered only by CI.