Skip to content

Scalarize tuples in the Lua backend - #1261

Closed
Frotty wants to merge 11 commits into
masterfrom
codex/lua-tuple-scalarization
Closed

Scalarize tuples in the Lua backend#1261
Frotty wants to merge 11 commits into
masterfrom
codex/lua-tuple-scalarization

Conversation

@Frotty

@Frotty Frotty commented Aug 29, 2026

Copy link
Copy Markdown
Member

Summary

  • run the established IM tuple-elimination pass for Lua so tuple locals, parameters, returns, fields, arrays, nested values, assignments, and comparisons become scalar storage/operations
  • preserve Lua virtual dispatch by sharing scalar tuple-return slots across an override group
  • monomorphize only tuple-valued generic paths so erased generic storage can also be split without changing ordinary Lua generic erasure
  • reject residual runtime tuple IM after lowering, preventing table-based tuple emission from silently returning
  • update array-default expectations: tuple arrays no longer need identity-bearing lazy table defaults

Acceptance criteria

  • emitted Lua creates no tuple tables, tuple-copy helpers, or tuple-equality helpers
  • tuple values preserve value semantics and evaluation order
  • class fields, arrays, nested tuples, virtual tuple returns, and tuple-valued generic storage work on the real Lua 5.3 test runtime
  • Jass behavior remains unchanged

Verification

  • ./gradlew.bat test — 1,760 tests passed on the completed implementation before the final tuple-only specialization scope cleanup
  • focused current-head suites: LuaBackendAuditTests, LuaTranslationTests, FieldIterationTests, and FastHashMapTests — passed (190+ tests)
  • deterministic randomized 64-case tuple value-semantics test — passed on Lua
  • git diff --check — clean

Follow-up

Class instances intentionally remain Lua tables in this PR. A separate follow-up will evaluate integer IDs plus per-field arrays with explicit reclamation, including stale-reference semantics, reference cleanup, closure lifetime, and generated-Wurst benchmarks.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 29, 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-08-29T09:15:00.930913Z 066517c 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: 43495f3091

ℹ️ 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 Aug 29, 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: e415c7110a

ℹ️ 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 Aug 29, 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: 1b370435db

ℹ️ 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 Aug 29, 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: ad994db850

ℹ️ 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 Aug 29, 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: c96e3708ad

ℹ️ 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 Aug 29, 2026

Copy link
Copy Markdown
Member Author

@codex review

@Frotty

Frotty commented Aug 29, 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: 982eee608a

ℹ️ 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 Aug 29, 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: 7904f0b954

ℹ️ 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 Aug 29, 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: 6c8d2051ef

ℹ️ 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 Aug 29, 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

exprs.remove(i);
List<ImExpr> tupleExprs = tupleExpr.getExprs().removeAll();
exprs.addAll(i, tupleExprs);

P2 Badge Stage tuple arguments before flattening them

When tuple-returning calls are passed directly as arguments, this turns each call into adjacent expressions such as consume(first(), shared_slot, second(), shared_slot). The auxiliary components use mutable globals shared by the dispatch group, while Lua does not specify expression evaluation order, so an implementation that evaluates or interleaves the later arguments first can read stale slots or let second() overwrite first() before its slot is captured, silently diverging from Jass tuple semantics. Materialize each tuple argument's scalar components in ordered statements before constructing the call argument list.

AGENTS.md reference: AGENTS.md:L217-L221

ℹ️ 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 Aug 29, 2026

Copy link
Copy Markdown
Member Author

Addressed the latest P2 in 066517c. Calls receiving a tuple argument now evaluate the dynamic receiver and every original argument left-to-right into scalar locals, then invoke the scalar-only call. This prevents later tuple-returning arguments from overwriting shared return slots and preserves interleaved scalar side effects. Added a real-Lua regression for consume(produce(1), mark(7), produce(2)); focused LuaBackendAuditTests and TupleTests pass.

@Frotty

Frotty commented Aug 29, 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: 066517c8e3

ℹ️ 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 +1003 to +1005
ImVar temp = JassIm.ImVar(rhs.attrTrace(), rv.getType(), "tuple_return", false);
f.getLocals().add(temp);
stmts.add(JassIm.ImSet(parent.getTrace(), JassIm.ImVarAccess(temp), rhs));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Capture return components before later component preludes

When an earlier tuple component is a mutable read and a later component has been lowered to an ImStatementExpr, flattenTupleExpr moves the later component's statements into stmts before this loop captures any flatExprs. Thus return pair(x, producer().y) returns the modified value of x if producer() changes it, instead of the value read before evaluating the second component. Capture each component at its original flattening position rather than staging all values after every extracted prelude.

AGENTS.md reference: AGENTS.md:L217-L221

Useful? React with 👍 / 👎.

@Frotty

Frotty commented Aug 29, 2026

Copy link
Copy Markdown
Member Author

Superseded by #1265. The replacement is rebased on merged #1264, consolidates the history, replaces downstream recovery/name parsing with structural phase invariants, and adds ordered-bundle plus differential coverage.

@Frotty Frotty closed this Aug 29, 2026
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