Repository navigation
Give a member reached through an old-generic value its class's type arguments - #1531
Conversation
…rguments A field read, field write or method call on an old-generic value whose type argument is a new-generic class, such as h.item.value with h a Holder<Box<int>> or id(b).value with an old-generic id, failed on Jass: "Could not find field array for Holder_item[h].Box_value", or an index error in specializeMethod for h.item.get(). EliminateGenerics gives a member access or method call the type arguments of the member's class from the receiver's IM type (addMemberTypeArguments). An old-generic value is erased to any in the IM, so the receiver had no class type, the access kept no type arguments and still named the member of the unspecialised Box, which class elimination has no field array for. Reading through a local of type Box<int> worked because the local carries the type. The translation still has the receiver's Wurst type, so it now supplies the class's type arguments when the translated receiver is erased: from the receiver type itself or the supertype that declares the member. Field accesses go through one helper, method calls prepend the arguments to their own. Every other receiver is unchanged and gets its arguments from its IM type as before. The IM shape is otherwise the same as for a typed receiver, so neither backend emits anything new.
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: 2518046b34
ℹ️ 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".
…class's type arguments The previous change supplied the class's type arguments to field accesses and method calls whose receiver is an erased old-generic value, but three other translations build a call on such a receiver themselves. With h a Holder<Box<int>> and Box<T:> a new-generic class, h.item + "!" calling Box.toString implicitly, destroy h.item, and for x from h.item each still reached the members of the unspecialised Box on Jass: an index error in specializeMethod for the first two, and a method call left for the Jass translation for the loop. The implicit toString call and the destroy call now take their type arguments from erasedReceiverTypeArguments, as the explicit method call does. The for-from loop stores its target in a variable typed by the erased IM type, so the hasNext and next calls on that variable had no class to read the arguments from; the variable now takes the class of the target's Wurst type when the target is erased, as a local declared with that type would. The other direct constructions of a member access or method call cannot see an erased receiver: class field initialisers and closures access through this or a closure variable of a class type, null-safe accesses and cascades store the receiver in a variable of its Wurst type, the for-in loop calls iterator() with its own type arguments, and the later passes copy an existing access with its type arguments.
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! 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". |
…rough-old-generic # Conflicts: # de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/GenericsTests.java
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! 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". |
Problem
A new-generic class's member reached through an old-generic value failed on Jass:
Reading through a local (
Box<int> item = h.item) worked. A method callh.item.get()failed too, with anArrayIndexOutOfBoundsExceptioninspecializeMethod.EliminateGenerics.addMemberTypeArgumentstakes a member access's or method call's class type arguments from the receiver's IM type. An old-generic value is erased toany, so the access kept no type arguments and still named the field of the unspecialisedBox<T>, which class elimination has no array for. The Wurst type of the receiver still had them, so the information was lost in the AST-to-IM translation.Change
When the translated receiver's IM type is
any, the translation supplies the class's type arguments from the receiver's Wurst type, or from the supertype that declares the member (ExprTranslation.erasedReceiverTypeArguments). All six translation sites that create a field access with a receiver go through one helper (memberAccess): reads, lvalues, and the overloaded[]get and set. A dynamic-dispatch method call adds the same arguments in front of its own. Receivers of any other IM type are unchanged, and no IM nodes are added.Tests
In
GenericsTests, run in the interpreter, on Jass and on Lua. Each failed on master:-inline -localOptimizations;h.item.value = 7);id(b).value);Sub<U:> extends Box<U>inHolder<Sub<string>>).A non-generic
Boxand a new-genericHolder<T:>already passed.Windows, bundled Lua 5.3,
-PallBackends: GenericsTests 109 and CompiletimeTests 64 on master after #1527. Before the rebase: GenericsWithTypeclassesTests 119, ClassesTests 128, LuaBackendAuditTests 285, GenericSpecialisationMatrixTests 384 and DeterministicChecks 29. Two large real maps compile to byte-identical optimised Lua, and one also to byte-identical Jass. Not done: Linux and macOS.Not covered: an old-generic value whose argument is a new-generic type variable, rather than a concrete class, gets no type arguments, as before.
Found while fixing the defects from the 19-21 Oct audit (#1528).