duplicated creation of toplevel objects in c compiler
compile-load this file. "constructing" string should be printed once per instance. due to having two data vectors (one for permanent objects and one for temporary objects which are used in top-level forms) we may have duplicated entries. That is reflected in a fixme in src/cmp/cmpwt.lsp:add-object
;; FIXME! Currently we have two data vectors and, when compiling ;; files, it may happen that a constant is duplicated and stored ;; both in VV and VVtemp. This would not be a problem if the ;; constant were readable, but due to using MAKE-LOAD-FORM we may ;; end up having two non-EQ objects created for the same value.
code to reproduce:
(eval-when (:compile-toplevel :load-toplevel :execute) (defclass my-class () ((name :initarg :name :accessor name) (parent :accessor compiler-test-parent :initform nil) (children :initarg :children :accessor compiler-test-children :initform nil))) (defmethod make-load-form ((x my-class) &optional environment) (declare (ignore environment)) (values ;; make,init `(progn (format t "~&constructing ~s~%" ',(name x)) (make-instance ',(class-of x) :children ',(slot-value x 'children) :name ',(slot-value x 'name))) `(setf (compiler-test-parent ',x) ',(slot-value x 'parent))))) (eval-when (:compile-toplevel) (defvar s4 (make-instance 'my-class :name :s4)) (defvar s5 (make-instance 'my-class :name :s5)) (setf (compiler-test-parent s5) s4) (setf (compiler-test-children s4) (list s5))) ;; (defun foo () ;; (let ((x #.s4) ;; (y #.s5)) ;; (format t "~a: ~a, ~a~%~a: ~a, ~a~%" ;; x (compiler-test-parent x) (compiler-test-children x) ;; y (compiler-test-parent y) (compiler-test-children y)) ;; (cons x y))) (let ((a '#.s4)) (print a)) (defun foo () (let ((x #.s4)) x))
if we swap
let form and defun
form, then problem doesn't happen, because object is first added to the permanent storage.
objects should migrate from temporary storage to permanent storage. This issue report is a side-product of fixing #562 -- I've planned to fix it altogether, but after a thought I've concluded that more serious refactor is necessary to make it a clean improvement, so that will wait for after the release.