all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* byte-compile-preprocess+cconv seem to mutate self evaluating forms in expanded macros
@ 2023-01-20 12:40 Vibhav Pant
  2023-01-20 13:03 ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Vibhav Pant @ 2023-01-20 12:40 UTC (permalink / raw)
  To: emacs-devel, monnier

[-- Attachment #1: Type: text/plain, Size: 1543 bytes --]

While working on scratch/comp-static-data, which adds support for
native compiling self evaluating forms in Lisp code as static consts in
the eln (with immutability enforced additionally by `CHECK_IMPURE`), I
noticed that compiling minor-mode definitions would result in a
`pure_write_error`. This arises as cconv-closure-convert, called from
`byte-compile-preprocess` would call `setcar` on a self evaluating
interactive form as part of the minor-mode's function body.

A hacky way to reproduce this would be to stuff the following snippet
into loadup.el (purecopy ensures modifying the list triggers an error):

```
(load "emacs-lisp/bytecomp")
(setq sample-interactive-spec
      (purecopy '(interactive
                  (list (if current-prefix-arg
                            (prefix-numeric-value 
                             current-prefix-arg)
                          'toggle)))))

(defmacro define-purecopied-func ()
  `(defun foo-bar (arg)
     ,sample-interactive-spec))

(let ((byte-compile-debug t))
  (byte-compile '(define-purecopied-func)))
```
(Alternatively, just building scratch/comp-static-data will also
reproduce these errors)

Because modifying self-evaluating forms is technically undefined
behaviour as per the Elisp reference manual
(https://www.gnu.org/software/emacs/manual/html_node/elisp/Mutability.html),
shouldn't we be use 'copy-tree' after macro expansion in these cases?


-- 
Vibhav Pant
vibhavp@gmail.com
GPG: 7ED1 D48C 513C A024 BE3A  785F E3FB 28CB 6AB5 9598

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-01-20 21:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-20 12:40 byte-compile-preprocess+cconv seem to mutate self evaluating forms in expanded macros Vibhav Pant
2023-01-20 13:03 ` Stefan Monnier
2023-01-20 13:13   ` Vibhav Pant
2023-01-20 18:21     ` Stefan Monnier
2023-01-20 21:27       ` Vibhav Pant

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.