Repository navigation
Interpreter: an object read back from an old generic is that object - #1525
Conversation
Compile-time code which put an object into an old-generic container and
read it back got a different value: `m.get(7) == a` was false for a
HashMap<int, A>, and the false was baked into the script on every target,
while the same function answered true at run time.
An old generic erases its value to an int on the way in (castTo int) and
the value leaves the generic as `any` with no cast back, so before class
elimination the interpreter holds the object's id where the program has
the object. The class-value consumers (member access, method calls,
instanceof, destroy) already read such an id as its object through
ProgramState.toObject, but == and != compared an ILconstObject by
identity, so it never equalled its own id. An assignment to a field of
such a value failed as well: the lvalue member access took the class only
from the receiver's type, which is `any`, and looked the id up in every id
space, where the container's own id collided with it ("Ambiguous object
id").
== and != now compare an object and an int by the object's id, as both
targets do, and the lvalue member access falls back to the class which
declares the field, as the rvalue access already did. Tests cover HashMap
(both operand orders and !=), HashList, nested containers, and a field
write and method call on the value read back. LinkedList, which keeps the
object itself, a Table id cast back explicitly, and a null value already
behaved.
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. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3b7918bab7
ℹ️ 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".
…-generic-identity
|
Codex Review: Didn't find any major issues. Another round soon, please! 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". |
== compared the elements of tuples with the interpreter's object-or-id rule, but != fell back to raw equality of the whole tuple, so a tuple holding a value read back from an old generic was both == and != to the same tuple with the original object, and compile time could bake either answer. sameValue, which != negates, now compares tuple elements the same way, reals exactly as != does.
|
@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". |
Problem
In compile-time code,
let a = new A; let m = new HashMap<int, A>; m.put(7, a); return m.get(7) == agavefalse, and that result was baked into the script on every target. At run time (Jass, and the interpreter on the transformed program) it istrue.An old generic's
VisImAnyTypein the IM.HashMap.getends incastTo any, and its caller uses the result as anAwithout a cast back. So before class elimination the interpreter holds the object's integer id where the program has the object. Member access, method calls,instanceofanddestroyalready accept that id (ProgramState.toObject). But==and!=compared anILconstObjectby identity, so an object never equalled its own id.A sibling turned up while testing: writing a field of such a value (
m.get(7).x = 4) failed with "Ambiguous object id 1 in multiple id spaces". The write took the class only from the receiver's type, which isany.Change
WurstOperator:==(also inside tuples) and!=compare an object and an int by the object's id, in either order (sameValue), as both targets do, since an object is its id there. Reals and tuples are unchanged, andILconst.equals/hashCodeare untouched. The operator's other callers are constant folding (AttrConstantValue), which never sees objects, and the Jass interpreter, which runs translated code where objects are ints.EvaluateExpr: a field write on a receiver of typeanyfalls back to the class that declares the field, as the read already did (memberAccessClassType, shared).Tests
Five tests in
CompiletimeTests, each run at compile time and at run time. Each failed without the change:HashMaprepro, and both operand orders with!=;HashList;HashMap<int, HashMap<int, A>>andHashMap<int, LinkedList<A>>);==fix).Windows, bundled Lua 5.3,
-PallBackends: CompiletimeTests 55, InterpreterTests 29, GenericsTests 81, NewFeatureTests 42, LuaBackendAuditTests 285, ClassesTests 128, DeterministicChecks 29, plus WurstOperatorTests 4, all passing. Not done: Linux and macOS.Found by a defect audit of the 19-21 Oct merges.