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

Editor review: type confusion around number types #1413

Closed
8 tasks done
syg opened this issue Mar 4, 2021 · 17 comments · Fixed by #2455
Closed
8 tasks done

Editor review: type confusion around number types #1413

syg opened this issue Mar 4, 2021 · 17 comments · Fixed by #2455
Assignees
Labels
spec-text Specification text involved tc39-review
Milestone

Comments

@syg
Copy link

syg commented Mar 4, 2021

Since the arithmetic fix in ecma262, the editorial convention is that:

  • All arithmetic and comparisons are done on the Mathematical Values.
  • Internal fields should store MVs.
  • When MVs need to be passed back to user code, they are converted to Number values.
  • MVs no longer have any subscripts (no subscript ℝ), while Number values have a subscript 𝔽.

For more details see 5.2.5.

This spec draft has type confusion for operating on numbers in several places. I haven't read through everything to make an exhaustive list. Some places I noticed:


@ptomato ptomato added tc39-review spec-text Specification text involved labels Mar 4, 2021
@ptomato ptomato added this to the Next milestone Mar 4, 2021
@ptomato
Copy link
Collaborator

ptomato commented Mar 4, 2021

Thanks, I was afraid there might be a few places where this is still wrong.

@ptomato ptomato modified the milestones: Next, Stage 3 Conditional Mar 19, 2021
ptomato added a commit that referenced this issue Apr 29, 2021
This is to be done comprehensively in #1413, but may as well fix these
cases that were identified in review.
ptomato added a commit that referenced this issue Apr 30, 2021
This is to be done comprehensively in #1413, but may as well fix these
cases that were identified in review.
(Comma separators are currently not used in the spec text, so prefer
scientific notation if the numbers are large.)
@ptomato
Copy link
Collaborator

ptomato commented Apr 30, 2021

Should note that while doing this issue, comma thousands separators are currently not used in the spec text.

@ptomato ptomato modified the milestones: Stage 3 Conditional, Next May 12, 2021
ptomato added a commit that referenced this issue May 21, 2021
This is to be done comprehensively in #1413, but may as well fix these
cases that were identified in review.
(Comma separators are currently not used in the spec text, so prefer
scientific notation if the numbers are large.)
ptomato added a commit that referenced this issue May 21, 2021
This is to be done comprehensively in #1413, but may as well fix these
cases that were identified in review.
(Comma separators are currently not used in the spec text, so prefer
scientific notation if the numbers are large.)
ptomato added a commit that referenced this issue May 31, 2021
This is to be done comprehensively in #1413, but may as well fix these
cases that were identified in review.
(Comma separators are currently not used in the spec text, so prefer
scientific notation if the numbers are large.)
ptomato added a commit that referenced this issue May 31, 2021
This is to be done comprehensively in #1413, but may as well fix these
cases that were identified in review.
(Comma separators are currently not used in the spec text, so prefer
scientific notation if the numbers are large.)
Ms2ger pushed a commit that referenced this issue Jun 1, 2021
This is to be done comprehensively in #1413, but may as well fix these
cases that were identified in review.
(Comma separators are currently not used in the spec text, so prefer
scientific notation if the numbers are large.)
Ms2ger pushed a commit that referenced this issue Jun 1, 2021
This is to be done comprehensively in #1413, but may as well fix these
cases that were identified in review.
(Comma separators are currently not used in the spec text, so prefer
scientific notation if the numbers are large.)
@ptomato
Copy link
Collaborator

ptomato commented Jun 8, 2021

Note, make sure that all operations make clear what the number types of the inputs are, by assertions.

@ptomato ptomato self-assigned this Jun 8, 2021
ptomato added a commit that referenced this issue Jun 12, 2021
These are not currently used in Ecma-262. Use scientific notation in these
simple power-of-10 cases.

See: #1413
ptomato added a commit that referenced this issue Jun 12, 2021
ptomato added a commit that referenced this issue Jun 12, 2021
…umbers

As per #1413, internal fields should store mathematical values. Previously
the internal slots of Temporal.Duration were described as integer Number
values.

Changing this also requires changing the return value of
GetOffsetNanosecondsFor to an integer, because arithmetic is done on
offset nanoseconds with Duration fields.

Adds test262 tests covering the validation steps done at the end of
GetOffsetNanosecondsFor, for all entry points that observably call
Temporal.TimeZone.getOffsetNanosecondsFor().

See: #1413
ptomato added a commit that referenced this issue Jun 14, 2021
These are not currently used in Ecma-262. Use scientific notation in these
simple power-of-10 cases.

See: #1413
ptomato added a commit that referenced this issue Jun 14, 2021
@ptomato
Copy link
Collaborator

ptomato commented Jun 14, 2021

  • Internal fields should store MVs.

This won't be a problem for most of Temporal, but @anba raised in #1534 (comment) that this requirement is a problem for Temporal.Duration's internal slots, because they are unbounded. This could make any future additional properties on Temporal.Duration unpolyfillable. @syg do you have any opinion on this?

@syg
Copy link
Author

syg commented Jun 15, 2021

I don't quite understand the concern @anba raised. Why can't the polyfills use BigInts and convert them to Numbers at the boundary?

@ptomato
Copy link
Collaborator

ptomato commented Jun 15, 2021

If I'm understanding @anba correctly, suppose a new method was added to Duration in the future, which used the bigint values from the internal slots in its calculations. A polyfill wouldn't be able to correctly do this.

@ljharb
Copy link
Member

ljharb commented Jun 15, 2021

Why wouldn't it? The polyfill would still store the bigint value internally, and its version of the new method would have access to those, no?

(Separately, if the values are being stored as bigints/mathematical integers internally, why are they exposed as Numbers in the API?)

@Ms2ger
Copy link
Collaborator

Ms2ger commented Jun 15, 2021

Why wouldn't it? The polyfill would still store the bigint value internally, and its version of the new method would have access to those, no?

Depends on whether the polyfill would replace the entire API or just add the new function, presumably.

@ljharb
Copy link
Member

ljharb commented Jun 15, 2021

That’s a fair point; it would likely force a new method being polyfilled to also polyfill all of that Temporal type.

@anba
Copy link
Contributor

anba commented Jun 15, 2021

Yes, I was concerned about the case when a possible Temporal v2 extends Temporal.Duration and a polyfill wants to implement these new methods by extending the (browser) built-in Temporal.Duration object. It seems unlikely that a polyfill will want to replace the whole built-in Temporal.Duration object for that case. (And to be properly spec-compliant, the polyfill will actually need to replace everything from Temporal, because other Temporal objects are also creating Temporal.Duration objects.)

@anba
Copy link
Contributor

anba commented Jun 15, 2021

The patch from #1534 was only redefining that the internal slots are now stored as mathematical values instead of Number values. It didn't update any existing call sites to use resp. 𝔽 to convert to/from mathematical values. I don't have any issues when the spec defines that the internal slots are storing mathematical values as long as all callers are updated to use 𝔽 when reading these slots.

@syg
Copy link
Author

syg commented Jun 15, 2021

Thanks for the explanation. The "do math on MVs, convert to Numbers at the boundary" is pretty pervasive in the spec. I don't feel like partial polyfilling is a use case that we ought to go out of our way to enable, especially for Temporal, one of whose main value adds is that we can start shipping this and the related data in browsers to cut down on payload size. So I'd rather not do anything different here, which could result in subtle arithmetic bugs and gotchas down the road.

@ptomato
Copy link
Collaborator

ptomato commented Jun 15, 2021

Understood on the editorial preference. @Ms2ger and I will investigate whether this change is possible without a normative change to the approved spec text. In #1534 @anba suggests that it is not.

ptomato added a commit that referenced this issue Jun 15, 2021
These are not currently used in Ecma-262. Use scientific notation in these
simple power-of-10 cases.

See: #1413
ptomato added a commit that referenced this issue Jun 15, 2021
@Ms2ger
Copy link
Collaborator

Ms2ger commented Jun 16, 2021

I think I agree that we should do all internal maths on MVs. My apologies for not realizing earlier that this would be a normative change in the Duration case. Any changes to the other classes should be purely editorial, thanks to the existing range checks, so we should be able to continue with those pending a plenary decision.

@ptomato
Copy link
Collaborator

ptomato commented Jul 1, 2021

I'd like to split off #1604 for the normative change to Duration, so that Ms2ger can close this when all of the other editorial issues are resolved.

ptomato added a commit that referenced this issue Mar 8, 2022
GetOption with Number type returns a Number value, so the fallback value
should also be a Number value, and the result should be compared with
Number values in the following step.

Add a structured header, to make the types clear.

See: #1413
Ms2ger pushed a commit that referenced this issue Mar 8, 2022
GetOption with Number type returns a Number value, so the fallback value
should also be a Number value, and the result should be compared with
Number values in the following step.

Add a structured header, to make the types clear.

See: #1413
@ptomato ptomato modified the milestones: Next, Stage "3.5" Dec 8, 2022
@ptomato
Copy link
Collaborator

ptomato commented Dec 8, 2022

Verify things on checklist.

ptomato added a commit that referenced this issue Jan 4, 2023
…aders

There were a few remaining abstract operations that operate on numeric
types, that didn't have those types spelled out either via structured
headers or via assertions.

This converts those operations to use structured headers. That also allows
ecmarkup to point out places where a ! notation was used superfluously.

This revealed that the return type of RoundTemporalInstant wasn't correct:
it should have been a BigInt, since it returns a number of epoch
nanoseconds.

Closes: #1413
@ptomato
Copy link
Collaborator

ptomato commented Jan 4, 2023

  • Handling of infinities in ToTemporalRoundingIncrement: these are now handled.
  • PreparePartialTemporalFields passes MVs to CreateDataPropertyOrThrow (sometimes): PreparePartialTemporalFields was folded into PrepareTemporalFields and the cases where a MV was passed to CreateDataPropertyOrThrow are fixed.
  • Comma thousands separators: The only place where these remain is in prose, which is consistent with the prose in ECMA-262.
  • Numeric type assertions: There were still a few AOs operating on numeric types that didn't have these type assertions, either explicitly or via structured headers, and one (RoundTemporalInstant) should've been returning a BigInt. This is fixed in Editorial: Convert operations with numeric arguments to structured headers #2455.

Ms2ger pushed a commit that referenced this issue Jan 10, 2023
…aders

There were a few remaining abstract operations that operate on numeric
types, that didn't have those types spelled out either via structured
headers or via assertions.

This converts those operations to use structured headers. That also allows
ecmarkup to point out places where a ! notation was used superfluously.

This revealed that the return type of RoundTemporalInstant wasn't correct:
it should have been a BigInt, since it returns a number of epoch
nanoseconds.

Closes: #1413
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spec-text Specification text involved tc39-review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants