Type error in DEFTRANSFORM *: NIL is not of type NUMBER

Bug #1717971 reported by Paul F. Dietz
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
Medium
Unassigned

Bug Description

This looks similar to 1716061.

(defun ftest5 ()
  (let ((vals '(669124251968))
 (lam '(lambda (b)
        (declare (type (integer 544930329876 12017151562996) b))
        (declare (optimize (debug 1) (safety 0) (space 3) (compilation-speed 0)))
        (catch 'ct5
   (*
    (flet ((%f (&key (x (throw 'ct5 0)))
      (the integer x)))
      (%f))
    b)))))
    (apply (compile nil lam) vals)))

(ftest5) ==>

The value
  NIL
is not of type
  NUMBER
   [Condition of type TYPE-ERROR]

Restarts:
 0: [ABORT] Exit debugger, returning to top level.

Backtrace:
  0: (ABS NIL)
  1: ((SB-C:DEFTRANSFORM *) #<SB-C::COMBINATION :FUN #<SB-C::REF :LEAF #<SB-C::GLOBAL-VAR :%SOURCE-NAME * :TYPE #1=#<SB-KERNEL:FUN-TYPE #> :DEFINED-TYPE #1# :WHERE-FROM :DECLARED :KIND :GLOBAL-FUNCTION {1..
  2: (SB-C::IR1-TRANSFORM #<SB-C::COMBINATION :FUN #<SB-C::REF :LEAF #<SB-C::GLOBAL-VAR :%SOURCE-NAME * :TYPE #1=#<SB-KERNEL:FUN-TYPE #> :DEFINED-TYPE #1# :WHERE-FROM :DECLARED :KIND :GLOBAL-FUNCTION {100..
  3: (SB-C::IR1-OPTIMIZE-COMBINATION #<SB-C::COMBINATION :FUN #<SB-C::REF :LEAF #<SB-C::GLOBAL-VAR :%SOURCE-NAME * :TYPE #1=#<SB-KERNEL:FUN-TYPE #> :DEFINED-TYPE #1# :WHERE-FROM :DECLARED :KIND :GLOBAL-FU..
  4: (SB-C::IR1-OPTIMIZE-BLOCK #<SB-C::CBLOCK 2 :START c2 {1003BBA983}>)

Revision history for this message
Paul F. Dietz (paul-f-dietz) wrote :

The general problem here appears to be that the type of a dead lvar can be determined to be something that is not consistent with its value. In this case, the DEFTRANSFORM requires the type be INTEGER, but the value of the lvar is NIL.

Perhaps DEFTRANSFORM should have a consistency check that the type of the value matches? If it does not, the compiler could determine the expression is dead and stop trying to optimize it.

One can construct other examples where this fails. For example, on the FLOOR function:

(defun ftest6 ()
  (let ((vals '(1))
 (lam '(lambda (b)
        (declare (type (integer 0 1000000000) b))
        (catch 'ct5
   (floor
    b
    (flet ((%f (&key (x (throw 'ct5 0)))
      (the integer x)))
      (%f))
    )))))
    (apply (compile nil lam) vals)))

this leads to the same type error in a DEFTRANSFORM.

Revision history for this message
Stas Boukarev (stassats) wrote :

It's because of casts, the transform gets applied based on the cast type, but the constant value is from principal-lvar-use, and the type conflict hasn't been recognized yet.

Changed in sbcl:
importance: Undecided → Medium
status: New → Triaged
Jan Moringen (scymtym)
Changed in sbcl:
status: Triaged → Fix Committed
Stas Boukarev (stassats)
Changed in sbcl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.