Clozure / ccl

Clozure Common Lisp
http://ccl.clozure.com
Apache License 2.0
850 stars 103 forks source link

Loop fix #430

Closed svspire closed 1 year ago

svspire commented 1 year ago

Fixes #300 (the Matt Kaufmann bug portion of that issue).

Summary: The type-spec that ANSI allows for the loop variable in a for-as-arithmetic subclause should NOT be slavishly checked against the :from, :to, or :by (and related) values because:

I am confident that the developers of the ANSI standard never intended for the type-spec of the loop variable to be blindly applied to the other values in a for-as-arithmetic subclause by the loop macroexpander. This PR fixes that problem.

svspire commented 1 year ago

I wondered if there was some way to to turn the indexv-type type specifier into a ctype and then determine the numeric-ctype-class of it, and write a suitable type specifier based on that. I don't know if that's even a good idea.

There is a way: (ccl::numeric-ctype-class (ccl::specifier-type '(integer 10 20))) ;==> INTEGER That was the first thing I tried and then I realized it was pointless. If the values are constants, the compiler is already smart enough to DTRT with them and I don't think there would be any speed advantage to the compiled code (although it might be possible to make the compiler a tiny bit smarter if :by is a constant fixnum. Haven't looked at the assembler output to see if it's already doing that).

If :by etc are variables, I think it's important to let the programmer declare their types elsewhere if he/she wishes to do so. (That would be where the programmer could explicitly declare a :by variable to be a fixnum, for example.)

Might be worth further investigation to see if there's any advantage to applying the numeric-ctype-class to :by iff it's not already a declared variable with a type, but now we're talking about potentially deep surgery. As you say, this is loop, and in order to just fix MK's bug I was aiming for a minimal footprint (for now).