fasl dump fails when function type contains structures

Bug #1929160 reported by Yurii Hryhorenko
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Undecided
Unassigned

Bug Description

I was trying to use member type with structure instances as members as a part of a function type declaration. Some functions that use such a function fail to compile with 'attempt to dump invalid structure' error when the debug level is greater than 0.

Test case:

(eval-when (:compile-toplevel)
  (defstruct my-struct)

  (defvar *my-struct* (make-my-struct))

  (defmethod make-load-form ((struct my-struct) &optional env)
    (declare (ignore env))
    '*my-struct*))

(deftype my-struct-type ()
  `(member ,*my-struct*))

(declaim (ftype (function () my-struct-type) my-func))
(defun my-func ()
  *my-struct*)

Compilation of the following code in a separate file

(declaim (optimize (debug 1)))

(defun my-func-2 ()
  (my-func))

fails with

  attempt to dump invalid structure:
    #S(MY-STRUCT)

SBCL version: SBCL 2.1.2.nixos
uname -a: Linux hp-800g1 5.4.108 #1-NixOS SMP Wed Mar 24 10:26:46 UTC 2021 x86_64 GNU/Linux

*FEATURES*:
(:ASDF3.3 :ASDF3.2 :ASDF3.1 :ASDF3 :ASDF2 :ASDF :OS-UNIX
 :NON-BASE-CHARS-EXIST-P :ASDF-UNICODE :SWANK :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
Yurii Hryhorenko (rsauex) wrote :
Download full text (3.3 KiB)

Error:

attempt to dump invalid structure:
  #S(MY-STRUCT)
How did this happen?
   [Condition of type SIMPLE-ERROR]

Restarts:
 0: [ABORT] Abort compilation.
 1: [*ABORT] Return to SLIME's top level.
 2: [ABORT] abort thread (#<THREAD "worker" RUNNING {100649E3B3}>)

Backtrace:
  0: (SB-FASL::DUMP-STRUCTURE #S(MY-STRUCT) #<SB-FASL:FASL-OUTPUT "/home/rsauex/test.fasl">)
  1: (SB-FASL::DUMP-NON-IMMEDIATE-OBJECT #S(MY-STRUCT) #<SB-FASL:FASL-OUTPUT "/home/rsauex/test.fasl">)
  2: (SB-FASL::DUMP-LIST (MEMBER #S(MY-STRUCT)) #<SB-FASL:FASL-OUTPUT "/home/rsauex/test.fasl"> T)
  3: (SB-FASL::DUMP-LIST (VALUES (MEMBER #S(MY-STRUCT)) &REST T) #<SB-FASL:FASL-OUTPUT "/home/rsauex/test.fasl"> T)
  4: (SB-FASL::DUMP-LIST (FUNCTION NIL (VALUES (MEMBER #S(MY-STRUCT)) &REST T)) #<SB-FASL:FASL-OUTPUT "/home/rsauex/test.fasl"> T)
  5: (SB-FASL::DUMP-LIST ((FUNCTION NIL (VALUES # &REST T)) . #(#(0 1 1 1) MY-FUNC)) #<SB-FASL:FASL-OUTPUT "/home/rsauex/test.fasl"> T)
  6: (SB-FASL::DUMP-NON-IMMEDIATE-OBJECT ((FUNCTION NIL (VALUES # &REST T)) . #(#(0 1 1 1) MY-FUNC)) #<SB-FASL:FASL-OUTPUT "/home/rsauex/test.fasl">)
  7: (SB-FASL:DUMP-OBJECT ((FUNCTION NIL (VALUES # &REST T)) . #(#(0 1 1 1) MY-FUNC)) #<SB-FASL:FASL-OUTPUT "/home/rsauex/test.fasl">)
  8: (SB-FASL::DUMP-CODE-OBJECT #<SB-C:COMPONENT :NAME "DEFUN MY-FUNC-2" {100698B553}> #<SB-ASSEM:SEGMENT {100699C173}> 152 (#S(SB-C::FIXUP-NOTE :KIND :RELATIVE :FIXUP #S(SB-C:FIXUP :NAME SB-C:RETURN-MULTI..
  9: (SB-FASL:FASL-DUMP-COMPONENT #<SB-C:COMPONENT :NAME "DEFUN MY-FUNC-2" {100698B553}> #<SB-ASSEM:SEGMENT {100699C173}> 152 (#S(SB-C::FIXUP-NOTE :KIND :RELATIVE :FIXUP #S(SB-C:FIXUP :NAME SB-C:RETURN-MUL..
 10: (SB-C::%COMPILE-COMPONENT #<SB-C:COMPONENT :NAME "DEFUN MY-FUNC-2" {100698B553}>)
 11: (SB-C::COMPILE-COMPONENT #<SB-C:COMPONENT :NAME "DEFUN MY-FUNC-2" {100698B553}>)
 12: (SB-C::COMPILE-TOPLEVEL (#<SB-C::CLAMBDA :%SOURCE-NAME SB-C::.ANONYMOUS. :%DEBUG-NAME (SB-C::TOP-LEVEL-FORM #) :KIND :TOPLEVEL :TYPE #<SB-KERNEL:BUILT-IN-CLASSOID FUNCTION (read-only)> :WHERE-FROM :DE..
 13: (SB-C::CONVERT-AND-MAYBE-COMPILE (SB-IMPL::%DEFUN (QUOTE MY-FUNC-2) (SB-INT:NAMED-LAMBDA MY-FUNC-2 NIL (DECLARE #) (BLOCK MY-FUNC-2 #))) (#1=(SB-IMPL::%DEFUN (QUOTE MY-FUNC-2) (SB-INT:NAMED-LAMBDA MY-..
 14: (SB-C::PROCESS-TOPLEVEL-FORM (SB-IMPL::%DEFUN (QUOTE MY-FUNC-2) (SB-INT:NAMED-LAMBDA MY-FUNC-2 NIL (DECLARE #) (BLOCK MY-FUNC-2 #))) ((PROGN (EVAL-WHEN # #) (SB-IMPL::%DEFUN # #)) SB-C::ORIGINAL-SOURC..
 15: (SB-C::PROCESS-TOPLEVEL-PROGN ((EVAL-WHEN (:COMPILE-TOPLEVEL) (SB-C:%COMPILER-DEFUN # T NIL NIL)) (SB-IMPL::%DEFUN (QUOTE MY-FUNC-2) (SB-INT:NAMED-LAMBDA MY-FUNC-2 NIL # #))) ((PROGN (EVAL-WHEN # #) (..
 16: (SB-C::PROCESS-TOPLEVEL-FORM (PROGN (EVAL-WHEN (:COMPILE-TOPLEVEL) (SB-C:%COMPILER-DEFUN # T NIL NIL)) (SB-IMPL::%DEFUN (QUOTE MY-FUNC-2) (SB-INT:NAMED-LAMBDA MY-FUNC-2 NIL # #))) (SB-C::ORIGINAL-SOUR..
 17: (SB-C::PROCESS-TOPLEVEL-FORM (DEFUN MY-FUNC-2 NIL (MY-FUNC)) (SB-C::ORIGINAL-SOURCE-START 0 1) NIL)
 18: ((LAMBDA (SB-KERNEL:FORM &KEY :CURRENT-INDEX &ALLOW-OTHER-KEYS) :IN SB-C::SUB-COMPILE-FILE) (DEFUN MY-FUNC-2 NIL (MY-FUNC)) :CURRENT-INDEX 1)
 19: (SB-C::%DO-FORMS-FROM-INFO #<FUNCTION (LAMBDA (SB-KERNEL:FORM &KEY :CUR...

Read more...

Revision history for this message
Yurii Hryhorenko (rsauex) wrote :

After some poking around, I was able to fix the issue locally. Diff attached.

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

Thanks.

Changed in sbcl:
status: New → Fix Committed
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.

Other bug subscribers