Skip to content

Lower a direct wurstKeyOf call on Lua - #1506

Merged
Frotty merged 1 commit into
masterfrom
lua-wurstkeyof-direct-call
Oct 20, 2026
Merged

Frotty merged 1 commit into
masterfrom
lua-wurstkeyof-direct-call

Conversation

@Frotty

@Frotty Frotty commented Oct 20, 2026

Copy link
Copy Markdown
Member

On Lua a direct call of the wurstKeyOf intrinsic answered its placeholder: wurstKeyOf(7) was 0 and every class instance shared key 0. Jass gives the intrinsic a body only after generic elimination (JassKeyOfLowering); Lua keeps generics erased, so the source body return 0 survived and nothing lowered a direct call. KeyedTableTests.intKeyIsIdentity and classInstanceKeyIsStable passed on the interpreter and Jass and failed on Lua (BACKLOG.md).

Change

  • LuaNativeLowering.transform lowers each direct call where it is made, from its type argument: an int or a class instance (an integer id on both targets) is its own key, a handle becomes the same GetHandleId call Lua makes for a handle of that type (ImTranslator.handleIdNative). No helper call, allocation or guard.
  • A type without a stable integer key (real, boolean, string, code, tuples) and a call from erased generic code are rejected with a diagnostic instead of answering 0 (AGENTS.md §3). The declaration check is shared with Jass (JassKeyOfLowering.isCheckedKeyOf).
  • The keyed tables are lowered before the post-generics tree shake (was: after it), so the Jass bodies they replace, whose wurstKeyOf(key) has no concrete type on Lua, are dropped rather than lowered.

Backend difference: a direct call from generic code compiles on Jass, which specialises it, and is a compile error on Lua, which erases it. callFromGenericCodeIsRejectedOnLuaOnly pins this.

Evidence

  • The four keyed-table tests that now also run on Lua failed there before and pass now; five new tests cover handles, keys passed into replaced natives (SaveInteger(ht, 0, wurstKeyOf(u), 5), which an early version left unlowered), rejected types and the generic-code rejection.
  • Emitted Lua for wurstKeyOf(7): before function wurstKeyOf(value4) return 0 end and a call; after the literal 7, with no wurstKeyOf in the output.
  • No other output changes: the 291 Lua scripts emitted by LuaKeyedMapTests, LuaTranslationTests, LuaBackendAuditTests and LuaCodeListTests are byte-identical to master's.
  • Passing locally: KeyedTableTests 17, LuaTranslationTests 144, LuaBackendAuditTests 243, LuaKeyedMapTests 39, LuaCodeListTests 7, DeterministicChecks 27, TreeShakerTests 25, ImTranslatorPinnedFunctionsTests 2.

Tested on Windows with the bundled Lua 5.3; Linux runs in PR CI, macOS only on master. The change touches no filesystem or process code.

On Lua the intrinsic kept its placeholder body, so wurstKeyOf(7) was 0 and
every class instance shared key 0. LuaNativeLowering now lowers each call
where it is made, from its type argument: an int or class instance is its
own key, a handle becomes the GetHandleId call Lua makes for its type.
Types without a stable integer key, and calls from erased generic code,
are rejected with a diagnostic. The keyed tables are now lowered before the
tree shake, so the Jass bodies they replace are dropped rather than lowered.
@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-20T15:50:00.480370Z — PR opened
ℹ️ 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.

@Frotty
Frotty merged commit a99c4ef into master Oct 20, 2026
2 checks passed
Frotty added a commit that referenced this pull request Oct 21, 2026
The direct Lua lowering of wurstKeyOf (#1506) replaced the call by the value itself for a class or interface
type. A null instance is nil on Lua, so its key was nil: arithmetic on it raised and no table can be indexed
by it, where Jass and the interpreter answer 0. The call now lowers to the value's cast to int, which Lua
prints as `x or 0`, so a key and `castTo int` agree for every value, null included.
@Frotty
Frotty deleted the lua-wurstkeyof-direct-call branch November 25, 2026 08:54
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