cisco / ChezScheme

Chez Scheme
Apache License 2.0
6.97k stars 984 forks source link

Add add1, sub1 and abs to cptypes #790

Closed gus-massa closed 8 months ago

gus-massa commented 9 months ago

Add special cases for add1, sub1 and abs to cptypes. In particular, that they are closed for flonums, reals and exact-integers.

jltaylor-us commented 9 months ago

needs more mats to cover all of the clauses in the new specializations

gus-massa commented 9 months ago

I added more tests.

jltaylor-us commented 8 months ago

Still doesn't test the bignum case for abs, but looks ok to me. I don't think I've actually done any work in cptypes before, though, so maybe one of the other maintainers will give it a quick glance before it goes in.

mflatt commented 8 months ago

The changes in cptypes.ss look good to me. I agree that it would be good to cover the bignum case of abs with a test (which is the one where I had to pause to believe that it's right).

gus-massa commented 8 months ago

I don't care too much about bignums because they don't trigger too many optimizations. I care more about fixnums.

A long time ago, I added bignums so (and (integer? x) (exact? x)) is equivalent to (or (fixnum? x) (bignum? x)). This is a reduction in cpnanopass that is not visible by cptypes, but the reduction may be moved to an early pass in the future, or the expression may be in the code written by the programmer.

Now, I added the test for bignums in abs and also negative tests in the others. I also added the negative tests for fixnums. They are sanity checks, because it's too easy to be confused and add a wrong rule for fixnums in the future to cptypes.