Skip to content

Convert an integer stored into a real on Lua - #1492

Merged
Frotty merged 7 commits into
masterfrom
lua-int-stored-into-real
Oct 17, 2026
Merged

Frotty merged 7 commits into
masterfrom
lua-int-stored-into-real

Conversation

@Frotty

@Frotty Frotty commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Jass converts an integer stored where a real is declared: set r = n, local real r = n, an integer argument for a real parameter. Lua kept the integer, and the game's Lua computes integers in 32 bits, so a product of the stored value wrapped where Jass multiplies reals. Only Jass code stores an integer there (an int is a real only in Jass code).

On Lua the translation to IM now converts at those stores (ExprTranslation.isIntStoredAsReal): the value becomes n + 0., next to the existing case of a literal, which was already translated as the real it stands for. Since the conversion is in the IM from the start, the interpreter, the optimiser and the backend all see it. An operand of an operator gets nothing (the operation converts), and Wurst code gets nothing. The Jass target is unchanged.

Tests (LuaBackendAuditTests, each red before the change):

  • jassIntStoredIntoRealIsARealOnLua: a global, an array element, a local initialiser and a parameter, run on Lua (fourth power of 65536, which wraps at 64 bits in the test Lua too) plus the emitted shape.
  • jassIntStoredIntoRealStaysARealWhenInlinedOnLua: the same with -inline -localOptimizations; before, copy propagation and inlining made each of them n * n * n * n.
  • wurstRealCodeGetsNoIntConversionOnLua: no conversion in Wurst real code.

Measured on the 3.0.0 client, Lua maps built by master before and after this change (-inline -localOptimizations, every operand read from an array at run time):

before after
65536 stored into a real global, squared, / 65536. 0 65536
real r = 14 div 2 (Wurst), / 4, x1000, local and global 1750 1750
7 stored into a real local by its initialiser, / 2, x1000 3500 3500
set r = n then set r = r / m, x1000 3500 3500
7 passed to a real parameter, / 2, x1000 3500 3500
real global initialised with 7, / 2, x1000 3500 3500
real global initialised with an int expression, / 2, x1000 3500 3500

The divisions were already right on Lua, whose / always gives a real. Jass gives 65536 in the square case.

Locally green on Windows: LuaBackendAuditTests, LuaTranslationTests, LuaCodeListTests, LuaHashtableTests, LuaKeyedMapTests, LuaMultipleResultsTests, LuaNativesTests, LuaSyntaxCheckTests, LuaTypecastingTests, BugTests, ExpressionTests, DeterministicChecks, CompiletimeTests. Of the 347 Lua scripts those tests emit, only the two Jass repros get a conversion.

The interpreters and the Jass optimiser rewrites for the same stores are #1484; the runtime test here is Lua only so it does not depend on that.

An integer returned from a function which returns real is left out of the tests and the table on purpose: #1491 makes it a type error, as pjass already does, except on legacy targets. The translation still converts it there, so the two PRs do not depend on each other in either order.

@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-17T19:43:33.872238Z a2318e7 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: 76afe45024

ℹ️ 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: 2e5f8b3f6f

ℹ️ 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. Another round soon, please!

Reviewed commit: a2318e70cc

ℹ️ 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 4f7c04e into master Oct 17, 2026
2 checks passed
@Frotty
Frotty deleted the lua-int-stored-into-real branch October 17, 2026 19:50
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