RESOLVED FIXED 182214
[ESNext][BigInt] Implement "+" and "-" unary operation
https://bugs.webkit.org/show_bug.cgi?id=182214
Summary [ESNext][BigInt] Implement "+" and "-" unary operation
Caio Lima
Reported 2018-01-27 10:08:46 PST
...
Attachments
Patch (26.25 KB, patch)
2018-01-27 10:46 PST, Caio Lima
no flags
Patch (26.32 KB, patch)
2018-01-27 19:08 PST, Caio Lima
no flags
Archive of layout-test-results from ews104 for mac-sierra-wk2 (2.56 MB, application/zip)
2018-01-27 20:22 PST, EWS Watchlist
no flags
Patch (45.12 KB, patch)
2018-02-02 16:14 PST, Caio Lima
no flags
Patch (46.35 KB, patch)
2018-02-04 17:10 PST, Caio Lima
no flags
Patch to test on EWS (80.44 KB, patch)
2018-03-09 15:27 PST, Caio Lima
no flags
Patch (47.16 KB, patch)
2018-04-11 08:44 PDT, Caio Lima
no flags
Archive of layout-test-results from ews206 for win-future (12.46 MB, application/zip)
2018-04-11 11:09 PDT, EWS Watchlist
no flags
Patch (46.71 KB, patch)
2018-04-16 19:40 PDT, Caio Lima
ews-watchlist: commit-queue-
Archive of layout-test-results from ews102 for mac-sierra (2.38 MB, application/zip)
2018-04-16 20:56 PDT, EWS Watchlist
no flags
Patch (44.51 KB, patch)
2018-04-23 05:51 PDT, Caio Lima
no flags
Patch updated (44.51 KB, patch)
2018-04-26 19:55 PDT, Caio Lima
no flags
Patch (46.73 KB, patch)
2018-05-01 15:51 PDT, Caio Lima
no flags
Patch (46.91 KB, patch)
2018-05-01 16:31 PDT, Caio Lima
no flags
Archive of layout-test-results from ews200 for win-future (12.93 MB, application/zip)
2018-05-01 18:57 PDT, EWS Watchlist
no flags
Patch (46.91 KB, patch)
2018-05-05 08:02 PDT, Caio Lima
no flags
Patch (47.22 KB, patch)
2018-05-10 19:03 PDT, Caio Lima
no flags
Patch (45.75 KB, patch)
2018-05-13 08:29 PDT, Caio Lima
no flags
Archive of layout-test-results from ews117 for mac-sierra (3.02 MB, application/zip)
2018-05-13 10:14 PDT, EWS Watchlist
no flags
Benchmark results (93.14 KB, text/plain)
2018-05-13 11:45 PDT, Caio Lima
no flags
Patch (47.35 KB, patch)
2018-05-20 14:57 PDT, Caio Lima
ysuzuki: review+
Benchmark Report (93.94 KB, text/plain)
2018-05-20 18:07 PDT, Caio Lima
no flags
Patch For landing (45.33 KB, patch)
2018-05-25 07:30 PDT, Caio Lima
no flags
Patch for landing (45.29 KB, patch)
2018-05-27 18:46 PDT, Caio Lima
no flags
Caio Lima
Comment 1 2018-01-27 10:46:15 PST
EWS Watchlist
Comment 2 2018-01-27 11:53:46 PST
Comment on attachment 332473 [details] Patch Attachment 332473 [details] did not pass jsc-ews (mac): Output: http://webkit-queues.webkit.org/results/6234382 New failing tests: stress/arith-negate-on-various-types.js.default stress/arith-negate-on-various-types.js.no-cjit-collect-continuously stress/arith-negate-on-various-types.js.ftl-no-cjit-validate-sampling-profiler stress/arith-negate-on-various-types.js.no-cjit-validate-phases stress/arith-negate-on-various-types.js.ftl-no-cjit-b3o1 stress/arith-negate-on-various-types.js.ftl-no-cjit-no-inline-validate stress/arith-negate-on-various-types.js.no-ftl stress/arith-negate-on-various-types.js.no-llint
Caio Lima
Comment 3 2018-01-27 19:08:35 PST
EWS Watchlist
Comment 4 2018-01-27 20:22:18 PST
Comment on attachment 332485 [details] Patch Attachment 332485 [details] did not pass mac-wk2-ews (mac-wk2): Output: http://webkit-queues.webkit.org/results/6237172 New failing tests: fast/workers/worker-cloneport.html
EWS Watchlist
Comment 5 2018-01-27 20:22:19 PST
Created attachment 332486 [details] Archive of layout-test-results from ews104 for mac-sierra-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: ews104 Port: mac-sierra-wk2 Platform: Mac OS X 10.12.6
Caio Lima
Comment 6 2018-02-02 16:14:27 PST
Caio Lima
Comment 7 2018-02-04 17:10:40 PST
Saam Barati
Comment 8 2018-02-05 10:25:30 PST
Comment on attachment 333056 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=333056&action=review Some initial comments. I still need to review some parts in more detail. > Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:721 > + forNode(node).setType(m_graph, SpecBytecodeNumber | SpecCellOther); Why SpecCellOther and not BigInt directly? > Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:-945 > - // We'd like to assert here that the arith profile for the result of negate never > - // sees a non-number, but we can't. It's true that negate never produces a non-number. > - // But sometimes we'll end up grabbing the wrong ArithProfile during OSR exit, and > - // profiling the wrong value, leading the ArithProfile to think it observed a non-number result. Why remove this comment? > Source/JavaScriptCore/jit/JITOperations.cpp:2686 > + JSValue result = JSValue(JSBigInt::unaryMinus(exec, asBigInt(primValue.asCell()))); why do you need the asCell here? We should juts add a asBigInt(JSValue) function if we don't already have one. > Source/JavaScriptCore/runtime/CommonSlowPaths.cpp:408 > + if (UNLIKELY(throwScope.exception())) > + RETURN(JSValue()); I think you just want: EXCEPTION_CHECK() here > JSTests/stress/big-int-negate-jit.js:32 > +/* > +function negateBigInt(n) { > + return -n; > +} > +noInline(negateBigInt); > + > +for (let i = 0; i < 100000; i++) { > + assert(negateBigInt(100n), -100n); > + assert(negateBigInt(-0x1fffffffffffff01n), 0x1fffffffffffff01n); > +} > + > +if (numberOfDFGCompiles(negateBigInt) > 1) > + throw "Failed negateBigInt(). We should have compiled a single negate for the BigInt type."; > + > +function negateBigIntSpecializedToInt(n) { > + return -n; > +} > +noInline(negateBigIntSpecializedToInt); > + > +for (let i = 0; i < 100000; i++) { > + negateBigIntSpecializedToInt(100); > +} > + > +assert(negateBigIntSpecializedToInt(100n), -100n); > +*/ Why is this commented out?
Saam Barati
Comment 9 2018-02-05 10:27:03 PST
Comment on attachment 333056 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=333056&action=review >> Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:721 >> + forNode(node).setType(m_graph, SpecBytecodeNumber | SpecCellOther); > > Why SpecCellOther and not BigInt directly? I see, we don't have SpecBigInt yet... We should add at some point, along with the necessary compiler changes.
Saam Barati
Comment 10 2018-02-05 10:27:22 PST
Comment on attachment 333056 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=333056&action=review >> Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:-945 >> - // profiling the wrong value, leading the ArithProfile to think it observed a non-number result. > > Why remove this comment? Ignore this. I see why you removed it.
Saam Barati
Comment 11 2018-02-05 10:32:50 PST
Comment on attachment 333056 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=333056&action=review > Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp:201 > + SpeculatedType prediction = node->child1()->prediction(); > + if (prediction) { > + if (isInt32OrBooleanSpeculation(prediction) && node->canSpeculateInt32(m_pass)) > + changed |= mergePrediction(SpecInt32Only); > + else if (m_graph.unaryArithShouldSpeculateAnyInt(node, m_pass)) > + changed |= mergePrediction(SpecInt52Only); > + else if (isBytecodeNumberSpeculation(prediction)) > + changed |= mergePrediction(speculatedDoubleTypeForPrediction(node->child1()->prediction())); > + else { > + changed |= mergePrediction(SpecInt32Only); > + if (node->mayHaveNonNumberResult()) { > + // FIXME: We should add support to BigInt into speculation > + // https://bugs.webkit.org/show_bug.cgi?id=182470 > + changed |= mergePrediction(SpecCellOther); > + } > + if (node->mayHaveDoubleResult()) > + changed |= mergePrediction(SpecBytecodeDouble); > + } > + } > + break; This code is almost identical to the ArithNegate case below. Let's combine them in some way and perhaps just branch on node->op() where they differ.
Caio Lima
Comment 12 2018-03-09 15:27:01 PST
Created attachment 335475 [details] Patch to test on EWS Testing in EWS. It includes code from https://bugs.webkit.org/show_bug.cgi?id=182470
Caio Lima
Comment 13 2018-04-11 08:44:58 PDT
EWS Watchlist
Comment 14 2018-04-11 10:00:59 PDT
Comment on attachment 337703 [details] Patch Attachment 337703 [details] did not pass jsc-ews (mac): Output: http://webkit-queues.webkit.org/results/7284294 New failing tests: stress/ftl-put-by-id-setter-exception-interesting-live-state.js.dfg-eager-no-cjit-validate
EWS Watchlist
Comment 15 2018-04-11 11:09:32 PDT
Comment on attachment 337703 [details] Patch Attachment 337703 [details] did not pass win-ews (win): Output: http://webkit-queues.webkit.org/results/7284646 New failing tests: http/tests/security/contentSecurityPolicy/userAgentShadowDOM/allow-audio.html
EWS Watchlist
Comment 16 2018-04-11 11:09:43 PDT
Created attachment 337718 [details] Archive of layout-test-results from ews206 for win-future The attached test failures were seen while running run-webkit-tests on the win-ews. Bot: ews206 Port: win-future Platform: CYGWIN_NT-6.1-2.9.0-0.318-5-3-x86_64-64bit
Caio Lima
Comment 17 2018-04-16 19:40:31 PDT
EWS Watchlist
Comment 18 2018-04-16 20:56:01 PDT
Comment on attachment 338072 [details] Patch Attachment 338072 [details] did not pass mac-ews (mac): Output: http://webkit-queues.webkit.org/results/7338762 New failing tests: animations/needs-layout.html
EWS Watchlist
Comment 19 2018-04-16 20:56:02 PDT
Created attachment 338075 [details] Archive of layout-test-results from ews102 for mac-sierra The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews102 Port: mac-sierra Platform: Mac OS X 10.12.6
Caio Lima
Comment 20 2018-04-17 19:33:23 PDT
Ping Review
Caio Lima
Comment 21 2018-04-19 15:40:02 PDT
Ping Review
Caio Lima
Comment 22 2018-04-23 05:51:29 PDT
Created attachment 338579 [details] Patch Patch rebased.
Saam Barati
Comment 23 2018-04-26 15:38:39 PDT
Comment on attachment 338579 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=338579&action=review > Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:740 > + forNode(node).setType(m_graph, SpecBytecodeNumber | SpecBigInt); Is this only used for BigInt? If not, why else would it be used? > Source/JavaScriptCore/runtime/JSBigInt.cpp:255 > + for (int i = 0; i < x->length(); i++) should be unsigned
Caio Lima
Comment 24 2018-04-26 19:03:36 PDT
Comment on attachment 338579 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=338579&action=review Thx for the review >> Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:740 >> + forNode(node).setType(m_graph, SpecBytecodeNumber | SpecBigInt); > > Is this only used for BigInt? If not, why else would it be used? It is also used by Objects with valueOf or toString. >> Source/JavaScriptCore/runtime/JSBigInt.cpp:255 >> + for (int i = 0; i < x->length(); i++) > > should be unsigned Ok
Caio Lima
Comment 25 2018-04-26 19:55:13 PDT
Created attachment 338956 [details] Patch updated Addressing Saam's comments.
Caio Lima
Comment 26 2018-05-01 15:51:52 PDT
Caio Lima
Comment 27 2018-05-01 16:31:59 PDT
EWS Watchlist
Comment 28 2018-05-01 18:56:57 PDT
Comment on attachment 339241 [details] Patch Attachment 339241 [details] did not pass win-ews (win): Output: http://webkit-queues.webkit.org/results/7530964 New failing tests: http/tests/security/video-poster-cross-origin-crash2.html
EWS Watchlist
Comment 29 2018-05-01 18:57:08 PDT
Created attachment 339254 [details] Archive of layout-test-results from ews200 for win-future The attached test failures were seen while running run-webkit-tests on the win-ews. Bot: ews200 Port: win-future Platform: CYGWIN_NT-6.1-2.9.0-0.318-5-3-x86_64-64bit
Caio Lima
Comment 30 2018-05-02 06:12:00 PDT
Ping?
Caio Lima
Comment 31 2018-05-05 08:02:26 PDT
Caio Lima
Comment 32 2018-05-07 08:33:09 PDT
Ping review
Caio Lima
Comment 33 2018-05-10 19:03:47 PDT
Caio Lima
Comment 34 2018-05-13 08:29:43 PDT
EWS Watchlist
Comment 35 2018-05-13 10:14:39 PDT
Comment on attachment 340263 [details] Patch Attachment 340263 [details] did not pass mac-debug-ews (mac): Output: http://webkit-queues.webkit.org/results/7669225 New failing tests: svg/custom/object-sizing-explicit-height.xhtml
EWS Watchlist
Comment 36 2018-05-13 10:14:40 PDT
Created attachment 340265 [details] Archive of layout-test-results from ews117 for mac-sierra The attached test failures were seen while running run-webkit-tests on the mac-debug-ews. Bot: ews117 Port: mac-sierra Platform: Mac OS X 10.12.6
Yusuke Suzuki
Comment 37 2018-05-13 10:24:31 PDT
Comment on attachment 340263 [details] Patch Could you ensure performance regression is not introduced by running benchmarks?
Caio Lima
Comment 38 2018-05-13 10:45:40 PDT
(In reply to Yusuke Suzuki from comment #37) > Comment on attachment 340263 [details] > Patch > > Could you ensure performance regression is not introduced by running > benchmarks? Sure!
Caio Lima
Comment 39 2018-05-13 11:45:24 PDT
Created attachment 340270 [details] Benchmark results Here is the performance results. The patch is perf neutral in my machine.
Yusuke Suzuki
Comment 40 2018-05-14 23:58:00 PDT
Comment on attachment 340263 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=340263&action=review > Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:766 > + forNode(node).setType(m_graph, SpecBytecodeNumber | SpecBigInt); Use setTypeForNode(node, SpecBytecodeNumber | SpecBigInt); > Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:770 > case ArithNegate: { Should not have ArithNegate(Untyped) case. It is incorrect if the input is BigInt. It should be handled by ValueAdd. Let's add RELEASE_ASSERT_NOT_REACHED for "default" clause. > Source/JavaScriptCore/dfg/DFGBackwardsPropagationPhase.cpp:310 > - > + Remove this change > Source/JavaScriptCore/dfg/DFGFixupPhase.cpp:163 > + if (node->child1()->shouldSpeculateInt32OrBoolean() && node->canSpeculateInt32(FixupPass)) { > + node->setOp(ArithNegate); > + fixIntOrBooleanEdge(node->child1()); > + if (bytecodeCanTruncateInteger(node->arithNodeFlags())) > + node->setArithMode(Arith::Unchecked); > + else if (bytecodeCanIgnoreNegativeZero(node->arithNodeFlags())) > + node->setArithMode(Arith::CheckOverflow); > + else > + node->setArithMode(Arith::CheckOverflowAndNegativeZero); > + node->setResult(NodeResultInt32); > + node->clearFlags(NodeMustGenerate); > + break; > + } Nice. > Source/JavaScriptCore/dfg/DFGFixupPhase.cpp:186 > + } And let's fix ArithNegate case too. ArithNegate can produce ArithNegate(Untyped). But it is wrong... ArithNegate(BigInt) would produce BigInt, but ArithNegate node type claims that it always produces numbers. So, we should remove ArithNegate(Untyped) case, and this should be handled ValueNegate(Untyped). This is the same strategy to ArithAdd and ValueAdd. We should fixup edges with some number filters in ArithNegate. If int fixup (Int32, Int52 etc.) is failed in ArithNegate, we should always call fixDoubleOrBooleanEdge(node->child1()) to emit edge filter. This is OK since bytecode parser emits ArithNegate only for operands which result is number. Original ArithNegate(Untyped) thing should be done by ValueNegate. > Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp:258 > else { We should have BigInt speculation type, edge filter, and speculation check here. Let's add FIXME and url. > Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp:4533 > + return; This "return" is unnecessary. > Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp:4536 > void SpeculativeJIT::compileArithNegate(Node* node) Why does ArithNegate have ArithNegate(Untyped)? Can we use ValueNegate for that case? Since ArithNegate's result type should be number, we cannot take BigInt for that. So, current ArithNegate(Untyped) is wrong with BigInt. ArithAdd does not have ArithAdd(Untyped, Untyped). Instead it uses ValueAdd(Untyped, Untyped) for that. Since ArithNegate is emitted in bytecode parser if the operand has NumberResult, and we only convert ValueAdd to ArithAdd with number related edge filtering, we can remove ArithNegate(Untyped) case if we carefully change fixup etc. > Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp:2720 > void compileArithNegate() Ditto. Remove ArithNegate(Untyped) case. And please ensure ArithAdd(Untyped) is not produced. > Source/JavaScriptCore/runtime/JSBigInt.cpp:253 > +JSBigInt* JSBigInt::copy(ExecState* state, JSBigInt* x) Take VM& instead of ExecState*. > Source/JavaScriptCore/runtime/JSBigInt.cpp:264 > +JSBigInt* JSBigInt::unaryMinus(ExecState* state, JSBigInt* x) Take VM& instead of ExecState*. > Source/JavaScriptCore/runtime/JSBigInt.h:81 > + enum ParseIntMode { DisallowEmptyString, AllowEmptyString }; > + enum ParseIntSign { Unsigned, Signed }; Use enum class.
Caio Lima
Comment 41 2018-05-20 14:57:27 PDT
Caio Lima
Comment 42 2018-05-20 14:57:52 PDT
Comment on attachment 340263 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=340263&action=review Thanks for the Review! >> Source/JavaScriptCore/dfg/DFGFixupPhase.cpp:186 >> + } > > And let's fix ArithNegate case too. ArithNegate can produce ArithNegate(Untyped). But it is wrong... ArithNegate(BigInt) would produce BigInt, but ArithNegate node type claims that it always produces numbers. > So, we should remove ArithNegate(Untyped) case, and this should be handled ValueNegate(Untyped). This is the same strategy to ArithAdd and ValueAdd. > We should fixup edges with some number filters in ArithNegate. If int fixup (Int32, Int52 etc.) is failed in ArithNegate, we should always call fixDoubleOrBooleanEdge(node->child1()) to emit edge filter. > This is OK since bytecode parser emits ArithNegate only for operands which result is number. Original ArithNegate(Untyped) thing should be done by ValueNegate. Cool! You are right. >> Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp:4536 >> void SpeculativeJIT::compileArithNegate(Node* node) > > Why does ArithNegate have ArithNegate(Untyped)? Can we use ValueNegate for that case? > Since ArithNegate's result type should be number, we cannot take BigInt for that. So, current ArithNegate(Untyped) is wrong with BigInt. > > ArithAdd does not have ArithAdd(Untyped, Untyped). Instead it uses ValueAdd(Untyped, Untyped) for that. Since ArithNegate is emitted in bytecode parser if the operand has NumberResult, and we only convert ValueAdd to ArithAdd with number related edge filtering, we can remove ArithNegate(Untyped) case if we carefully change fixup etc. Sure. Removing it.
Caio Lima
Comment 43 2018-05-20 18:07:07 PDT
Created attachment 340812 [details] Benchmark Report This is the new result of benchmarks. These changes are perf neutral.
Caio Lima
Comment 44 2018-05-22 18:01:02 PDT
Ping Review
Caio Lima
Comment 45 2018-05-24 20:14:00 PDT
Ping?
Yusuke Suzuki
Comment 46 2018-05-24 21:37:05 PDT
Comment on attachment 340808 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=340808&action=review r=me with comments. > Source/JavaScriptCore/jit/JITOperations.cpp:2720 > + return JSValue::encode(JSValue(JSBigInt::unaryMinus(vm, asBigInt(primValue)))); Do not need `JSValue()` wrap around JSBigInt result. `JSValue::encode(JSBigInt::xxx())` works. > Source/JavaScriptCore/jit/JITOperations.cpp:2740 > + JSValue result = JSValue(JSBigInt::unaryMinus(vm, asBigInt(primValue))); Do not need this `JSValue()` wrap. Just, JSBigInt* result = JSBigInt::xxx(); arithProfile.observeRusult(result); works. > Source/JavaScriptCore/jit/JITOperations.cpp:2785 > + JSValue result = JSValue(JSBigInt::unaryMinus(vm, asBigInt(primValue))); Ditto. > Source/JavaScriptCore/jit/JITOperations.cpp:2817 > + JSValue result = JSValue(JSBigInt::unaryMinus(vm, asBigInt(primValue))); Ditto. > Source/JavaScriptCore/runtime/CommonSlowPaths.cpp:406 > + JSValue result = JSValue(JSBigInt::unaryMinus(exec->vm(), asBigInt(primValue))); Ditto.
Caio Lima
Comment 47 2018-05-25 07:30:03 PDT
Created attachment 341279 [details] Patch For landing Let's see EWS
Dominik Inführ
Comment 48 2018-05-25 08:46:15 PDT
Did you link the wrong bugzilla id in `// https://bugs.webkit.org/show_bug.cgi?id=18247`? It points to "On Mac: showModalDialog doesn't follow Apple's Human Interface Guidelines" right now.
Caio Lima
Comment 49 2018-05-27 18:22:42 PDT
(In reply to Dominik Inführ from comment #48) > Did you link the wrong bugzilla id in `// > https://bugs.webkit.org/show_bug.cgi?id=18247`? It points to "On Mac: > showModalDialog doesn't follow Apple's Human Interface Guidelines" right now. Nice Catch. I'm going to update it.
Caio Lima
Comment 50 2018-05-27 18:46:27 PDT
Created attachment 341440 [details] Patch for landing
WebKit Commit Bot
Comment 51 2018-05-27 20:19:43 PDT
Comment on attachment 341440 [details] Patch for landing Clearing flags on attachment: 341440 Committed r232232: <https://trac.webkit.org/changeset/232232>
WebKit Commit Bot
Comment 52 2018-05-27 20:19:45 PDT
All reviewed patches have been landed. Closing bug.
Radar WebKit Bug Importer
Comment 53 2018-05-27 20:22:05 PDT
Note You need to log in before you can comment on or make changes to this bug.