-
Notifications
You must be signed in to change notification settings - Fork 122
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
remove the crc-32
library from dependency
#1565
base: main
Are you sure you want to change the base?
remove the crc-32
library from dependency
#1565
Conversation
@@ -0,0 +1,58 @@ | |||
const TABLE = new Int32Array([ |
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.
Please don't add generated code here.
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.
Why?
- it is faster than creating a table every time;
- it is done by analogy with
crc16
, which has the same table.
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.
Which of the two options sounds more correct? :)
- execute 2048 operations every time compiler starts
- have a table of questionable provenance that is impossible to review, that also takes 65536 operations every time TS checks types, and also increases size of js bundle
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.
So typescript
and type checking is called only once, when building a project. And if you don't calculate the table, you will have to do it every time you start the compiler.
Regarding the “weird” table:
- This table is available in the LLVM project: https://github.com/llvm/llvm-project/blob/6383a12e3b4339fa4743bb97da4d51dea6d2e2ea/llvm/lib/Support/CRC.cpp#L30
- There are many references in Microsoft repository https://github.com/search?q=org%3Amicrosoft%20%220xD9D65ADC%22&type=code
If you look at the code of the js-crc32
library, it doesn't get any better, it doesn't even have comments https://github.com/SheetJS/js-crc32/blob/master/crc32c.js#L85
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.
To make sure the table is correct, you can copy from anywhere else, diff will be zero.
I can also add its generator to the project.
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 realize there are quite a few mentions of this table online, because it's used for something like last half of a century, but I don't think checking numbers by hand is a sound approach to development.
type checking is called only once
There's also tsserver
.
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 original issue started specifically with
Write tests with a contract that uses crc32 function that pass strings with unicode characters.
Until there are tests for unicode characters, or rather any crc32 tests at all, we can't even know that hash is computed the way it did before, and can't do any of these changes.
Imagine worst-case scenario: we have something like |
]); | ||
|
||
export function crc32(data: string | Buffer): number { | ||
if (!(data instanceof Buffer)) { |
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 src/optimizer/interpreter.ts
is the only place we call it from, we never pass Buffer
here.
Buffer
is Node's non-standard API for binary data, while there is platform-agnostic Blob
. When we build browser version of @tact-lang/compiler
, we have to include a polyfill for Buffer
.
While there are other places that use Buffer
, we're working hard to remove them. I'd consider removing Buffer
support here too.
Issue
Closes #1437.
The table was generated in advance, via:
If you need to write tests, I'll add them
Checklist