[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: constant folding/smashing



	
    Date: Fri, 10 Jun 88 14:28 EDT
    From: David A. Moon <Moon@STONY-BROOK.SCRC.Symbolics.COM>
    
	Date: 10 Jun 1988 11:03-EDT
	From: NGALL@G.BBN.COM
    
	....
	And this brings up the second example of the confusion in constant
	folding that no one has yet addressed: Why are lists and strings
	(among others) constant folded, but not general vectors, since all of
	them are composite objects?  
    
    What makes you think that is true?  (I assume you mean "coalesced", that
    is, two distinct pieces of source text resulting in a single object in the
    compiled program, rather than "constant folded", which means a pure function
    with constant arguments replaced by its constant result.)  I don't of
Yes. I meant "collapsed" (CLtL pg. 78) not "folded".
    anything that says that Common Lisp must treat quoted general vectors
    differently from quoted strings.  If some implementations do so, that's
    merely an implementation. 
I think my statement above is true based on pg. 78 (Collapsing
constants that are EQUAL) and pg. 80 (Def of EQUAL): Object X may be
collapsed with object Y iff (AND (EQUAL X Y) (NOT (EQ X Y))).  This
condition can hold for strings, but NOT for general vectors, since any
EQUAL general vectors are EQ and hence are already collapsed.

	[3] (EQ (QUOTE #1=(1 2 3))  (QUOTE #1#)) => T or NIL, wow!!!!!
    
    I see no evidence that any interpreter or compiler is permitted to
    return NIL for the above form.
According to the above quoted passages, the following definition for
COPY-QUOTE is semantically equivalent to QUOTE:
 (defvar *copy-quote-flip-flop* nil)
 (defmacro copy-quote (obj)
   `(let ((obj-copy (copy ',obj)))
      (if (and (equal ',obj obj-copy)
               (setf *copy-quote-flip-flop* (not *copy-quote-flip-flop*)))
          obj-copy
          ',obj)))
 [Where COPY is a function that dispatches off to the appropiate copy
 function (e.g., COPY-SEQ, COPY-SYMBOL, etc) if there is one, otherwise
 it returns its arg.]
If you agree with this assertion, then you'll agree that an
implementation that used the above semantics for QUOTE, would return
NIL in example [3].

    What you're probably thinking of
    is (EQ (QUOTE #(1 2 3)) (QUOTE #(1 2 3))), which might be true or false.

Assuming that READ is non-structure-sharing, this predicate form MUST
return NIL in ALL implementations.  The two vectors are not EQUAL so
they cannot be collapsed!  Agreed?
    Once you (or anyone else in this somewhat rambling and inconclusive
    discussion) think you understand the issues above, figure out what
    you think about these three forms:
    
      (EQ (FUNCTION (LAMBDA () 1)) (FUNCTION (LAMBDA () 1)))
T or NIL    
      (EQ (FUNCTION (LAMBDA (N) (DO ((I 1 (1+ I)) (A 0 (+ A I)))
				    ((>= I N) A))))
	  (FUNCTION (LAMBDA (N) (DO ((I 0 (1+ I)) (A 0 (+ A I)))
				    ((>= I N) A)))))
T or NIL    
      (EQ (FUNCTION (LAMBDA (N) (DO ((I 1 (1+ I)) (A 0 (+ A I)))
				    ((>= I N) A))))
	  (FUNCTION (LAMBDA (N) (* N (1- N) 1/2))))
T or NIL (what an optimizer! :-)
Based on my interpretation of the description of FUNCTION pgs. 87-89
But I think you're getting away from the point.

    I think you'll find that in some systems compiled code and its constants
    become read-only during a system building procedure, but not when you
    just call the COMPILE or LOAD functions.  Nobody says read-onlyness
    of constants is -required- to be enforced.
You're right, nobody did say it.

	...you are collapsing two behaviors into one special
	form.  A bad idea in this case....
    
	I hope CLtL would clean-up EQUAL to mean "collapsable" rather than
	subject the poor Lisp novice to yet another slightly-different
	equality predicate.
	
    The above two statements don't seem to me to be based on a consistent
    philosophy.
    
You're right, I should have said

 ...you are collapsing two [unrelated] behaviors into one special
 form.  A bad idea in this case....
    
 I hope CLtL would clean-up EQUAL to mean "collapsable" rather than
 subject the poor Lisp novice to yet another [closely related]
 equality predicate.
	
I think the confusion in the discussion demonstrates conclusively that
the current semantics of QUOTE is not well defined.

-- Nick