Commit e8dfd197 authored by Stefan Monnier's avatar Stefan Monnier

* lisp/emacs-lisp/cl-macs.el (cl-defsubst): Make it clear that args

are immutable.  Don't use `unsafe' any more.
(cl--defsubst-expand): Don't substitute at the same time as keeping
a residual unused let-binding.  Don't use `unsafe' any more.
parent ba579ea6
2013-08-29 Stefan Monnier <monnier@iro.umontreal.ca>
* emacs-lisp/cl-macs.el (cl-defsubst): Make it clear that args
are immutable. Don't use `unsafe' any more.
(cl--defsubst-expand): Don't substitute at the same time as keeping
a residual unused let-binding. Don't use `unsafe' any more.
2013-08-29 Glenn Morris <rgm@gnu.org> 2013-08-29 Glenn Morris <rgm@gnu.org>
* calendar/cal-china.el (calendar-chinese-year-cache): * calendar/cal-china.el (calendar-chinese-year-cache):
......
...@@ -2693,15 +2693,16 @@ macro that returns its `&whole' argument." ...@@ -2693,15 +2693,16 @@ macro that returns its `&whole' argument."
;;;###autoload ;;;###autoload
(defmacro cl-defsubst (name args &rest body) (defmacro cl-defsubst (name args &rest body)
"Define NAME as a function. "Define NAME as a function.
Like `defun', except the function is automatically declared `inline', Like `defun', except the function is automatically declared `inline' and
the arguments are immutable.
ARGLIST allows full Common Lisp conventions, and BODY is implicitly ARGLIST allows full Common Lisp conventions, and BODY is implicitly
surrounded by (cl-block NAME ...). surrounded by (cl-block NAME ...).
The function's arguments should be treated as immutable.
\(fn NAME ARGLIST [DOCSTRING] BODY...)" \(fn NAME ARGLIST [DOCSTRING] BODY...)"
(declare (debug cl-defun) (indent 2)) (declare (debug cl-defun) (indent 2))
(let* ((argns (cl--arglist-args args)) (p argns) (let* ((argns (cl--arglist-args args)) (p argns)
(pbody (cons 'progn body)) (pbody (cons 'progn body)))
(unsafe (not (cl--safe-expr-p pbody))))
(while (and p (eq (cl--expr-contains args (car p)) 1)) (pop p)) (while (and p (eq (cl--expr-contains args (car p)) 1)) (pop p))
`(progn `(progn
,(if p nil ; give up if defaults refer to earlier args ,(if p nil ; give up if defaults refer to earlier args
...@@ -2717,10 +2718,10 @@ surrounded by (cl-block NAME ...). ...@@ -2717,10 +2718,10 @@ surrounded by (cl-block NAME ...).
;; does not pay attention to the argvs (and ;; does not pay attention to the argvs (and
;; cl-expr-access-order itself is also too naive). ;; cl-expr-access-order itself is also too naive).
nil nil
,(and (memq '&key args) 'cl-whole) ,unsafe ,@argns))) ,(and (memq '&key args) 'cl-whole) nil ,@argns)))
(cl-defun ,name ,args ,@body)))) (cl-defun ,name ,args ,@body))))
(defun cl--defsubst-expand (argns body simple whole unsafe &rest argvs) (defun cl--defsubst-expand (argns body simple whole _unsafe &rest argvs)
(if (and whole (not (cl--safe-expr-p (cons 'progn argvs)))) whole (if (and whole (not (cl--safe-expr-p (cons 'progn argvs)))) whole
(if (cl--simple-exprs-p argvs) (setq simple t)) (if (cl--simple-exprs-p argvs) (setq simple t))
(let* ((substs ()) (let* ((substs ())
...@@ -2728,7 +2729,7 @@ surrounded by (cl-block NAME ...). ...@@ -2728,7 +2729,7 @@ surrounded by (cl-block NAME ...).
(cl-mapcar (lambda (argn argv) (cl-mapcar (lambda (argn argv)
(if (or simple (macroexp-const-p argv)) (if (or simple (macroexp-const-p argv))
(progn (push (cons argn argv) substs) (progn (push (cons argn argv) substs)
(and unsafe (list argn argv))) nil)
(list argn argv))) (list argn argv)))
argns argvs)))) argns argvs))))
;; FIXME: `sublis/subst' will happily substitute the symbol ;; FIXME: `sublis/subst' will happily substitute the symbol
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment