diff options
| author | Chong Yidong | 2007-04-11 17:10:42 +0000 |
|---|---|---|
| committer | Chong Yidong | 2007-04-11 17:10:42 +0000 |
| commit | fb67ebdf160ef0b56573e0ad092114d5aa93eabd (patch) | |
| tree | 18b41ffd1210df7af75358157b2e88776a762e60 | |
| parent | f782c3293c257308cf9b79207278506e8600fadf (diff) | |
| download | emacs-fb67ebdf160ef0b56573e0ad092114d5aa93eabd.tar.gz emacs-fb67ebdf160ef0b56573e0ad092114d5aa93eabd.zip | |
(byte-optimize-form-code-walker): Evaluate pure function calls if possible.
(byte-optimize-all-constp): New function.
| -rw-r--r-- | lisp/emacs-lisp/byte-opt.el | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el index a9dedae398c..2c9dc8e3314 100644 --- a/lisp/emacs-lisp/byte-opt.el +++ b/lisp/emacs-lisp/byte-opt.el | |||
| @@ -557,8 +557,20 @@ | |||
| 557 | ;; Otherwise, no args can be considered to be for-effect, | 557 | ;; Otherwise, no args can be considered to be for-effect, |
| 558 | ;; even if the called function is for-effect, because we | 558 | ;; even if the called function is for-effect, because we |
| 559 | ;; don't know anything about that function. | 559 | ;; don't know anything about that function. |
| 560 | (cons fn (mapcar 'byte-optimize-form (cdr form))))))) | 560 | (let ((args (mapcar #'byte-optimize-form (cdr form)))) |
| 561 | 561 | (if (and (get fn 'pure) | |
| 562 | (byte-optimize-all-constp args)) | ||
| 563 | (list 'quote (apply fn (mapcar #'eval args))) | ||
| 564 | (cons fn args))))))) | ||
| 565 | |||
| 566 | (defun byte-optimize-all-constp (list) | ||
| 567 | "Non-nil iff all elements of LIST satisfy `byte-compile-constp'." | ||
| 568 | (let ((constant t)) | ||
| 569 | (while (and list constant) | ||
| 570 | (unless (byte-compile-constp (car list)) | ||
| 571 | (setq constant nil)) | ||
| 572 | (setq list (cdr list))) | ||
| 573 | constant)) | ||
| 562 | 574 | ||
| 563 | (defun byte-optimize-form (form &optional for-effect) | 575 | (defun byte-optimize-form (form &optional for-effect) |
| 564 | "The source-level pass of the optimizer." | 576 | "The source-level pass of the optimizer." |
| @@ -1241,6 +1253,18 @@ | |||
| 1241 | (setq side-effect-and-error-free-fns (cdr side-effect-and-error-free-fns))) | 1253 | (setq side-effect-and-error-free-fns (cdr side-effect-and-error-free-fns))) |
| 1242 | nil) | 1254 | nil) |
| 1243 | 1255 | ||
| 1256 | |||
| 1257 | ;; pure functions are side-effect free functions whose values depend | ||
| 1258 | ;; only on their arguments. For these functions, calls with constant | ||
| 1259 | ;; arguments can be evaluated at compile time. This may shift run time | ||
| 1260 | ;; errors to compile time. | ||
| 1261 | |||
| 1262 | (let ((pure-fns | ||
| 1263 | '(concat symbol-name regexp-opt regexp-quote string-to-syntax))) | ||
| 1264 | (while pure-fns | ||
| 1265 | (put (car pure-fns) 'pure t) | ||
| 1266 | (setq pure-fns (cdr pure-fns))) | ||
| 1267 | nil) | ||
| 1244 | 1268 | ||
| 1245 | (defun byte-compile-splice-in-already-compiled-code (form) | 1269 | (defun byte-compile-splice-in-already-compiled-code (form) |
| 1246 | ;; form is (byte-code "..." [...] n) | 1270 | ;; form is (byte-code "..." [...] n) |