1.0.17.24: refactor handling of constants in the compiler
[sbcl.git] / src / compiler / node.lisp
index ac17c72..afcb90d 100644 (file)
     (functional-%debug-name leaf)))
 
 ;;; The CONSTANT structure is used to represent known constant values.
-;;; If NAME is not null, then it is the name of the named constant
-;;; which this leaf corresponds to, otherwise this is an anonymous
-;;; constant.
-(def!struct (constant (:include leaf))
+;;; Since the same constant leaf may be shared between named and anonymous
+;;; constants, %SOURCE-NAME is never used.
+(def!struct (constant (:constructor make-constant (value
+                                                   &aux
+                                                   (type (ctype-of value))
+                                                   (%source-name '.anonynous.)
+                                                   (where-from :defined)))
+                      (:include leaf))
   ;; the value of the constant
-  (value nil :type t))
+  (value (missing-arg) :type t))
 (defprinter (constant :identity t)
-  (%source-name :test %source-name)
   value)
 
 ;;; The BASIC-VAR structure represents information common to all
 (def!struct (ref (:include valued-node (reoptimize nil))
                  (:constructor make-ref
                                (leaf
+                                &optional (%source-name '.anonymous.)
                                 &aux (leaf-type (leaf-type leaf))
                                 (derived-type
                                  (make-single-value-type leaf-type))))
                  (:copier nil))
   ;; The leaf referenced.
-  (leaf nil :type leaf))
+  (leaf nil :type leaf)
+  ;; CONSTANT nodes are always anonymous, since we wish to coalesce named and
+  ;; unnamed constants that are equivalent, we need to keep track of the
+  ;; reference name for XREF.
+  (%source-name (missing-arg) :type symbol :read-only t))
 (defprinter (ref :identity t)
   #!+sb-show id
+  %source-name
   leaf)
 
 ;;; Naturally, the IF node always appears at the end of a block.