Unreachable code notes do not fire sometimes.

Bug #2016417 reported by Charles
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
New
Undecided
Unassigned

Bug Description

Consider

(lambda ()
  (block nil (let () (funcall #'+ (eval 'nil) (eval '1) (return :good)))))

We should expect an unreachable code note here, and also a note that the fourth argument of FUNCALL does not return. This used to work in the past, but now it doesn't.

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

This is because + is source transformed and loses its source location. This has always been the case. At least now
(block nil
  (return)
  (+ 1 2 3))
signals a note by attaching the source location to the starting ctran, but in the (+ 1 2 (return)) case the initial ctran gets executed and there's no good place to attach a source path.

Revision history for this message
Charles (karlosz) wrote :

(lambda ()
  (block nil
    (let ()
      (cons
        (eval 'nil)
        (return
         :good)))))

doesn't work either, and this is a regression since 2018. I identified the change that caused this and I will push soon. The other case cited worked pre-2003 (and CMU CL).

Revision history for this message
Charles (karlosz) wrote :

In CMU CL it even knows about the source transform:
(compile nil '(lambda () (block nil
                           (+ 1 2 (return :good)))))

; In: LAMBDA NIL

; (+ 1 2 (RETURN :GOOD))
; ==>
; (+ (+ 1 2) (RETURN :GOOD))
; Note: The second argument never returns a value.
;

Revision history for this message
Charles (karlosz) wrote :

And, while we're here, CMU CL doesn't need to attach stuff to ctrans to get

(block nil
  (return)
  (+ 1 2 3))

to report the correct source location for the deleted code either, so there must be some existing mechanism in SBCL that can handle this correctly already that it just being hidden.

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

Note: The second argument never returns a value. is not a code deletion note. Obscure the non-returning in something like (when t (return)) and it won't produce any notes.

My version of cmucl, nor sbcl from 2013, don't produce any notes for
(block nil
  (return)
  (+ 1 2 3))

Revision history for this message
Charles (karlosz) wrote :

Hm, interesting. This is what I see:

CMU Common Lisp 2022-05-02 21:52:41 (21D Unicode), running on skybluecherry
With core: /usr/lib/cmucl/lib/lisp-sse2.core
Dumped on: Mon, 2022-05-02 23:52:42+02:00 on arojas
See <http://www.cmucl.org/> for support information.
Loaded subsystems:
    Unicode 1.29 with Unicode version 6.2.0
    Python 1.1, target Intel x86/sse2
    CLOS based on Gerd's PCL 2010/03/19 15:19:03
* (block nil
    (return)
    (+ 1 2 3))

; In: BLOCK NIL

; (+ 1 2 3)
; Note: Deleting unreachable code.
;
NIL

So clearly the machinery is there *somewhere*.

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

That way, yes, but I'm using compile-file. Or compile.

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.