-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Emit BigInt literals in hexadecimal if shorter (#4165) #4166
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Function<String, String> normalizeBigInt = s -> | ||
s.substring(0, s.length() - 1).toLowerCase() + s.substring(s.length() - 1); |
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.
What's the downside of skipping this normalization in the test cases?
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.
If we skip this normalization, then the tests are enforcing that the compiler outputs the hexadecimal in lowercase, which is not necessarily a part of the compiler spec. In js spec, the hexadecimal encoding can be upper or lowercase including the 'x' character of "0x". (The final 'n' has to be lowercase though)
For simplicity it can be skipped.
As an example, if the compiler has a pass for optimizing brotli-compressed size, it may decide to convert all characters to upper case where applicable. This test would break. This is hypothetical and just to demonstrate the over-specification of the tests if we don't normalize.
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.
My general inclination is to try to keep the testing infrastructure simpler, even if that means we need to update the test cases more frequently. I think this makes it easier to read and understand the tests.
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.
Sounds good, will update the tests shortly
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.
@blickly I updated the tests. Please have another look, thank you!
- Remove the normalization step, which enforces that the BigInt emitter outputs the hexadecimal encoding in lower case.
Thanks for the contribution! |
Emit BigInt literals in hexadecimal format if it leads to shorter code size. This is important for cryptographic libraries, especially in verifiable computation, which have long list of large constants.
The exact threshold after which hexadecimal is shorter is 10^17, however to keep the code simple and extensible, we calculate both the decimal and hexadecimal encodings and compare their sizes.While both
f = (x) => x.toString(16).length + 2
andg = (x) => x.toString().length
are monotone, the difference of two monotone functions is not generally monotone. The above comment is incorrect, though the code is correct as is.