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. |
cristianoc
left a comment
There was a problem hiding this comment.
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
| } | ||
| var a_type = typeof a; | ||
| var b_type = typeof b; | ||
| var exit = 0; |
There was a problem hiding this comment.
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.
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.
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.
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.
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. |
cristianoc
left a comment
There was a problem hiding this comment.
You removed .ml but forgot to remove .mli
cristianoc
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
cristianoc
left a comment
There was a problem hiding this comment.
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.bigIntwithbigInteven though in JavaScript you can comparebigIntwithfloat.comparethere is a clause aboutif b == Obj.repr Js.null || Caml_option.isNested b. I didn't understand this. Just addedbigIntas another condition.equaldid not understand the part aboutb_type = "number" || b_type = "bigint" || b_type = "undefined". Confused about why this isn't parallel to the checks ona_typethat includestringandboolean.Objmodule 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.