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

Editorial: Refactor common alg of since/until into AOs #2167

Merged
merged 13 commits into from
May 6, 2022

Conversation

FrankYFTang
Copy link
Contributor

Most of the operations between until and since are the same except negative value. Refactor to shared AOs between them with a direction which either 1 or -1.

@FrankYFTang
Copy link
Contributor Author

@pdunkel @ptomato @ljharb

@FrankYFTang FrankYFTang changed the title Editoral: Refactor common alg of since/until into AOs Editorial: Refactor common alg of since/until into AOs Apr 29, 2022
spec/instant.html Outdated Show resolved Hide resolved
spec/plaindate.html Outdated Show resolved Hide resolved
spec/plaindatetime.html Outdated Show resolved Hide resolved
spec/plaindatetime.html Outdated Show resolved Hide resolved
spec/plaintime.html Outdated Show resolved Hide resolved
spec/plainyearmonth.html Outdated Show resolved Hide resolved
spec/zoneddatetime.html Outdated Show resolved Hide resolved
spec/zoneddatetime.html Outdated Show resolved Hide resolved
spec/plaindate.html Outdated Show resolved Hide resolved
spec/instant.html Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Apr 29, 2022

Codecov Report

Merging #2167 (885a76e) into main (fbff635) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main    #2167   +/-   ##
=======================================
  Coverage   80.47%   80.47%           
=======================================
  Files          17       17           
  Lines       10886    10886           
  Branches     1468     1468           
=======================================
  Hits         8760     8760           
  Misses       2083     2083           
  Partials       43       43           
Flag Coverage Δ
tests 80.47% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fbff635...885a76e. Read the comment docs.

@FrankYFTang
Copy link
Contributor Author

PTAL

@FrankYFTang FrankYFTang requested a review from ljharb April 29, 2022 21:47
Copy link
Collaborator

@ptomato ptomato left a comment

Choose a reason for hiding this comment

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

Thanks!

As in #2166 I think these will need type="abstract operation" and <dl class="header"> in order for the headers to render correctly. I think you can make the descriptions of these AOs similar to the description that I suggested in #2166.

spec/instant.html Outdated Show resolved Hide resolved
spec/plaindate.html Outdated Show resolved Hide resolved
spec/instant.html Outdated Show resolved Hide resolved
spec/plaindate.html Outdated Show resolved Hide resolved
spec/plaindatetime.html Outdated Show resolved Hide resolved
spec/plainyearmonth.html Outdated Show resolved Hide resolved
spec/plainyearmonth.html Outdated Show resolved Hide resolved
spec/plainyearmonth.html Outdated Show resolved Hide resolved
spec/zoneddatetime.html Outdated Show resolved Hide resolved
spec/zoneddatetime.html Outdated Show resolved Hide resolved
@FrankYFTang FrankYFTang requested a review from justingrant May 3, 2022 00:35
@FrankYFTang
Copy link
Contributor Author

PTAL

@ljharb
Copy link
Member

ljharb commented May 3, 2022

LGTM

Copy link
Collaborator

@ptomato ptomato left a comment

Choose a reason for hiding this comment

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

Thanks!

spec/instant.html Outdated Show resolved Hide resolved
spec/instant.html Outdated Show resolved Hide resolved
spec/instant.html Outdated Show resolved Hide resolved
spec/plaintime.html Outdated Show resolved Hide resolved
FrankYFTang and others added 3 commits May 4, 2022 15:14
Co-authored-by: Philip Chimento <philip.chimento@gmail.com>
Co-authored-by: Philip Chimento <philip.chimento@gmail.com>
Co-authored-by: Philip Chimento <philip.chimento@gmail.com>
@FrankYFTang FrankYFTang requested a review from ptomato May 4, 2022 22:16
@FrankYFTang
Copy link
Contributor Author

PTAL

Copy link
Collaborator

@ptomato ptomato left a comment

Choose a reason for hiding this comment

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

Thanks. Same story here, I spotted a few elements out of place, I'll just accept those suggestions right away and merge the PR in order not to hold it up any longer.

spec/instant.html Outdated Show resolved Hide resolved
spec/plaindate.html Outdated Show resolved Hide resolved
spec/plaintime.html Outdated Show resolved Hide resolved
spec/plainyearmonth.html Outdated Show resolved Hide resolved
Copy link
Collaborator

@justingrant justingrant left a comment

Choose a reason for hiding this comment

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

Found a few issues, otherwise looks great. I'm really pleased with how this PR has turned out. I really like how ~since~ and ~until~... makes it really clear why the sign value is what it is.

Also it looks like some lint errors to resolve?

Thanks Frank for putting in the time to refactor these complex AOs... they're some of the most difficult parts of Temporal and it's good to have them more DRY now.

spec/instant.html Show resolved Hide resolved
</dl>
<emu-alg>
1. Set _other_ to ? ToTemporalInstant(_other_).
1. If _operation_ is ~until~, then,
Copy link
Collaborator

Choose a reason for hiding this comment

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

For consistency, can we use the same logic for until vs. since handling that's used in all other AOs (especially DifferenceTemporalPlainTime whose behavior should be almost identical to this one except for overflow handling) ?

Specifically, removing this swapping of _other_ and _instant_ and then using logic like we use elsewhere. Like this:

1. If _operation_ is ~since~, let _sign_ be -1. Otherwise, let _sign_ be 1.

then...

        1. If _operation_ is ~since~, then
          1. Set _roundingMode_ to ! NegateTemporalRoundingMode(_roundingMode_).

and finally:

1. Let _result_ be ! BalanceDuration(0, 0, 0, 0, 0, 0, `sign` × _roundedNs_, _largestUnit_).

If there's a perf or other reason that this AO should use the swapping logic, then why doesn't DifferenceTemporalPlainTime have the same optimization?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What you are asking is not a refactoring of the current logic, but rather a different math. I am not opposing to do that but I lack of confidence to that kind of change. Just look at the current spec:
https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.since
https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.round

I simply copy the alg there and factor out. What you suggest is way more complicated than that and I do not feel I have the time to ensure such change is correct.

I am also trubled by the "consistency" ideology. "consistency" will need to end somewhere while the two different type are differeent. It is not avoidable some "consistency" will be broken to deal with type specific issue. WHER the "consistency" should end is the question and I feel we push too deep on this. I think "consistency" should be kept on public API level and someone want it to be in the AO function level. But inside alg of AO? I think that simply go too far.

How about we first land this AO with if/swap . And if you or anyone feel comfortable of changing that logic w/o introduce error (which I do not feel confident) than you can do that later in a separate editorial PR.

@FrankYFTang
Copy link
Contributor Author

I understand the desire for consistency. My desire is to reduce redundancy. The current spec text is both inconsistent and redundant. This PR is aim to reduce only the redundancy w/o introduce additional inconsistency but I do not feel compentent to address pre-existing inconsistency and anyone who desire to improve inconsistency please feel free to submt your changes.

@FrankYFTang FrankYFTang requested a review from justingrant May 6, 2022 00:00
@FrankYFTang FrankYFTang requested a review from ptomato May 6, 2022 00:00
Copy link
Collaborator

@justingrant justingrant left a comment

Choose a reason for hiding this comment

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

OK, I can file a follow-up PR for Instant inconsistency.

Copy link
Collaborator

@ptomato ptomato left a comment

Choose a reason for hiding this comment

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

Thanks.

@ptomato ptomato enabled auto-merge (squash) May 6, 2022 16:28
@ptomato ptomato merged commit 85a9f57 into tc39:main May 6, 2022
@FrankYFTang FrankYFTang deleted the shareSinceUntil branch May 11, 2022 03:23
@ptomato ptomato added the spec-text Specification text involved label May 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spec-text Specification text involved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants