LOOP type declaration issue
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
Confirmed
|
Medium
|
Unassigned |
Bug Description
Reported by Stas Boukarev on sbcl-devel.
(loop for i from most-negative-
count i))
expands into
(BLOCK NIL
(LET ((I MOST-NEGATIVE-
(DECLARE (TYPE (AND REAL NUMBER) I))
(LET ((#:LOOP-SUM-899 0))
(DECLARE (TYPE FIXNUM #: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.
Changed in sbcl: | |
importance: | Undecided → Medium |
status: | New → Confirmed |
description: | updated |
CLHS says about LOOP COUNT:
"The count construct counts the number of times that the supplied form returns true. The argument var accumulates the number of occurrences; if var is supplied, loop does not return the final count automatically. The var argument is bound as if by the construct with to a zero of the appropriate type. Subsequent values (including any necessary coercions) are computed as if by the function 1+. If into var is used, a type can be supplied for var with the type-spec argument; the consequences are unspecified if a nonnumeric type is supplied. If there is no into variable, the optional type-spec argument applies to the internal variable that is keeping the count. The default type is implementation- dependent; but it must be a supertype of type fixnum."
So FIXNUM appears to be a legal assumption, actually. Suboptimal, but legal.