Repository navigation
Lua: declare no global as nil at the top of the script - #1495
Merged
Merged
Conversation
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.
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every global was declared as
X = nilat 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 whichmainruns 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 beforemain, sees nil for these globals either way.Effect on two large maps
Built with
-lua -inline -localOptimizations:With the
X = nillines 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).luacaccepts both scripts.Verification
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.bootstrapDefaults), which is the same evidence.LuaBackendAuditTests,LuaTranslationTests,LuaKeyedMapTests,LuaHashtableTests,LuaNativesTests,TypeClassTests,ObservableEffectsTests,FastHashMapTests,DeterministicChecks,FieldIterationTests,ClassesTests,NewFeatureTests,GenericsTests,GenericsWithTypeclassesTests,CompiletimeTestspass. The full suite and the other platforms are left to CI.