Skip to content

Lua: declare no global as nil at the top of the script - #1495

Merged
Frotty merged 1 commit into
masterfrom
lua-no-nil-global-declarations
Oct 18, 2026
Merged

Frotty merged 1 commit into
masterfrom
lua-no-nil-global-declarations

Conversation

@Frotty

@Frotty Frotty commented Oct 18, 2026

Copy link
Copy Markdown
Member

Every global was declared as X = nil at the top of the emitted Lua script. So were the runtime's object, number and string index maps and the bootstrap's done flag. A global Lua has not seen already reads as nil, and the bootstrap which main runs first gives each of them its value, so each declaration was a table write at load which changed nothing. They are no longer emitted. References still point at the same variables, and the bootstrap's assignments are unchanged. config(), which the game runs before main, sees nil for these globals either way.

Effect on two large maps

Built with -lua -inline -localOptimizations:

nil declarations script instructions
Map A 3,437 7.92 → 7.78 MB (−1.8%) 433,739 → 423,657 (−2.3%)
Map B 3,544 4.93 → 4.79 MB (−2.7%) 281,465 → 271,060 (−3.7%)

With the X = nil lines taken out of the old output, the only remaining differences from the new output are a few blank lines between blocks (and map B's build timestamp). luac accepts both scripts.

Verification

  • New test globalsAreNotDeclaredAsNilAtTheTopOfTheScript: globals of each kind (int, real, boolean, string, class, array) emit no top-level nil declaration, get their defaults in the bootstrap, and behave as before on Jass, the interpreter and Lua.
  • Four tests counted the nil declarations to show that each generic static specialisation has its own storage. They now count the specialisations' default assignments in the bootstrap (bootstrapDefaults), which is the same evidence.
  • Local runs (Windows): LuaBackendAuditTests, LuaTranslationTests, LuaKeyedMapTests, LuaHashtableTests, LuaNativesTests, TypeClassTests, ObservableEffectsTests, FastHashMapTests, DeterministicChecks, FieldIterationTests, ClassesTests, NewFeatureTests, GenericsTests, GenericsWithTypeclassesTests, CompiletimeTests pass. The full suite and the other platforms are left to CI.
  • In game, measured on the 3.0.0 client: both maps, built with this change, load, initialise every package and start running with no uncaught error. This covers loading and package initialisation, not gameplay.

Every global, and the runtime's index maps and bootstrap flag, was
declared as `X = nil` at the top of the script. A global Lua has not
seen already reads as nil, and the bootstrap which main runs first gives
each its value, so every declaration was a table write at load which
changed nothing.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 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-18T11:52:28.644094Z 355ed2f 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 04f2782 into master Oct 18, 2026
2 checks passed
@Frotty
Frotty deleted the lua-no-nil-global-declarations 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