Slot access failure in interpreted mode

Bug #2008922 reported by Jonathan Braud
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
Undecided
Unassigned

Bug Description

When using the interpreter, accessing a slot fails in some situations. After evaluating this:

    (setq *evaluator-mode* :interpret)

    (defclass foo () ((x :initform 123)))

    (defun foo-x-0 (foo)
      (slot-value foo 'x))

    (defmethod foo-x-1 ((foo foo))
      (slot-value foo 'x))

    (defmethod foo-x-2 ((foo foo))
      (let ((%foo foo))
        (slot-value %foo 'x)))

    (defmethod foo-x-3 ((foo t))
      (slot-value foo 'x))

I get the following results:

    (foo-x-0 (make-instance 'foo)) => ERROR
    (foo-x-1 (make-instance 'foo)) => 123
    (foo-x-2 (make-instance 'foo)) => ERROR
    (foo-x-3 (make-instance 'foo)) => ERROR

The error is:

  The function
  (SB-PCL::SLOT-ACCESSOR :GLOBAL COMMON-LISP-USER::X SB-PCL::READER) is
  undefined.

There is no such problem when *EVALUATOR-MODE* is :COMPILE.

Looking at the FUNCTION-LAMBDA-EXPRESSION of the four functions, the slot access goes through a call to:

  For foo-x-0: SLOT-VALUE
  For foo-x-1: SB-PCL::OPTIMIZED-SLOT-VALUE
  For foo-x-2: SB-PCL::ACCESSOR-SLOT-VALUE
  For foo-x-3: SB-PCL::ACCESSOR-SLOT-VALUE

(Presumably because FOO-X-1 knows the type of the first argument to SLOT-VALUE but the other functions don't.)

It looks like the compiler defines the function (SB-PCL::SLOT-ACCESSOR :GLOBAL COMMON-LISP-USER::X SB-PCL::READER) but the interpreter doesn't, because simply compiling FOO-X-0 makes everything right:

    (compile 'foo-x-0)
    (foo-x-3 (make-instance 'foo)) => 123
    (foo-x-2 (make-instance 'foo)) => 123
    (foo-x-1 (make-instance 'foo)) => 123
    (foo-x-0 (make-instance 'foo)) => 123

The problem persists in version 2.3.2.8-63bafe1ba.

uname -a: Linux io 6.1.12-arch1-1 #1 SMP PREEMPT_DYNAMIC Tue, 14 Feb 2023 22:08:08 +0000 x86_64 GNU/Linux

*FEATURES*:
(:ARENA-ALLOCATOR :X86-64 :GENCGC :64-BIT :ANSI-CL :COMMON-LISP :ELF
 :IEEE-FLOATING-POINT :LINUX :LITTLE-ENDIAN :PACKAGE-LOCAL-NICKNAMES :SB-LDB
 :SB-PACKAGE-LOCKS :SB-THREAD :SB-UNICODE :SBCL :UNIX)

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

Not a problem with sb-fasteval.

Changed in sbcl:
assignee: nobody → Christophe Rhodes (csr21-cantab)
Revision history for this message
Stas Boukarev (stassats) wrote :

Maybe it's time to leave just sb-fasteval?

Revision history for this message
Christophe Rhodes (csr21-cantab) wrote :

Thanks for the report. Does the attached patch fix things for you more generally?

Revision history for this message
Douglas Katzman (dougk) wrote :

I agree with Stas. Anything sb-eval can do, sb-fasteval can do better.

Revision history for this message
Jonathan Braud (jathd) wrote :

Thanks for the patch, it fixes the problem.

(BTW: I wasn't aware of the sb-fasteval option because I'm simply using my distro's default sbcl package, which builds with --fancy. Same goes for Ubuntu and Debian. If there's no downside to using sb-fasteval, maybe it should be included in --fancy?)

Changed in sbcl:
status: New → Fix Committed
assignee: Christophe Rhodes (csr21-cantab) → nobody
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.