named-lambda clobbers type derivation

Bug #1289779 reported by James M. Lawrence on 2014-03-08
This bug affects 2 people
Affects Status Importance Assigned to Milestone

Bug Description

(defun foo ()

(when nil
  (defun foo ()

(defun foo2 ()
  (let ((x (foo)))

When the above is compiled,

(foo2) ;=> error: The value 99 is not of type (MEMBER :BAR).


Confirmed on latest and various versions I tried
back to 1.0.50.

Linux xii 3.2.0-24-generic-pae #39-Ubuntu SMP Mon May 21 18:54:21 UTC
2012 i686 i686 i386 GNU/Linux


description: updated
Stas Boukarev (stassats) wrote :

The consequences are actually undefined if you modify the function which is called by another function in the same file, but that typecheck is bogus.

Changed in sbcl:
status: New → Invalid
Stas Boukarev (stassats) wrote :

You need to declaim it notinline if you wish to redefine it.

Stas Boukarev (stassats) wrote :

And such behaviour should probably only happen when there are benefits, like (defun foo2 () (1+ (foo))), where it can get optimized, passing stuff around just adds an unnecessary typecheck.

James M. Lawrence (llmjjmll) wrote :

This was whittled down from a bordeaux-threads bug. Please remove the invalid designation. Note the "when nil", which is the fboundp test in bordeaux-threads. The bug is about the failed type derivation.

Stas Boukarev (stassats) wrote :

(defun foo () 1)

(defun x ()
  (sb-int:named-lambda foo () :bar))

(defun foo2 ()
  (1+ (foo)))

named-lambda causes the type to get derived.

summary: - Confusion with non-toplevel defun
+ named-lambda clobbers type derivation
Changed in sbcl:
status: Invalid → Triaged
tags: added: compiler-ir1
Changed in sbcl:
importance: Undecided → Low
James M. Lawrence (llmjjmll) wrote :

More closely related to the original bordeaux-threads problem is:

(defparameter *foo* 99)
(declaim (inline foo))
(defun foo () *foo*)

(defun x ()
  (sb-int:named-lambda foo () :bar))

(defun foo2 ()
  (let ((z (foo)))

(foo2) ;=> :BAR

James M. Lawrence (llmjjmll) wrote :

... so for an inline function it's the definition that's clobbered, not just the type derivation. To me this is more alarming than a low priority bug, but whatever you decide.

Stas Boukarev (stassats) wrote :

The definition is clobbered when it's declared INLINE.

Changed in sbcl:
importance: Low → Medium
Douglas Katzman (dougk) wrote :

I don't think this bug is about inline-ness.

(defun defit1 () (defun foo () :bar))
(defun defit2 () (defun foo () :mumble))

* (compile-file "/tmp/foo.lisp")
* (sb-int:info :function :type 'foo)

The fact that anything happens at all to global information when a non-toplevel named-lambda is processed is weird.
I don't think the compiler is supposed to assume stuff about definitions in the same file when they didn't happen at toplevel.

Stas Boukarev (stassats) wrote :


Changed in sbcl:
status: Triaged → Fix Committed
Stas Boukarev (stassats) on 2018-05-29
Changed in sbcl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Duplicates of this bug

Other bug subscribers