Open hemml opened 2 years ago
I cannot answer the code-generation question, but according to MDN, Math.sqrt
can return NaN
sometimes:
Return value
The square root of the given number. If the number is negative, NaN is returned.
There is no way to disable the checks right now. It could be nice to add support for (declare (optimize speed))
to disable those.
The compiler is rather naive and the type checks are everywhere. It also makes the output huge, because those are inlined. It'd be nice to wrap those type checks in JS functions in prelude, so (+ x y)
would compile to just a function call with the typecheck in a single place.
Of course, it would be even better to do some basic analysis in the compiler and remove some unnecessary checks. I started a few attempts to add a smarter compiler, but never got enough time to finish it. But if anyone has time and some will, it is doable.
cannot answer the code-generation question, but according to MDN,
Math.sqrt
can returnNaN
sometimes:
Sure, but typeof NaN
returns "number"
anyway :)
There is no way to disable the checks right now. It could be nice to add support for (declare (optimize speed)) to disable those.
Maybe go this way:
check-type
, typecase
, and assert
. If the user doesnt not check the type, it is done by JS and throws an exception. Compiler messages do less help localize the source of errors.Maybe it's easier than compiler redesign? Mmm?
I think the default should be to check the types always.
But we can disable them kind of easily with a declaration without improving the compiler.
Indeed if the user chooses safety 0
, then they could add check-type
.
I think the default should be to check the types always.
Definitely so. by default, type checking is always enabled.
Introduce the pragma
disable-check-type directive.
l cl-user> (pragma :disable-check-type t)
(pragma :disable-check-type t)
(let ()))
As an option.
safety 0
it should disable all checks: arrays, indices, strings, lists.
I'm trying to perform some computations on the browser-side, which is rather slow sometimes. I see in the JSCL-generated code a lot of type checking like this:
It seems strange, because Math.sqrt can return numbers only and, anyway, that checks are slowdowns the code. Is there a way to disable type checking in generated code?