-
Notifications
You must be signed in to change notification settings - Fork 464
bigInt comparision #6097
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
bigInt comparision #6097
Conversation
This is a good opportunity to convert to .res syntax. Sorry that wasted some time. Then the 2 functions that show up in the output, we don't want them. If you make them private they won't. |
Once they're converted to ReScript this is less confusing. This is just a ReScript file, and we really only care about the generated JS, which goes into a library shipped with the compiler. So their idea is: whatever gives the desired JS is good. |
In general, we want to limit the number of tests in the compiler. For test running speed and maintenance reasons. |
If such a condition is not already there for number and string, then it's very unlikely that it will be needed for bigint. |
For the main file I converted to ReScript and did the same with the |
The test file could be res too. But it looks weird. This doesn't look like a LIST or an ARRAY. Not sure what it is supposed to be.
Left this as-is after automatic conversion. Tests seem to run. |
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.
Left some small comments.
Not sure why the code generated by compare has changed so much, let me take a look and get back.
lib/es6/caml_obj.js
Outdated
@@ -42,11 +42,20 @@ function compare(a, b) { | |||
} | |||
var a_type = typeof a; | |||
var b_type = typeof b; | |||
var exit = 0; |
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.
There are all these exit
now. Let me take a look at the changes in the source and see what might have caused this.
lib/es6/caml_obj.js
Outdated
function notequal(a, b) { | ||
if (typeof a === "number" && typeof b === "number") { | ||
if (canNumericCompare(a, b)) { |
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.
It's better inlined.
I suspect this will be inlined again once canNumericCompare is made a private function.
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'm not sure it is re-building. I changed it to == number or == string or == bigint but the javascript is the same. What command to build with rescript? make lib
not doing it. I have the reScript extension on my computer and installed Rescript into package.json.
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.
Need to go to sleep. Do you think I need tests related to comparing bigInt and float? In JavaScript you can type bigInt < 3.0 but I think ReScript prevents this unless you do an unsafe cast. Will look at this in the morning.
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 can take it from here. Thanks for this!
I think it's OK. That's a custom infix operator. It's going to be defined somewhere. |
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.
You removed .ml but forgot to remove .mli
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.
OK found what was causing the code to change that much.
After this, it should be pretty much ready to merge.
Thanks for doing this!!!
jscomp/runtime/caml_obj.res
Outdated
| ("bigint", "bigint") | ||
| ("number", "number") => | ||
Pervasives.compare((Obj.magic(a): float), (Obj.magic(b): float)) | ||
| ("bigint", _) | ("number", _) => |
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.
Can you remove this change?
The type system does not let us compare bigint and int.
The only reason to care about this is this change complicates the generated code.
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.
Sorry not totally understanding. Do you want me to take out the bigint
on this line? The check above I think is essential.
| ("bigint", "bigint")
| ("number", "number") =>
Pervasives.compare((Obj.magic(a): float), (Obj.magic(b): float))
>>> | ("bigint", _) | ("number", _) =>
if b === Obj.repr(Js.null) || Caml_option.isNested(b) {
1
} else {
/* Some (Some ..) < x */
jscomp/runtime/caml_obj.res
Outdated
/* Some (Some ..) < x */ | ||
-1 | ||
} /* Integer < Block in OCaml runtime GPR #1195, except Some.. */ | ||
| (_, "bigint") | (_, "number") => |
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 too
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.
And this line switch back to just "number"?
-1
} /* Integer < Block in OCaml runtime GPR #1195, except Some.. */
>>>> | (_, "bigint") | (_, "number") =>
if a === Obj.repr(Js.null) || Caml_option.isNested(a) {
-1
I think if one follows the instructions in the contributing doc these issue should not arise. |
It's done automatically every time you do |
The lib is built in a custom way because of... historical reasons and complications left in there.
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.
Should be OK now.
I'll merge a little later.
Sorry not working for me. After I mangle the isNumberOrBigInt function it still just checks for "number" or "bigint". Have tried make lib and make test. I'm going to bed. You can take it from here if you want. Or I'll try in the morning. |
Support bigInt comparison. Fix for #6096
Some comments and questions:
<>
or=
.dune build
. Compiler version mismatch: this project seems to be compiled with version 4.06 of the OCaml compiler, but the running ocamllsp supports OCaml version 4.14. OCaml language support will not work properly until this problem is fixed. And I couldn't figure out how to fix this. and so had lots of red squiggly errors though things seemed to compile and tests pass.bigInt
withbigInt
even though in JavaScript you can comparebigInt
withfloat
.compare
there is a clause aboutif b == Obj.repr Js.null || Caml_option.isNested b
. I didn't understand this. Just addedbigInt
as another condition.equal
did not understand the part aboutb_type = "number" || b_type = "bigint" || b_type = "undefined"
. Confused about why this isn't parallel to the checks ona_type
that includestring
andboolean
.Obj
module directly likelessthan
- just could get tocompare
(global namespace somehow) and the operators. But my tests look similar to the other compare tests, so probably ok."number"
in the code. So maybe other places need work to support BigInt? It was too much for me to get my head around.