Object `+= lfuns are not called when they should have been.
Well. That depends on how you define "should have been.". :)
`+= has never been called except when there is only one reference to the object, which is why it can be somewhat confusing. It does allow optimizations since the value can be modified destructively, however.
And, really, X += Y only implies that the variable X will have Y added to it, it is not the same as whatever X pointing to getting Y added.
(this is much the same as if there had been a `=, assignment overloading)
Consider:
| mapping m = ([]); | object o = 1003443894984389348989434389; | multiset z = (<>); | array q = ({}); | string b = "";
In which cases should using += change not only the variable but also what it points to?
I think this would be somewhat confusing, as an example:
| object a = 18042893489438948390; | object b = 182389983498439843983498; | object c = b;
a += b;
// afterwards c == b, while I would expect (a-b == c) to be true.
As for how the += optimization is supposed to work:
- For one, the object might have an extra instance on the stack, in which case the minimum number of references becomes 2 already.
Well, this should be mostly fixed by the fact that a = a + X; should be handled differently than other additions, the lvalue (the variable being assigned to and read from) is actually cleared before the addition happens.
The code that is supposed to ensure this is the case lives in line 1337 in las.c (nice..).
The non-existence of +=/-= etc as actual opcpdes is done in treeopt.in, but note that even if those rules are removed there is actually no += opcode in the generated code, and there never has been to my knowledge, the conversion was done in docode.c previously however, which led to a lot of code duplication.
- And for another, the object might have multiple instances which all refer to the same object; which *implies* that updating one of those using += should modify all of them.
Well. Not really, in pike. Adding things to a variable only ever change the variable, not the thing it points to.