-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Temporal: Reimplement TemporalDuration::total() according to the spec #50468
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
Temporal: Reimplement TemporalDuration::total() according to the spec #50468
Conversation
|
EWS run on previous version of this PR (hash c4b6238) Details |
c4b6238 to
1eae6b0
Compare
|
EWS run on previous version of this PR (hash 1eae6b0) Details |
1eae6b0 to
67c0a70
Compare
|
EWS run on previous version of this PR (hash 67c0a70) Details |
| StringBuilder result; | ||
| appendInteger(globalObject, result, static_cast<double>(absInt128(quotient))); | ||
| RETURN_IF_EXCEPTION(scope, { }); | ||
| result.append('.'); | ||
| result.append(decimalDigits.toString()); | ||
| // NOTE: if result.toString() == 9007199254740992.999, | ||
| // the result is rounded down to 9007199254740992. | ||
| // This causes the test262 test | ||
| // Temporal/Duration/prototype/total/precision-exact-mathematical-values-7.js | ||
| // to fail when unit=milliseconds, smallerUnit=microseconds, integer=2**53, fraction=1999. | ||
| return sign * result.toString().toDouble(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very inefficient. Why do we need to do this string and re-parsing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code is making up for the lack of float128. The spec calls this out: "The following step cannot be implemented directly using floating-point arithmetic when 𝔽(timeDuration) is not a safe integer."
I followed the polyfill implementation closely, but if you have a better idea, let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently, boa temporal etc. is not doing this inefficient implementation. So, r-.
Translating JS polyfill to C++ is not what we should follow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boa fails the test Temporal/Duration/prototype/total/precision-mathematical-values-6.js. (see https://boajs.dev/conformance?version=main&testPath=built-ins%2FTemporal%2FDuration%2Fprototype%2Ftotal ). There is a note to this effect here ("TODO Fix: Arithemtic on floating point numbers is not safe. According to NOTE 2 in the spec").
On the other hand, tests like this are the uncommon case, so I'll try to think about whether there's a way to optimize the common case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Constellation I took a look at what SpiderMonkey does; their implementation is conformant (at least for the Duration/prototype/total tests). So I adapted that code instead of using the algorithm from the polyfill. Let me know what you think of this approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been told it may not be an option to commit non-BSD-licensed code to WebKit, so this approach might not be feasible. In any event, I'll be on vacation until Sept. 29; will reply to any comments when I return.
| StringBuilder result; | ||
| appendInteger(globalObject, result, static_cast<double>(absInt128(quotient))); | ||
| RETURN_IF_EXCEPTION(scope, { }); | ||
| result.append('.'); | ||
| result.append(decimalDigits.toString()); | ||
| // NOTE: if result.toString() == 9007199254740992.999, | ||
| // the result is rounded down to 9007199254740992. | ||
| // This causes the test262 test | ||
| // Temporal/Duration/prototype/total/precision-exact-mathematical-values-7.js | ||
| // to fail when unit=milliseconds, smallerUnit=microseconds, integer=2**53, fraction=1999. | ||
| return sign * result.toString().toDouble(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently, boa temporal etc. is not doing this inefficient implementation. So, r-.
Translating JS polyfill to C++ is not what we should follow.
|
EWS run on previous version of this PR (hash d0288e7) Details |
|
EWS run on previous version of this PR (hash 19d0e4c) Details |
|
EWS run on previous version of this PR (hash 2ca4f28) Details |
2ca4f28 to
1cc23b2
Compare
|
EWS run on previous version of this PR (hash 1cc23b2) Details |
|
@Constellation I've eliminated the MPLed code and replaced it with an implementation contributed by @ptomato, who reports that this code is twice as fast as the equivalent code in Firefox. Hopefully this addresses the concerns about performance. |
1cc23b2 to
5d2b115
Compare
|
EWS run on current version of this PR (hash 5d2b115) Details |
|
Force-push was to rebase and resolve a conflict in expectations.yaml. |
https://bugs.webkit.org/show_bug.cgi?id=298561 Reviewed by Yusuke Suzuki. This enables some of the tests for Temporal/Duration/prototype/total. This patch was co-authored by Philip Chimento <pchimento@igalia.com>. * JSTests/stress/temporal-duration.js: * JSTests/test262/config.yaml: * JSTests/test262/expectations.yaml: * Source/JavaScriptCore/runtime/TemporalDuration.cpp: (JSC::appendInteger): (JSC::totalTimeDuration): (JSC::TemporalDuration::total const): * Source/JavaScriptCore/runtime/TemporalObject.h: (JSC::lengthInNanoseconds): Canonical link: https://commits.webkit.org/300802@main
5d2b115 to
ae59647
Compare
|
Committed 300802@main (ae59647): https://commits.webkit.org/300802@main Reviewed commits have been landed. Closing PR #50468 and removing active labels. |
🛠 mac-AS-debug
ae59647
5d2b115
🛠 win🧪 win-tests🧪 ios-wk2🧪 ios-wk2-wpt🧪 mac-wk2🧪 mac-AS-debug-wk2🧪 gtk-wk2🧪 mac-intel-wk2🛠 playstation