Repository navigation
Give a closure written inside another closure its owner's type parameters - #1518
Merged
Merged
Conversation
…ters (#1516) * Give a closure written inside another closure its owner's type parameters A closure written in another closure, in a generic class or function, made EliminateGenerics throw "Rewrite generics with wrong sizes" on Jass and Lua whenever either closure used the owner's T, even for a plain field read. The inner closure is translated while the enclosing closure's class is being created, before that class has its captured type variables: the inner closure captured the enclosing this as a class type without type arguments, and the enclosing closure allocated the inner one without them. ClosureTranslator now leaves the type variables of a closure written in another one to the outermost closure, which captures the same variables, all that any closure of the nest uses and in the same order, for each class of the nest, and makes each class name the others with its own variables. A closure with no closure inside it captures what it captured before. With that, EliminateGenerics no longer leaves such closures out of classNeedsIdentity (isInsideAnotherClosure), so on Lua an instanceof Box<T> in an inner closure tells the instantiations apart too. * Turn the test of a rejected nested closure into a success case TypeClassTests pinned that a closure written inside another one in a bounded generic function was rejected on Lua ("could not be resolved for the Lua target"), and asked to become a success case once that works. It works now: the program dispatches on the bound on Jass, the interpreter and Lua.
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.
Re-lands #1516 on master. #1516 was stacked on #1515's branch and was merged into
lua-closure-instanceof-identityafter #1515 had already been squash-merged, so its change never reached master. This is its squash commit 359a92c cherry-picked onto master; the change set is identical, with no conflicts.Checked locally on Windows: LuaBackendAuditTests 280, TypeClassTests 72, ClosureTests 68, GenericSpecialisationMatrixTests 384, all passing.
Original description of #1516:
Stacked on #1515. Merge this PR into that branch first, then #1515 into master. If #1515 lands first, this needs a roll-up PR to master.
When a closure is written inside another closure, in a generic class or function,
EliminateGenericsthrew "Rewrite generics with wrong sizes" on both Jass and Lua. It happened whenever either closure used the owner'sT, even for a plain field read:Cause
The inner closure is translated while the enclosing closure's class is still being created, before that class has its captured type variables. So the inner closure captured the enclosing
thisasMkGet_G_Test⟪⟫, with no type arguments, and the enclosing closure allocated the inner one without type arguments too.Changes
ClosureTranslator: a closure written inside another one no longer captures type variables itself; the outermost closure does it for the whole nest.EliminateGenerics: removes theisInsideAnotherClosureexclusion fromclassNeedsIdentity. Its javadoc described this crash as the reason for leaving such closures out. On Lua, aninstanceof Box<T>in an inner closure now tells the instantiations apart.Tests
LuaBackendAuditTests, each run on Jass, the interpreter and Lua. Each failed before this change: the first four with the crash, the last with an interpreter error.genericFieldReadInAClosureInsideAnotherClosuregenericConstructionInAClosureInsideAnotherClosuregenericInstanceofInAClosureInsideAnotherClosureboundDispatchInAClosureInsideAnotherClosuregenericStaticInAClosureTwoClosuresDeep(three levels of nesting, reading a per-instantiation static)TypeClassTests.nestedClosuresInsideBoundedGenericAreRejectedForLuapinned the old rejection and asked to become a success case once nested closures work. It is nownestedClosuresInsideBoundedGenericDispatchOnTheBound, and passes on Jass, the interpreter and Lua.GenericSpecialisationMatrixTestspasses 384 of 384 cases, run withWURST_GENERIC_MATRIX_KEEP_GOING.LuaBackendAuditTests,FieldIterationTests,ClosureTests,GenericsTests,GenericsWithTypeclassesTests,GenericsModuleTests,GenericStoreSpecializationTests,GenericStoreGeneratedTests,InterpreterTests,CompiletimeTests,LuaTranslationTests,LuaKeyedMapTests,DeterministicChecks,NewFeatureTests,ClassesTests,LuaExemptionTests,LuaNameCompressionTests,LuaCodeListTests.-PallBackends, and Linux or macOS. The change has no host-specific code.-lua -inline -localOptimizations) produces byte-identical Lua with and without this change.