Skip to content
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

Normative: Add new BigInt primitive #1515

Merged
merged 1 commit into from
Sep 27, 2019
Merged

Normative: Add new BigInt primitive #1515

merged 1 commit into from
Sep 27, 2019

Conversation

caiolima
Copy link
Contributor

@caiolima caiolima commented Apr 23, 2019

This PR is include changes to integrate tc39/proposal-bigint into ECMA262 text. It contains changes on:

  1. Grammar to support BigInt literals.
  2. Abstract Operations to consider this new primitive.
  3. Semantics of arithmetic expressions to support BigInts.
  4. The specification of BigInt objects, including the constructor and BigInt.prototype.
  5. Including BigInt64Array and BigUint64Array as new types of TypedArray.
  6. Changes on DataView operations to support new types.

Proposal author: Daniel Ehrenberg and Brendan Eich

@ljharb ljharb added normative change Affects behavior required to correctly evaluate some ECMAScript source text pending stage 4 This proposal has not yet achieved stage 4, but may otherwise be ready to merge. proposal This is related to a specific proposal, and will be closed/merged when the proposal reaches stage 4. labels Apr 23, 2019
@ljharb ljharb requested a review from littledan April 23, 2019 19:49
spec.html Show resolved Hide resolved
@annevk
Copy link
Member

annevk commented Apr 24, 2019

Should this land after #1135?

@littledan
Copy link
Member

@annevk Yes.

spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Show resolved Hide resolved
@jmdyck
Copy link
Collaborator

jmdyck commented Apr 26, 2019

I've got a bunch of suggested changes. I think it might be best to submit them as a PR against caiolima:big-int.

@littledan
Copy link
Member

@jmdyck That's great to hear. Looking forward to seeing your PR.

@jmdyck
Copy link
Collaborator

jmdyck commented Apr 29, 2019

Done: caiolima#3

Copy link
Member

@littledan littledan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

It'd be great to have reviews from the editors for this PR ahead of the June 2019 TC39 meeting, where Caio and I plan to propose BigInt for Stage 4. cc @ljharb @zenparsing

@caiolima
Copy link
Contributor Author

caiolima commented May 2, 2019

@littledan FYI, there are new changes from caiolima#4.

jmdyck added a commit to jmdyck/ecma262 that referenced this pull request May 28, 2019
Formerly, the procedure for applying ToNumber to the String type
was spread over three widely-separated prose paragraphs
in two different clauses.

This commit brings all that together, expresses it as an actual algorithm,
and gives it the name StringToNumber.

Similarly for the value of a NumericLiteral, here expressed as
the syntax-directed operation NumericValue.

This commit should provide better integration-points for PR tc39#1515 (BigInt).
@ljharb
Copy link
Member

ljharb commented Jul 4, 2019

@caiolima i've merged #1135; can you rebase this?

jmdyck added a commit to jmdyck/ecma262 that referenced this pull request Jul 5, 2019
Formerly, the procedure for applying ToNumber to the String type
was spread over three widely-separated prose paragraphs
in two different clauses.

This commit brings all that together, expresses it as an actual algorithm,
and gives it the name StringToNumber.

Similarly for the value of a NumericLiteral, here expressed as
the syntax-directed operation NumericValue.

This commit should provide better integration-points for PR tc39#1515 (BigInt).
@caiolima
Copy link
Contributor Author

caiolima commented Jul 5, 2019

@caiolima i've merged #1135; can you rebase this?

@ljharb done.

spec.html Show resolved Hide resolved
spec.html Show resolved Hide resolved
<li>If _base_ &lt; 0 and _base_ is finite and _exponent_ is finite and _exponent_ is not an integer, the result is *NaN*.</li>
</ul>
<emu-note>
<p>The result of _base_ `**` _exponent_ when _base_ is *1* or *-1* and _exponent_ is *+Infinity* or *-Infinity* differs from IEEE 754-2008. The first edition of ECMAScript specified a result of *NaN* for this operation, whereas later versions of IEEE 754-2008 specified *1*. The historical ECMAScript behaviour is preserved for compatibility reasons.</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commenting here to note the interaction with #1609

spec.html Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Show resolved Hide resolved
@ljharb ljharb requested a review from a team September 2, 2019 15:05
@littledan
Copy link
Member

Given that you identify the concern as non-blocking, and you haven't made another suggestion, would it make sense to land this PR and be open to other editorial alternatives?

@littledan
Copy link
Member

Thanks for the approval, BTW!

@ljharb
Copy link
Member

ljharb commented Sep 2, 2019

It’ll need approval from the other editor first. My approval means that yes, it will land once it has approval from the full editor group.


<emu-clause id="sec-numeric-types-bigint-subtract">
<h1>BigInt::subtract ( _x_, _y_ )</h1>
<p>The abstract operation BigInt::subtract with two arguments _x_ and _y_ of type BigInt returns the BigInt representing the difference _x_ minus _y_.</p>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<p>The abstract operation BigInt::subtract with two arguments _x_ and _y_ of type BigInt returns the BigInt representing the difference _x_ minus _y_.</p>
<p>The abstract operation BigInt::subtract with two arguments _x_ and _y_ of type BigInt returns the BigInt value that represents the difference _x_ minus _y_.</p>

... for consistency with my last commit. (I missed it because I was only looking for "a BigInt representing".)

spec.html Show resolved Hide resolved
@caiolima
Copy link
Contributor Author

@zenparsing is there anything else we need to do into this PR to get it merged?

@ljharb ljharb self-assigned this Sep 27, 2019
@ljharb ljharb added has stage 4 This PR represents a proposal that has achieved stage 4, and is ready to merge. and removed pending stage 4 This proposal has not yet achieved stage 4, but may otherwise be ready to merge. labels Sep 27, 2019
This PR includes changes over current ECMA262 spec text to include
a new primitive type called `BigInt`. This includes all changes necessary
to integrate this new primitive in the language. It also includes
changes on TypedArray, introducing `BigInt64Array` and `BigUint64Array`

Changes during PR review:
 - Make NumberToBigInt(...) a sub-clause of BigInt(...) and put "Runtime Semantics:" in the header, otherwise it looks too much like a built-in function. (Analogous to Function() and CreateDynamicFunction())
 - Rewrite the characteristics of the BigInt prototype object as a bulleted list.
 - Change 9x "of BigInt type" to "of type BigInt". Also, 1x "of BigInt" to "of type BigInt".
 - In the BigInt:: ops, change a few '0' to '*0n*'.
 - For some BigInt:: ops, change the preamble to a complete sentence
 - Rename "BitwiseOp" as "BigIntBitwiseOp" for symmetry with NumberBitwiseOp. Also, add an 'aoid' attribute to the clause.
 - Replace "ToString Applied to the BigInt Type" with "BigIntToString"
 - Rename 'NumericLiteralBase' to 'NonDecimalIntegerLiteral'. It more clearly expresses what it is, and it fits nicely with 'DecimalIntegerLiteral'.
 - Put 'thisBigIntValue' in a <dfn> element.
 - Mention '_littleEndian_' in preambles for setBigInt64, setBigUint64
 - Tweak pseudocode in Atomics.compareExchange
 - Reference new productions from Annex A.
 - Reproduce changes to 'NumericLiteral' in Annex B.
 - Replace <a> element with <emu-xref>
 - In "Numeric Type Operations" table, split "Value and Purpose" into 3 columns
 - Add ::toString() as a numeric type operation.
 - In BigInt::toString, invoke BigInt::toString directly, rather than via ToString.
 - Changing the grammar for BigInt literals to disallow them for Annex-B non-octal digits (tc39/proposal-bigint#208)
 - Relocate new property-clauses (Specifically, properties of DataView.prototype and the BigInt constructor.)
 - Move some new abstract op clauses.
 - Delete NumberToString: you have Number::toString; ditto BigIntToString and BigInt::toString.
 - In the "Type Conversion" clause, rather than simply putting all the new abstract operations at the end, move them to more logical locations.
 - Change "TypedArrayType" to "ElementType". "TypedArrayType" (and "TypedArray type") suggests one of the TypedArray types, where we're really talking about one of the TypedArray *element* types.
 - Add 'oldids' attributes
 - Reference DecimalBigIntegerLiteral from Annex A
 - Use NonDecimalIntegerLiteral in StrNumericLiteral

Co-authored-by: Caio Lima <[email protected]>
Co-authored-by: Michael Dyck <[email protected]>
Co-authored-by: Michael[tm] Smith <[email protected]>
@ljharb ljharb merged commit fd3a260 into tc39:master Sep 27, 2019
@caiolima
Copy link
Contributor Author

@ljharb and @zenparsing Thanks a lot for the review! @jmdyck and @littledan thx a lot for the fixes and reviews as well.

ljharb pushed a commit to jmdyck/ecma262 that referenced this pull request Sep 28, 2019
 - Let -> Set
 - Eliminate otherwise-assertions (per tc39#1559)
 - Change '?' to '!', because ::subtract can't return an abrupt completion.
 - Fix bug: '_v_' should be '_value_'

 - Fix bug: `_arrayTypeName_` not defined
... in Atomics.{store,wait,notify}.

(In Atomics.store, it does get defined in step 5, but needs to be defined
before the reference in step 3.)

(In Atomics.wait, the undefined reference is in step 11,
but by defining it earlier, it can also be used in the current step 3.)

(In Atomics.notify, the undefined reference is in step 7.)
ljharb pushed a commit to jmdyck/ecma262 that referenced this pull request Sep 28, 2019
 - Update preamble for SetValueInBuffer and GetModifySetValueInBuffer; the `_value_` parameter can be a BigInt now.
 - tweak some BigInt-related element-ids
ljharb pushed a commit to caiolima/ecma262 that referenced this pull request Sep 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has stage 4 This PR represents a proposal that has achieved stage 4, and is ready to merge. has test262 tests normative change Affects behavior required to correctly evaluate some ECMAScript source text proposal This is related to a specific proposal, and will be closed/merged when the proposal reaches stage 4.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants