[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

ISO help understanding compiler message

Jim Newton

10/19/2015 11:41:00 AM

[BTW, ISO=in search of, not international standard organization]

Can someone help me understand what the issue is with my program?
I also posted on the sbcl developers list, but was hoping someone
on comp.lang.lisp might be able to suggest something as well.

I get an SBCL compiler note that unreadable code is being deleted.

-+ note (2)
|-- deleting unreachable code
`-- deleting unreachable code

The offending line is a call to SET-EXCLUSIVE-OR, which is being used as a test in a COND.

The the text of the function is pretty large, but here is what I think is the interesting part.

(let ((current-states (ndfa:get-initial-states ndfa)))
(loop :while t
:do (let* ((next-char (read-next-char))
(next-states (perform-some-transitions ndfa current-states (list next-char))))
(cond
((null next-states)
(error "states exhausted unexpectedly"))
((find-if #'state-final-p next-states)
(consume (best-label current-states))
(return-from parse-file-content nil))
((set-exclusive-or next-states current-states) ;; <<-- CURIOUS COMPILER NOTE
(consume (best-label current-states)))
(t ; state did not change, keep reading
nil))
(setf buf (tconc buf next-char))
(setf current-states next-states))))))))


I'll attach the file being compiled, zipf.lisp, in case anyone wants to try to reproduce it.
You'll also need another file, ndfa.lisp which is required by the DEFPACKAGE.

The note is associated with line 128 of file zipf.lisp.

Thanks in advance for advise anyone can give me.
5 Answers

Jim Newton

10/19/2015 11:43:00 AM

0

If anyone is interesting in seeing the entire source. You are welcome and invited.

ndfa.lisp = https://www.dropbox.com/s/j7du3eh6f15amd2/ndfa...
zipf.lisp = https://www.dropbox.com/s/pmmewv70549mlwv/zipf...

Didier Verna

10/19/2015 12:37:00 PM

0

Jim Newton wrote:

> Can someone help me understand what the issue is with my program? I
> also posted on the sbcl developers list, but was hoping someone on
> comp.lang.lisp might be able to suggest something as well.

I don't get the note here. I have encountered cases where I got
similar notes due to the expansion of macros like LOOP, but in parts
not directly related to the code I wrote though. It may be misleading
at times.

--
My new Jazz CD entitled "Roots and Leaves" is out!
Check it out: http://didierverna.com/records/roots-and-...

Lisp, Jazz, Aïkido: http://www.didier...

Jim Newton

10/19/2015 3:50:00 PM

0

I've tried to reduce the function to a nonsense function which exhibits the same behaviour.

(defun dead-test ( client)
"read the content of a stream, parsing into words. Call the given CLIENT function on each word."
(declare (type (function (t t) t) client)
(optimize (debug 0) (speed 3)))
(let (buf)
(labels ((read-next-int ()
(random 12))

(perform-some-transitions (states inputs)
(dolist (input inputs)
(cond
((zerop (random 3))
(pop states))
((zerop (random 3))
(incf (car states) input))
(t
(setf states (sort states #'lessp)))))
states))

(let ((current-states '(1 2 3)))
(loop :while t
:do (let* ((next-int (read-next-int))
(next-states (perform-some-transitions current-states (list next-int))))
(when (set-exclusive-or next-states current-states) ;; CURIOUS COMPILER NOTE
(push next-int buf))
(setf current-states next-states)))))))

Carlos

10/19/2015 5:10:00 PM

0

[Jim Newton <jimka.issy@gmail.com>, 2015-10-19 08:50]
> I've tried to reduce the function to a nonsense function which
> exhibits the same behaviour.

Maybe because you end up discarding `buf', the compiler doesn't bother
with pushing into it (and related tests).


> (defun dead-test ( client)
> "read the content of a stream, parsing into words. Call the given
> CLIENT function on each word." (declare (type (function (t t) t)
> client) (optimize (debug 0) (speed 3)))
> (let (buf)
> (labels ((read-next-int ()
> (random 12))
>
> (perform-some-transitions (states inputs)
> (dolist (input inputs)
> (cond
> ((zerop (random 3))
> (pop states))
> ((zerop (random 3))
> (incf (car states) input))
> (t
> (setf states (sort states #'lessp)))))
> states))
>
> (let ((current-states '(1 2 3)))
> (loop :while t
> :do (let* ((next-int (read-next-int))
> (next-states (perform-some-transitions
> current-states (list next-int)))) (when (set-exclusive-or next-states
> current-states) ;; CURIOUS COMPILER NOTE (push next-int buf))
> (setf current-states next-states)))))))

--

Jim Newton

10/20/2015 7:13:00 AM

0

Hi Carlos, that's a good suggestion. But even if I modify the function to return but at the end, it still "complains" about the set-exclusive-or call.

Is there a way to ask SBCL, which dead code did you remove?