-
-
Notifications
You must be signed in to change notification settings - Fork 690
make handles_assign_ops for cpp always true #12390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make handles_assign_ops for cpp always true #12390
Conversation
It would be good to add a test for the behaviour that this fixes, and also we should determine why this was made false for cpp originally. EDIT: looks like the reason is #5545 |
|
Hm, that makes this issue more difficult than I initially suspected. I'll try to investigate... In the meantime I'll also create a test based on #5545 so that issues regarding OpAssignOp can be more easily caught in the future. |
|
Considering this example: public static var vg: Val;
static function testVec() {
var vl = new Val();
vg = new Val();
vg.x += 10;
vl.x += 10;
trace(vg.x, vl.x);
}Here The offending code here is: HXLINE( 31) cpp::Struct< ::_OriginalTest::_Val > fh = ::OriginalTest_obj::vg;
HXDLIN( 31) fh->x = (fh->x + 10);My first idea for a fix was something like the following: HXLINE( 31) cpp::Struct< ::_OriginalTest::_Val > fh = ::OriginalTest_obj::vg;
HXDLIN( 31) ::OriginalTest_obj::vg->x = (fh->x + 10);But this could obviously break easily if you had something like HXLINE( 34) cpp::Struct< ::_OriginalTest::_Val > fh1 = ::OriginalTest_obj::funcWithSideEffects();
HXDLIN( 34) fh1->x = (fh1->x + 5);If my idea above was used, this would call So considering this, here is my "revised" idea:
The main question I have is how feasible it is to track what would trigger copy semantics or not... I'm still very inexperienced when it comes to the Haxe compiler internals, so I'm very sorry if I've said something that makes no sense at all (which could be likely). |
|
I wonder if we could apply this to c++ ffa72bc. This way if the rhs expression doesn't have side effects then the assign op can be generated. It also seems strange to me that it checks for side effects on php but for other targets it just returns true without checking. The issue with |
|
Oh hah, I completely read over that- I think that would work quite well actually... Only one way to find out 😄 |
Previously
+=would not be handled by the analyzer.This issue/fix was found by @Apprentice-Alchemist but I decided to make a PR before it gets forgotten😅
Given:
It would generate
While with this change, or by doing
v.x = v.x + 30.0instead ofv.x += 30.0it would generate:I believe this change is rather crucial as without this change there is a difference in behaviour regarding
x += yandx = x + ywhen usingcpp.Struct<T>(or any type with copy semantics...)You can follow the conversation inside the Haxe discord server here