sheikh_anton
sheikh_anton

Reputation: 3452

Difference between signal and error for compiler (sbcl 1.2.4)

I got strange error from SBCL compiler, so may be someone can explain to me what is going on there. For information the package uses optima and drakma. I really tried to minify posted code, but this amount required to understand the problem.

(defun signal-vk-error (code)
  (error ;; <--- HERE IS THING
    (case code
      (100 'parse-error)
      (otherwise 'error))))

(defmacro match-with-error (response matcher)
  `(match ,response
         ((alist (:ERROR . code))
          (signal-vk-error code))
         ,matcher))

(defun api-call-response (resp)
  (match-with-error
    resp
    ((alist (:RESPONSE . data)) data)))

Compiling this file I got:

; caught ERROR:
;   don't know how to dump CODE (default MAKE-LOAD-FORM method called).
Unhandled TYPE-ERROR in thread #<SB-THREAD:THREAD "main thread" RUNNING
                                  {1002BF6F03}>:
  The value NIL is not of type (AND ATOM (NOT NULL)).

So there it looks like sbcl (1.2.4) can't create binary representation, but I can't underestand why.

If I just change ERROR to SIGNAL in signal-vk-error - everyhing compiles, loads and works as expected. I can also just load file in slime and eval is, it will work without errors and warnings.

So, the question is, what is wrong with error? What is major difference between error and signal?

UPDATE 1: Interesting observation, if I remove signal-vk-error function, and just put this code inside macro defenition it will compile ok.

UPDATE 2: Thanks to @RainerJoswig, declaring signal-vk-error not to be inlined fixes the problem. Reported to SBCL team, looks like they doing some optimization, which brokes compilation in this case.

Upvotes: 1

Views: 105

Answers (2)

sheikh_anton
sheikh_anton

Reputation: 3452

As it came out, there is a problem in compiler, in fact two of them, one of which is allegedly a feature. Anyone interested can read the conversation between one of SBCL hackers and the author of optima in bugtracker.

For now this fixed in optima side by not revealing pattern object during macroexpasion, commit d7ec93d0df4920b9a7b4a492e7aadf52480f437c

Upvotes: 0

Rainer Joswig
Rainer Joswig

Reputation: 139241

Smallest way to reproduce the problem:

(defun signal-vk-error ()
  (error 'error))

(defun api-call-response ()
  (optima:match 1
    ((not 2)
     (signal-vk-error))))

If I macroexpand or walk the match form, the problem disappears.

The following also makes the problem to disappear.

(declaim (notinline error))

Upvotes: 1

Related Questions