Comment 0 for bug 365497

Nikodemus Siivola (nikodemus) wrote :

Reported by Stas Boukarev on sbcl-devel.

(loop for i from most-negative-fixnum to most-positive-fixnum
      count i))

expands into

(BLOCK NIL
  (LET ((I MOST-NEGATIVE-FIXNUM))
    (DECLARE (TYPE (AND REAL NUMBER) I))
    (LET ((#:LOOP-SUM-899 0))
      (DECLARE (TYPE FIXNUM #:LOOP-SUM-899))
      (SB-LOOP::LOOP-BODY NIL
                          (NIL NIL
                           (WHEN (> I '536870911) (GO SB-LOOP::END-LOOP)) NIL)
                          ((WHEN I (SETQ #:LOOP-SUM-899 (1+ #:LOOP-SUM-899))))
                          (NIL (SB-LOOP::LOOP-REALLY-DESETQ I (1+ I))
                           (WHEN (> I '536870911) (GO SB-LOOP::END-LOOP)) NIL)
                          ((RETURN-FROM NIL #:LOOP-SUM-899))))))

Where counter has type FIXNUM even though the count becomes a bignum.

Note also the (AND REAL NUMBER) declaration for I: smarter placement of the termination test would allow a FIXNUM declaration there.