-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Swapping two arrays seems to behave asynchronous outside function #11047
Comments
This kind of question is better suited for the nodejs/help repo. FWIW though, your first example outputs 'true' every time for me. Your second example has a potential issue because of the way you're styling your loops. Specifically, this block: for(y = 0; y < h; y++) for(x = 0; x < w; x++){
// If I change the number 1 to 0 from this line, it prints 111
if((first[x | 0][y | 0] | 0) + 1);
}
[first, second] = [second, first]; is equivalent to: for(y = 0; y < h; y++) {
for(x = 0; x < w; x++) {
if((first[x | 0][y | 0] | 0) + 1);
}
}
[first, second] = [second, first]; instead of what you may be expecting: for(y = 0; y < h; y++) {
for(x = 0; x < w; x++) {
if((first[x | 0][y | 0] | 0) + 1);
}
[first, second] = [second, first];
} The reason is that control blocks (like Using the latter code block outputs:
every time. However, this is a total guess because I have no idea what your actual intentions are. I would suggest using braces and not placing multiple statements like that on a single line to avoid potential confusion like this in the future. |
I think you misunderstood my question. You don't have to explain me how syntax works, I am programming in JavaScript for five years and I also created my own JavaScript engine in pure assembler. My loop statements are placed exactly as it is supposed to be. The problem is strongly related to v8 engine here. Look at line where console log is called. We compare variable called first with output of function which returns first. No matter where and how we call it, it should return true always, but third time it is called it returns false. You can see it on image I posted. |
I can confirm this is a V8 bug and it still presents in the master. However it is fixed in https://github.com/v8/node/tree/vee-eight-lkgr. Not sure what commit causes this without bisecting though. |
P.S. I can narrow down the working V8 to 5.5.372.33 with the stable Chrome.. EDIT: That seems odd, the master has V8 5.5.372.40, it's probably a regression or something, or it has something to do with FWIW looks like it has something to do with TurboFan OSR. I've replaced the tenary expression with just the equality check so it prints true/false instead of 1/0 here.
|
I think I found what possibly may cause the problem. Look at this code. TurboFan caches the result of comparison, but in my code variables first and second are swapped. According to optimization techniques used in TurboFan, first are cached, but its value is actually second, when compared to real first variable it results false. |
This should probably be fixed by #10992. cc @nodejs/v8 |
cc @nodejs/v8 (@joyeecheung 's mention didn't work). |
/cc @bmeurer |
Upd: this comment had a mistype, amended. Can't reproduce on Linux and Node.js 7.5.0. |
Forgot to mention I'm on Darwin 15.6.0. Just tried out #10992, the bug is fixed in that brach :D. Master (58dc229) still has it though. |
It's a bug in V8, here's a minimal repro that fails in
Doesn't fail on ToT tho, so it's already fixed. It's clearly a bug in TurboFan generated code. |
Even simpler repro:
The bug is that the Parser tells TurboFan that |
@ofrobots Maybe it would be worth to add "confirmed-bug" label on this issue. |
#10992 was merged last week so I'll go ahead and close this out. |
Version: v7.1.0
Platform: Windows 8.1; 64-bit
Issue details: Swapping two variables from a function sometimes behaves like it is asynchronous as seen from outside that function, but synchronous from inside. It only happens when variables are swapped using the following short syntax:
However, it doesn't hapen every time. This is an example
However, it doesn't work always. But, after a few hours of testing, I came up with the following code, which always prints wrong output:
Here is how output looks like. I cannot find any possible explanations why is zero here:
The text was updated successfully, but these errors were encountered: