[ESNext][BigInt] Implement BigInt literals and JSBigInt
authorticaiolima@gmail.com <ticaiolima@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Dec 2017 21:01:57 +0000 (21:01 +0000)
committerticaiolima@gmail.com <ticaiolima@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Dec 2017 21:01:57 +0000 (21:01 +0000)
commitbb1d13176b080530c0417a7afdd80037a42739b2
tree0c891a55a7dd35fa1545c44d7e414de984c39f83
parent53a4cc3b0531671728cad7439baaf2c7ced46bda
[ESNext][BigInt] Implement BigInt literals and JSBigInt
https://bugs.webkit.org/show_bug.cgi?id=179000

Reviewed by Darin Adler and Yusuke Suzuki.

JSTests:

* bigIntTests.yaml: Added.
* stress/big-int-literal-line-terminator.js: Added.
* stress/big-int-literals.js: Added.
* stress/big-int-operations-error.js: Added.
* stress/big-int-type-of.js: Added.
* stress/big-int-white-space-trailing-leading.js: Added.
* stress/big-int-function-apply.js: Added.

Source/JavaScriptCore:

This patch starts the implementation of BigInt primitive on
JavaScriptCore. We are introducing BigInt primitive and
implementing it on JSBigInt as a subclass of JSCell with [[BigIntData]]
field implemented contiguosly on memory as inline storage of JSBigInt to
take advantages on performance due to cache locality. The
implementation allows 64 or 32 bitwise arithmetic operations.
JSBigInt also has m_sign to store the sign of [[BigIntData]] and
m_length that keeps track of BigInt length.
The implementation is following the V8 one. [[BigIntData]] is manipulated
by JSBigInt::setDigit(index, value) and JSBigInt::digit(index) operations.
We also have some operations to support arithmetics over digits.

It is important to notice that on our representation,
JSBigInt::dataStorage()[0] represents the least significant digit and
JSBigInt::dataStorage()[m_length - 1] represents the most siginificant digit.

We are also introducing into this Patch the BigInt literals lexer and
syntax parsing support. The operation Strict Equals on BigInts is also being
implemented to enable tests.
These features are being implemented behind a runtime flage "--useBigInt" and
are disabled by default.

* JavaScriptCore.xcodeproj/project.pbxproj:
* Sources.txt:
* bytecode/CodeBlock.cpp:
* bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::emitEqualityOp):
(JSC::BytecodeGenerator::addBigIntConstant):
* bytecompiler/BytecodeGenerator.h:
(JSC::BytecodeGenerator::BigIntEntryHash::hash):
(JSC::BytecodeGenerator::BigIntEntryHash::equal):
* bytecompiler/NodesCodegen.cpp:
(JSC::BigIntNode::jsValue const):
* dfg/DFGAbstractInterpreterInlines.h:
(JSC::DFG::isToThisAnIdentity):
* interpreter/Interpreter.cpp:
(JSC::sizeOfVarargs):
* llint/LLIntData.cpp:
(JSC::LLInt::Data::performAssertions):
* llint/LowLevelInterpreter.asm:
* parser/ASTBuilder.h:
(JSC::ASTBuilder::createBigInt):
* parser/Lexer.cpp:
(JSC::Lexer<T>::parseBinary):
(JSC::Lexer<T>::parseOctal):
(JSC::Lexer<T>::parseDecimal):
(JSC::Lexer<T>::lex):
(JSC::Lexer<T>::parseHex): Deleted.
* parser/Lexer.h:
* parser/NodeConstructors.h:
(JSC::BigIntNode::BigIntNode):
* parser/Nodes.h:
(JSC::ExpressionNode::isBigInt const):
(JSC::BigIntNode::value):
* parser/Parser.cpp:
(JSC::Parser<LexerType>::parsePrimaryExpression):
* parser/ParserTokens.h:
* parser/ResultType.h:
(JSC::ResultType::definitelyIsBigInt const):
(JSC::ResultType::mightBeBigInt const):
(JSC::ResultType::isNotBigInt const):
(JSC::ResultType::addResultType):
(JSC::ResultType::bigIntType):
(JSC::ResultType::forAdd):
(JSC::ResultType::forLogicalOp):
* parser/SyntaxChecker.h:
(JSC::SyntaxChecker::createBigInt):
* runtime/CommonIdentifiers.h:
* runtime/JSBigInt.cpp: Added.
(JSC::JSBigInt::visitChildren):
(JSC::JSBigInt::JSBigInt):
(JSC::JSBigInt::initialize):
(JSC::JSBigInt::createStructure):
(JSC::JSBigInt::createZero):
(JSC::JSBigInt::allocationSize):
(JSC::JSBigInt::createWithLength):
(JSC::JSBigInt::finishCreation):
(JSC::JSBigInt::toPrimitive const):
(JSC::JSBigInt::singleDigitValueForString):
(JSC::JSBigInt::parseInt):
(JSC::JSBigInt::toString):
(JSC::JSBigInt::isZero):
(JSC::JSBigInt::inplaceMultiplyAdd):
(JSC::JSBigInt::digitAdd):
(JSC::JSBigInt::digitSub):
(JSC::JSBigInt::digitMul):
(JSC::JSBigInt::digitPow):
(JSC::JSBigInt::digitDiv):
(JSC::JSBigInt::internalMultiplyAdd):
(JSC::JSBigInt::equalToBigInt):
(JSC::JSBigInt::absoluteDivSmall):
(JSC::JSBigInt::calculateMaximumCharactersRequired):
(JSC::JSBigInt::toStringGeneric):
(JSC::JSBigInt::rightTrim):
(JSC::JSBigInt::allocateFor):
(JSC::JSBigInt::estimatedSize):
(JSC::JSBigInt::toNumber const):
(JSC::JSBigInt::getPrimitiveNumber const):
* runtime/JSBigInt.h: Added.
(JSC::JSBigInt::setSign):
(JSC::JSBigInt::sign const):
(JSC::JSBigInt::setLength):
(JSC::JSBigInt::length const):
(JSC::JSBigInt::parseInt):
(JSC::JSBigInt::offsetOfData):
(JSC::JSBigInt::dataStorage):
(JSC::JSBigInt::digit):
(JSC::JSBigInt::setDigit):
(JSC::asBigInt):
* runtime/JSCJSValue.cpp:
(JSC::JSValue::synthesizePrototype const):
(JSC::JSValue::toStringSlowCase const):
* runtime/JSCJSValue.h:
* runtime/JSCJSValueInlines.h:
(JSC::JSValue::isBigInt const):
(JSC::JSValue::strictEqualSlowCaseInline):
* runtime/JSCell.cpp:
(JSC::JSCell::put):
(JSC::JSCell::putByIndex):
(JSC::JSCell::toPrimitive const):
(JSC::JSCell::getPrimitiveNumber const):
(JSC::JSCell::toNumber const):
(JSC::JSCell::toObjectSlow const):
* runtime/JSCell.h:
* runtime/JSCellInlines.h:
(JSC::JSCell::isBigInt const):
* runtime/JSType.h:
* runtime/MathCommon.h:
(JSC::clz64):
* runtime/NumberPrototype.cpp:
* runtime/Operations.cpp:
(JSC::jsTypeStringForValue):
(JSC::jsIsObjectTypeOrNull):
* runtime/Options.h:
* runtime/ParseInt.h:
* runtime/SmallStrings.h:
(JSC::SmallStrings::typeString const):
* runtime/StructureInlines.h:
(JSC::prototypeForLookupPrimitiveImpl):
* runtime/TypeofType.cpp:
(WTF::printInternal):
* runtime/TypeofType.h:
* runtime/VM.cpp:
(JSC::VM::VM):
* runtime/VM.h:

Source/WTF:

* wtf/HashFunctions.h:

Tools:

* Scripts/run-jsc-stress-tests:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225799 268f45cc-cd09-0410-ab3c-d52691b4dbfc
55 files changed:
JSTests/ChangeLog
JSTests/bigIntTests.yaml [new file with mode: 0644]
JSTests/stress/big-int-function-apply.js [new file with mode: 0644]
JSTests/stress/big-int-literal-line-terminator.js [new file with mode: 0644]
JSTests/stress/big-int-literals.js [new file with mode: 0644]
JSTests/stress/big-int-operations-error.js [new file with mode: 0644]
JSTests/stress/big-int-type-of.js [new file with mode: 0644]
JSTests/stress/big-int-white-space-trailing-leading.js [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/Sources.txt
Source/JavaScriptCore/bytecode/CodeBlock.cpp
Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h
Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h
Source/JavaScriptCore/interpreter/Interpreter.cpp
Source/JavaScriptCore/llint/LLIntData.cpp
Source/JavaScriptCore/llint/LowLevelInterpreter.asm
Source/JavaScriptCore/parser/ASTBuilder.h
Source/JavaScriptCore/parser/Lexer.cpp
Source/JavaScriptCore/parser/Lexer.h
Source/JavaScriptCore/parser/NodeConstructors.h
Source/JavaScriptCore/parser/Nodes.h
Source/JavaScriptCore/parser/Parser.cpp
Source/JavaScriptCore/parser/ParserTokens.h
Source/JavaScriptCore/parser/ResultType.h
Source/JavaScriptCore/parser/SyntaxChecker.h
Source/JavaScriptCore/runtime/CommonIdentifiers.h
Source/JavaScriptCore/runtime/JSBigInt.cpp [new file with mode: 0644]
Source/JavaScriptCore/runtime/JSBigInt.h [new file with mode: 0644]
Source/JavaScriptCore/runtime/JSCJSValue.cpp
Source/JavaScriptCore/runtime/JSCJSValue.h
Source/JavaScriptCore/runtime/JSCJSValueInlines.h
Source/JavaScriptCore/runtime/JSCell.cpp
Source/JavaScriptCore/runtime/JSCell.h
Source/JavaScriptCore/runtime/JSCellInlines.h
Source/JavaScriptCore/runtime/JSModuleRecord.cpp
Source/JavaScriptCore/runtime/JSType.h
Source/JavaScriptCore/runtime/MathCommon.h
Source/JavaScriptCore/runtime/NumberPrototype.cpp
Source/JavaScriptCore/runtime/Operations.cpp
Source/JavaScriptCore/runtime/Options.h
Source/JavaScriptCore/runtime/ParseInt.h
Source/JavaScriptCore/runtime/SmallStrings.h
Source/JavaScriptCore/runtime/Structure.cpp
Source/JavaScriptCore/runtime/StructureInlines.h
Source/JavaScriptCore/runtime/TypeofType.cpp
Source/JavaScriptCore/runtime/TypeofType.h
Source/JavaScriptCore/runtime/VM.cpp
Source/JavaScriptCore/runtime/VM.h
Source/WTF/ChangeLog
Source/WTF/wtf/HashFunctions.h
Tools/ChangeLog
Tools/Scripts/run-jsc-stress-tests