gcl-devel
[Top][All Lists]
Advanced

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

[Gcl-devel] Thoughts on reverse type propagation


From: Camm Maguire
Subject: [Gcl-devel] Thoughts on reverse type propagation
Date: 14 Apr 2006 18:43:13 -0400
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Greetings!

This subject concerns code like (car (reverse x)), where reverse
should know it will return a list, and that x is a list.  Pursuing
logic like this can clearly get out of hand, as it implies facts about
code involving x ahead of this call in any progn like environment.
But the incf discussion has brought the issue to the fore again.
Perhaps ew can capture the bulk of the cases of interest.

Here's the idea.  Wrap certain arguments in a 'the form, e.g. (car x)
-> (car (the list x)), at least at certain safety levels.  In c1setq1
c1the, and c1let bindings, traverse the pass1 processed representation
of the originating form and set its type from the type of the
destination form loosely as follows:

(defun set-form-type (form type)
  (let* ((it (info-type (cadr form)))
         (nt (type-and type it)))
    (unless nt
      (cmpwarn "Type mismatch: ~s ~s~%" it type))
    (setf (info-type (cadr form)) nt)
    (case (car form)
          ((let let*) (set-form-type (car (last form)) type))
          (progn (set-form-type (car (last (third form))) type))
          (if 
            (let ((tt (type-and type (info-type (cadr (fourth form)))))
                  (ft (type-and type (info-type (cadr (fifth form))))))
              (unless tt
                (set-form-type (fifth form) type)
                (setf (car form) 'progn (cadr form) (cadr (fifth form)) (caddr 
form) (list (fifth form)) (cdddr form) nil))
              (unless ft
                (set-form-type (fourth form) type)
                (setf (car form) 'progn (cadr form) (cadr (fourth
  form)) (caddr form) (list (fourth form)) (cdddr form) nil)))))))

i.e. locate the subforms yielding the return type of the master form
(i.e. the last form in let, etc.) and set their types as well,
performing ex post facto branch elimination if any branch type is
found to be nil.  This is working here locally, and solves the incf
optimization issue among others, for example.

Then, if pre-macroexpansion can be achieved, add explicit type
declarations corresponding to reverse inference as follows:

(let ((g (foo))) (car g)) -> (let ((g (foo))) (declare (list g)) (car
g)), etc.


These are just thoughts.  Suggestions as always most welcome.

Take care,

-- 
Camm Maguire                                            address@hidden
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah




reply via email to

[Prev in Thread] Current Thread [Next in Thread]