Repository navigation
Swapping two arrays seems to behave asynchronous outside function #11047
Description
Activity
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
for,if, etc.) only include the next statement if there are no braces surrounding the block.Using the latter code block outputs:
1 1 1every 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.
- addedquestionIssues asking questions about Node.js.Issues asking questions about Node.js.
on Jan 28, 2017 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.
- addedv8 engineIssues and PRs related to the V8 dependency.Issues and PRs related to the V8 dependency.
on Jan 28, 2017 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
console.logof Node.js being async (just guessing)?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.
../node/node --trace-opt --trace-opt-verbose 11047.js [marking 0x15b90280b079 <JS Function Uint8ArrayConstructByLength (SharedFunctionInfo 0x9c5d7c18c49)> for optimized recompilation, reason: small function, ICs with typeinfo: 5/4 (125%), generic ICs: 0/4 (0%)] [compiling method 0x15b90280b079 <JS Function Uint8ArrayConstructByLength (SharedFunctionInfo 0x9c5d7c18c49)> using Crankshaft] [optimizing 0x15b90280b079 <JS Function Uint8ArrayConstructByLength (SharedFunctionInfo 0x9c5d7c18c49)> - took 0.299, 0.610, 0.256 ms] [completed optimizing 0x15b90280b079 <JS Function Uint8ArrayConstructByLength (SharedFunctionInfo 0x9c5d7c18c49)>] true [marking 0x2d3813104d61 <JS Function func (SharedFunctionInfo 0x364a935e0d49)> for optimized recompilation, reason: hot and stable, ICs with typeinfo: 23/45 (51%), generic ICs: 1/45 (2%)] true [compiling method 0x2d3813104d61 <JS Function func (SharedFunctionInfo 0x364a935e0d49)> using TurboFan] [compiling method 0x2d3813104d61 <JS Function func (SharedFunctionInfo 0x364a935e0d49)> using TurboFan OSR] [optimizing 0x2d3813104d61 <JS Function func (SharedFunctionInfo 0x364a935e0d49)> - took 3.026, 4.122, 0.493 ms] [optimizing 0x2d3813104d61 <JS Function func (SharedFunctionInfo 0x364a935e0d49)> - took 3.700, 5.486, 0.439 ms] [completed optimizing 0x2d3813104d61 <JS Function func (SharedFunctionInfo 0x364a935e0d49)>] false../v8-node/node --trace-opt --trace-opt-verbose 11047.js [marking 0x2f78f9123ea9 <JS Function Uint8ArrayConstructByLength (SharedFunctionInfo 0x155859394e81)> for optimized recompilation, reason: small function, ICs with typeinfo: 5/7 (71%), generic ICs: 0/7 (0%)] [compiling method 0x2f78f9123ea9 <JS Function Uint8ArrayConstructByLength (SharedFunctionInfo 0x155859394e81)> using Crankshaft] [optimizing 0x2f78f9123ea9 <JS Function Uint8ArrayConstructByLength (SharedFunctionInfo 0x155859394e81)> - took 0.466, 1.584, 1.494 ms] [completed optimizing 0x2f78f9123ea9 <JS Function Uint8ArrayConstructByLength (SharedFunctionInfo 0x155859394e81)>] true [marking 0x35259e304cb9 <JS Function func (SharedFunctionInfo 0x23db7f3d92c9)> for optimized recompilation, reason: hot and stable, ICs with typeinfo: 20/39 (51%), generic ICs: 2/39 (5%)] true [compiling method 0x35259e304cb9 <JS Function func (SharedFunctionInfo 0x23db7f3d92c9)> using TurboFan] trueThis should probably be fixed by #10992. cc @nodejs/v8
cc @nodejs/v8 (@joyeecheung 's mention didn't work).
/cc @bmeurer
- removedquestionIssues asking questions about Node.js.Issues asking questions about Node.js.
on Feb 2, 2017 Upd: this comment had a mistype, amended.
Can't reproduce on Linux and Node.js 7.5.0.
Removed «question» label, though, as it seems that this is an actual issue that has been confirmed above.It's a bug in V8, here's a minimal repro that fails in
d8(ran with--allow-natives-syntaxin 5.4.500.43):(function() { 'use strict'; let first = 1; let second = 2; let getFirst = () => first; let func = () => { [first, second] = [second, first]; return first === getFirst(); }; print(func()); print(func()); %OptimizeFunctionOnNextCall(func); print(func()); })();Doesn't fail on ToT tho, so it's already fixed. It's clearly a bug in TurboFan generated code.
Even simpler repro:
(function() { 'use strict'; let first = 1; let getFirst = () => first; let func = (x) => { [first] = [x]; return first === getFirst(); }; print(func(2)); print(func(3)); %OptimizeFunctionOnNextCall(func); print(func(4)); })();The bug is that the Parser tells TurboFan that
firstis never re-assigned, and thus TurboFan constant-foldsfirstwhen inlininggetFirstintofunc. The fix is in crrev.com/2562443003.- addedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.
on Feb 6, 2017 #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: