Repository navigation
Lua: tell the instantiations apart in an instanceof written in a closure - #1515
Conversation
An instanceof Box<T> in a closure written in a method of a generic class accepted every Box on Lua. #1507 kept closures erased for an instanceof, because specialising one left its captured receiver typed by the erased class; #1512 fixed that receiver, so the exclusion is lifted: an instanceof of the type parameter now counts towards a closure's identity like any other member which needs its type argument. A closure which constructs the Box<T> another closure checks still stayed erased. Box<int> is observed only once the checking closure is specialised, in the second round, but classNeedsIdentity keeps its first answer, given in the first. Whether an instanceof observes a class is now collected once, before the specialisation, from every parameterised instanceof, including one still written with a type variable. The IM interpreter compared only the class in an instanceof, so it took a Box<string> for a Box<int> in compile-time code and @test functions. It now compares the type arguments of the instantiation too. The audit tests for instanceof identity run the interpreter on the generic program again. Removes the nine INSTANCEOF_CLOSURE cases from the matrix's known failures and the lua-instanceof-erased backlog entry. Records a crash found on the way: a closure inside another closure which uses its owner's T fails in EliminateGenerics on Jass 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3fd442a30a
ℹ️ 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".
…isation does Type-class bindings are dispatch metadata, which GenericTypes ignores at every nesting level when it tells specialisations apart; the interpreter now compares an object's instantiation with the checked one the same way, instead of through equalsType, which compares nested bindings. Adds a check of a type argument with a bound inside it, built directly and through generic functions.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3e5f5791bb
ℹ️ 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".
A class which reaches one generic interface through two others, as G<int> and as G<string>, is an instance of both, as on Jass and Lua. The interpreter compared the checked instantiation with the first path to the interface only, so one of the two checks was false. It now collects the instantiations of every path.
|
@codex review |
…eof-identity # Conflicts: # BACKLOG.md
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…lasses in the interpreter (#1524) * Bind an inherited generic method's type parameters through the superclasses in the interpreter A method a class inherits from a generic superclass (class Sub extends G<int>) ran in the IM interpreter with G's T unbound. The interpreter bound the type variables of the method's class positionally from the receiver's own type arguments, so a Sub, which has none, left T open. A new Box<T>() in such a method was then recorded as Box<T>: since #1515 its instanceof threw "Cannot decide whether Box<T> is a Box<integer>", and before that it took the object for a Box<string> too. A static of G read in such a method was keyed apart from the one G<int> writes, so it read as uninitialised. Jass and Lua were right, because their specialisation follows the superclass edge, as ImAttrType does for IM types since #1510. The interpreter now takes the receiver's type as an instance of the method's class through the superclass chain (ProgramState.adaptToSuperclass) before it binds that class's type variables. Adds tests for an instanceof of an object made in an inherited method, through one and two generic superclasses and in a default method of a generic interface, and for a static per instantiation read in an inherited method, on Jass, Lua and the interpreter. * Test an inherited method of an old generic class too The interpreter's binding of an inherited method's type parameters through the superclasses serves both generic systems. An old generic's parameter is erased, so cover a value returned by a method inherited through one and two old-generic superclasses, in the interpreter and on both targets.
An
instanceof Box<T>written in a closure inside a method of a new-generic classG<T:>accepted everyBoxinstantiation on Lua. Jass was right. This was thelua-instanceof-erasedbacklog tag, the last one the generic specialisation matrix listed.Changes
EliminateGenerics.classNeedsIdentity: Lua: tell the instantiations of a generic class apart in instanceof #1507 stopped aninstanceoffrom giving a closure an identity of its own, because specialising the closure left its captured receiver typed by the erased class. Lua: allocate an instantiation whose members need its type argument from its specialised class #1512 fixed that receiver, so the exclusion (identityIgnored) is removed. Aninstanceofof the type parameter now counts for a closure the same as for any other member that needs its type argument.instanceofobserves is collected once, before specialisation starts (classesWithObservedIdentity). This includes checks still written with a type variable. A closure that constructs theBox<T>which another closure checks used to stay erased:Box<int>only became observed in the second round, butclassNeedsIdentitykeeps the answer it gave in the first round. Every object it made was then of the erased class, sokeepErasedChecksWhereAnAllocationStaysErasedput every check ofBoxback to the erased class.instanceofcompared only the class. In compile-time code and@Testfunctions this took aBox<string>for aBox<int>. It now also compares the type arguments of the instantiation. If an instantiation cannot be resolved there, it throws an explicitInterpreterException. It compares instantiations the way the specialisation does (GenericTypes, which ignores type-class bindings), and it checks every path to a generic supertype: a class can reachG<int>andG<string>through two interfaces. The instanceof audit tests used to run the interpreter only after the transformations, and that is how this went unnoticed. They now run it on the generic program too.Tests
LuaBackendAuditTests, with Jass and the interpreter as the oracle:genericInstanceofInAClosureRejectsAnotherInstantiationgenericInstanceofOfAnObjectAnotherClosureConstructsgenericInstanceofThroughANonGenericInterfacegenericInstanceofOfANestedBoundTypeArgumentandgenericInstanceofThroughTwoPathsToOneGenericInterface, from the Codex review. The second failed in the interpreter before its fix. The first did not fail before: no divergence in bindings was found, so it guards theGenericTypescomparison.INSTANCEOF_CLOSURE_*cases are removed fromgenericSpecialisationMatrix-knownFailures.txt. WithWURST_GENERIC_MATRIX_KEEP_GOING, the pull-request tier passes 384 of 384 cases.GenericSpecialisationMatrixTests,LuaBackendAuditTests,FieldIterationTests,ClosureTests,GenericsTests,GenericsWithTypeclassesTests,GenericsModuleTests,GenericStoreSpecializationTests,GenericStoreGeneratedTests,InterpreterTests,CompiletimeTests,LuaTranslationTests,LuaKeyedMapTests,DeterministicChecks,NewFeatureTests,ClassesTests,LuaExemptionTests.-PallBackends, and the full matrix product. Linux and macOS are not verified locally either. The change has no host-specific code.instanceof(-lua -inline -localOptimizations) produces byte-identical Lua with and without this change. That is expected: the changed paths run only when a program contains a parameterisedinstanceof.Backlog
lua-instanceof-erasedentry is removed.Tfails inEliminateGenericswith "Rewrite generics with wrong sizes".