Repository navigation
Lua: tell the instantiations of a generic class apart in instanceof - #1507
Conversation
On Lua a new-generic class stays erased, so x instanceof Box<int> was true for a Box<string>, and for a Box<CB> against Box<CA>. Only tuple programs gave an observed instantiation an identity of its own, because the collection of instanceof targets ran only when a tuple type argument was present. Collect the instantiations an instanceof names whenever one does, and enter the Lua specialisation for such programs. A generic function or method which constructs a class with an observed instantiation is now specialised at its callers, so the object it allocates carries the identity the check compares. Instantiations no instanceof names stay erased, and programs without a parameterised instanceof emit the same 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: 4c06c6bd85
ℹ️ 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".
An object allocated from the class an instanceof observes, such as a Box<int>, was still called through the virtual methods of its interface and base class, but the copy's methods were bound to those roots only for tuple and construction-only specialisations. The call found no slot on the specialised class and failed at run time. Bind the copied methods of such a class like a tuple specialisation's, also for a class specialised before an instanceof named its instantiation. The classes are walked in program order there, because binding appends to the submethod lists whose order names the slots.
Fourteen instanceof cases now pass and leave the list. Five closure cases
now stop at the closure receiver defect and take its tag. In eleven the
check tells the instantiations apart but the object was allocated by an
erased writer ("expected 3 but got 2"); that is still lua-instanceof-erased,
which the matrix now recognises. The backlog entry describes what remains:
a generic class reached through a non-generic interface, base class or
destroy.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
When new Box<T>() is reached through an interface, base-class, destructor, or similar virtual-dispatch path, that writer can remain erased while this code gives the instanceof Box<T> target a specialized identity. A real Box<int> then fails instanceof Box<int> on Lua even though it previously passed; the newly checked-in matrix baseline confirms this regression with eleven expected 3 but got 2 cases in genericSpecialisationMatrix-knownFailures.txt:55-82. Ensure those allocation paths are redirected before splitting the target identity, or retain the erased check until they can be redirected.
AGENTS.md reference: AGENTS.md:L318-L322
ℹ️ 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 construction in a generic body which stays erased, such as a method reached through a non-generic interface, allocates the erased class for every instantiation. A check of the specialised class then rejected such an object even when it was of the checked instantiation, which an erased check had accepted. Split a class's identity only when no reachable erased construction makes an object of it or of a subclass; otherwise its checks go back to the erased class. Programs with tuple type arguments keep the split they had. The eleven matrix cases which showed this return to their listed symptom, so the matrix's check of that symptom is reverted.
|
Round-2 P1 (identity split while an allocation stays erased) addressed in e777b6b: after specialisation, |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e777b6b7bf
ℹ️ 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 closure in a generic class was specialised on construction when its body checked instanceof Box<T> or constructed an observed Box<T>. Specialising it leaves its captured receiver typed by the erased class, the closure receiver defect, so programs which compiled before were rejected. An instanceof identity is no longer a reason to specialise a closure, except in programs with tuple type arguments, which keep what they counted before. The closure stays erased, its constructions keep the erased check, and the five matrix cases return to their listed symptom.
|
@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". |
…ure (#1515) * Lua: tell the instantiations apart in an instanceof written in a closure 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. * Compare instantiations in the interpreter's instanceof as the specialisation 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. * Check every path to a generic supertype in the interpreter's instanceof 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.
On Lua a new-generic class stays erased, so
x instanceof Box<int>was true for aBox<string>, and for aBox<CB>againstBox<CA>; Jass, which specialises every instantiation, answers correctly. No generic code is needed:Found by the bounded-exhaustive matrix of #1505 (tag
lua-instanceof-erased).Cause
EliminateGenerics.transformGenericNewOnlycollected the instantiations aninstanceofnames (collectRuntimeTypeSpecializations) only when a tuple type argument was present, andtransformProgToLuadid not enter the Lua specialisation for a program whose only need was a parameterisedinstanceof.new Box<T>()inside generic code was not treated as needing specialisation whenBox's identity is observed, so the object it allocated stayed erased.Change
WurstCompilerJassImpl.containsParameterizedInstanceof()also gates the Lua specialisation phase and is passed totransformGenericNewOnly(tuples, observesGenericIdentity), which now gates the instanceof collection on it.EliminateGenerics.constructsClassWithObservedIdentity: a generic caller that constructs a class (or subclass) whose instantiation aninstanceofnames is specialised at the caller boundary, likeconstructsClassOwningGenericGlobals.Only the instantiations an
instanceofnames get an identity of their own; every other allocation stays erased. Programs without a parameterisedinstanceofemit the same Lua: the 258 Lua scripts of LuaBackendAuditTests and LuaTranslationTests are byte-identical to master's.Evidence
Seven new LuaBackendAuditTests cases (run on Jass too), each red on Lua before the fix: the program above, class arguments, a positive check, a subclass, and checks through generic code. They use
executeProgOnlyAfterTransforms()because the IM interpreter ignores the type arguments ofinstanceofon untranslated generic IM (EvaluateExpr.eval(ImInstanceof)), a separate defect not fixed here.Passing locally: LuaBackendAuditTests 250, LuaTranslationTests 144, TypeClassTests 72, GenericsWithTypeclassesTests 115, FieldIterationTests 43, GenericStoreGeneratedTests 48, GenericStoreSpecializationTests 21, DeterministicChecks 27, ClassesTests 128.
Not fixed yet (cross-checked against #1505's matrix)
With this change applied to #1505, the
INSTANCEOF_cases change as follows; none that passed before fails:lua-closure-receivercompile error ("Could not adapt receiver") instead of compiling with wrong results.These remaining failures are the erased-dispatch defect, which needs its own fix. Whichever of this PR and #1505 merges second updates
genericSpecialisationMatrix-knownFailures.txt(remove the 14, update the 16 symptoms).Tested on Windows with the bundled Lua 5.3; Linux runs in PR CI, macOS only on master. The change is IM logic with no host dependence.