Repository navigation
Keep an integer stored into a real a real - #1484
Conversation
Jass converts an integer stored into a real variable, so `set r = n` followed by `r / m` divides as reals. Copy propagation replaced the read of r by n, and the consecutive-set rewrite spliced n into `r / m`, which emitted `n / m`: an integer division. An int constant from Wurst, such as `real r = 14 div 2`, went the same way. A literal is now propagated as the real it becomes and an integer copy not at all. Both interpreters stored the integer as it was: the IM interpreter on an assignment, the Jass interpreter on an assignment, a parameter and a return value, so `r * r` wrapped at 32 bits and `r / m` divided as integers in the no-optimisation run.
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: 92dc1019a2
ℹ️ 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".
The globals inliner put the integer literal of a single-write real global in place of its reads, so `real g = 14 / 2` in a Jass globals block, or `constant real g = 14 div 2` in Wurst, then `g / m` emitted `7 / m`, an integer division in Jass. It now puts the real literal the global holds (`7. / m`), as copy propagation does for a local.
…-real # Conflicts: # de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/intermediatelang/optimizer/SimpleRewrites.java
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 24ff304def
ℹ️ 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".
| // Jass converts an integer stored into a real, as it does for a parameter or a return value | ||
| ILconst right = ILInterpreter.adjustTypeOfConstant(s.getRight().evaluate(globalState, localState), var.getType()); |
There was a problem hiding this comment.
Coerce integer-to-real boundaries in emitted Lua
When targeting Lua, this conversion only runs in the IM interpreter; translation/lua/translation/StmtTranslation.java:237-238 still emits g = n unchanged for a real g. On the game's runtime, the added jassIntStoredIntoRealGlobalMultipliesAsReal case therefore leaves g as an integer and 65536 * 65536 wraps to 0 instead of producing the real value around 4.29e9; the stock-Lua test masks this because its numeric behavior differs from the game. Apply the coercion in Lua lowering at stores and the analogous real parameter/return boundaries.
AGENTS.md reference: AGENTS.md:L316-L322
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Real, and out of scope here: this PR covers the interpreters and the Jass optimiser rewrites. The Lua side is #1492, which makes the conversion explicit in the IM for Lua (stores, real parameters and returns); measured on the 3.0.0 client, the squared global goes from 0 to 65536 with it.
Jass converts an integer stored into a real variable, so after
set r = nthe readr / mis a real division. Three optimiser rewrites put the integer source in place of the read and emittedn / m, which the game evaluates as an integer division:ConstantAndCopyPropagation), also for an int constant from Wurst (real r = 14 div 2thenr / m);SimpleRewrites.optimizeConsecutiveSet),set r = nthenset r = r / m;GlobalsInliner), for a real global written once with an integer literal:real g = 14 / 2in a Jass globals block, orconstant real g = 14 div 2in Wurst, theng / mgave7 / m.An integer literal is now propagated as the real literal it becomes (
7. / m), an integer copy not at all.realFormatting_consistent_fromIntOpsnow seesprint(1.)instead ofprint(1), the same value.Both interpreters kept the integer as it was, so the unoptimised run already computed the wrong result: the IM interpreter on an assignment (
r * rwrapped at 32 bits), the Jass interpreter on an assignment, a parameter, a return value and a global initialiser (r / mdivided as integers). They now convert where the engine does.Tests:
BugTests.jassIntStoredIntoReal*(Jass, interpreter and Lua runs) andOptimizerTests.intCopiedIntoRealIsNotPropagatedIntoRealDivision,intConstantStoredIntoRealIsPropagatedAsReal,intStoredIntoRealIsNotSplicedIntoTheNextSet,intConstantStoredIntoRealGlobalIsInlinedAsReal,jassIntExpressionInRealGlobalIsInlinedAsReal, each red before its fix. Locally green: BugTests, OptimizerTests, ExpressionTests, InterpreterTests (Windows). The Lua backend is unchanged; its/is always a real division.Measured on the 3.0.0 client, with a map built by master before and after this change (
-inline -localOptimizations, Jass, every operand read from an array at run time):real r = 14 div 2, thenr / 4/ 2set r = nthenset r = r / m, n = 7, m = 2/ 2/ 2/ 65536.14 / 2(Jass), then/ 2For the last row, "before" is this PR without the globals inliner change (measured on the 3.0.0 client too); the two scripts differ only in
7 / magainst7. / m. The Wurst formconstant real g = 14 div 2gave 1.75 in both builds of that map, whose startup order keeps the inliner from replacing that global; the unit test covers it.Two cases still differ from the game's own conversion after this change; neither is in its scope:
returns realwhich returns an integer, once inlined:f(7) / 2gives 3 in both builds (set a = n / min the output).