* bug#60974: 30.0.50; byte-compile-preprocess mutates self evaluating forms in expanded macro bodies [not found] <b979003119097f23f6b13d5bc4f561596cdb9704.camel@gmail.com> @ 2023-01-20 21:35 ` Vibhav Pant 2023-01-21 5:43 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 0 siblings, 1 reply; 10+ messages in thread From: Vibhav Pant @ 2023-01-20 21:35 UTC (permalink / raw) To: 60974, monnier; +Cc: emacs-devel [-- Attachment #1.1: Type: text/plain, Size: 160 bytes --] The attached patch should fix this, thoughts? Best, Vibhav -- Vibhav Pant vibhavp@gmail.com GPG: 7ED1 D48C 513C A024 BE3A 785F E3FB 28CB 6AB5 9598 [-- Attachment #1.2: Type: text/x-patch, Size: 744 bytes --] diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index aa9521e5a65..847965e6af6 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -2581,7 +2581,8 @@ byte-compile-flush-pending (defun byte-compile-preprocess (form &optional _for-effect) (let ((print-symbols-bare t)) ; Possibly redundant binding. - (setq form (macroexpand-all form byte-compile-macro-environment))) + (setq form (copy-tree + (macroexpand-all form byte-compile-macro-environment)))) ;; FIXME: We should run byte-optimize-form here, but it currently does not ;; recurse through all the code, so we'd have to fix this first. ;; Maybe a good fix would be to merge byte-optimize-form into [-- Attachment #2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply related [flat|nested] 10+ messages in thread
* bug#60974: 30.0.50; byte-compile-preprocess mutates self evaluating forms in expanded macro bodies 2023-01-20 21:35 ` bug#60974: 30.0.50; byte-compile-preprocess mutates self evaluating forms in expanded macro bodies Vibhav Pant @ 2023-01-21 5:43 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 2023-01-27 12:44 ` Vibhav Pant 0 siblings, 1 reply; 10+ messages in thread From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-01-21 5:43 UTC (permalink / raw) To: Vibhav Pant; +Cc: 60974, emacs-devel > The attached patch should fix this, thoughts? It's not really an option: - it's expensive - it breaks code when it doesn't form a tree, e.g. (list '#1=(a b #1#) 'c 'd) Instead, we need to find out where in the code we perform the side effect and change just that part. Stefan ^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#60974: 30.0.50; byte-compile-preprocess mutates self evaluating forms in expanded macro bodies 2023-01-21 5:43 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-01-27 12:44 ` Vibhav Pant 2023-01-28 23:10 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 0 siblings, 1 reply; 10+ messages in thread From: Vibhav Pant @ 2023-01-27 12:44 UTC (permalink / raw) To: Stefan Monnier; +Cc: 60974, emacs-devel [-- Attachment #1.1: Type: text/plain, Size: 723 bytes --] On Sat, 2023-01-21 at 00:43 -0500, Stefan Monnier wrote: > > The attached patch should fix this, thoughts? > > It's not really an option: > - it's expensive > - it breaks code when it doesn't form a tree, e.g. > > (list '#1=(a b #1#) 'c 'd) > > Instead, we need to find out where in the code we perform the > side effect and change just that part. > > > Stefan > Ah, right. Theother way I could think of a fix is setq-ing `form` to a shallow copy of the original form, with only the place(s) changed. This patch tries to do that by using `pcase-let` to destructure forms. -- Vibhav Pant vibhavp@gmail.com GPG: 7ED1 D48C 513C A024 BE3A 785F E3FB 28CB 6AB5 9598 [-- Attachment #1.2: Type: text/x-patch, Size: 2412 bytes --] diff --git a/lisp/emacs-lisp/cconv.el b/lisp/emacs-lisp/cconv.el index e715bd90a00..f6160a13579 100644 --- a/lisp/emacs-lisp/cconv.el +++ b/lisp/emacs-lisp/cconv.el @@ -477,20 +477,37 @@ cconv-convert branch)) cond-forms))) - (`(function (lambda ,args . ,body) . ,_) + (`(function (lambda ,args . ,body) . ,rest) (let* ((docstring (if (eq :documentation (car-safe (car body))) (cconv-convert (cadr (pop body)) env extend))) (bf (if (stringp (car body)) (cdr body) body)) (if (when (eq 'interactive (car-safe (car bf))) (gethash form cconv--interactive-form-funs))) (cif (when if (cconv-convert if env extend))) - (_ (pcase cif - (`#'(lambda () ,form) (setf (cadr (car bf)) form) (setq cif nil)) - ('nil nil) - ;; The interactive form needs special treatment, so the form - ;; inside the `interactive' won't be used any further. - (_ (setf (cadr (car bf)) nil)))) - (cf (cconv--convert-function args body env form docstring))) + (cf nil)) + (pcase cif + (`#'(lambda () ,form) + (pcase-let ((`((,f1 . (,_ . ,f2)) . ,f3) bf)) + (setq bf `((,f1 . (,form . ,f2)) . ,f3))) + (setq cif nil)) + ('nil (setq bf nil)) + ;; The interactive form needs special treatment, so the form + ;; inside the `interactive' won't be used any further. + (_ (pcase-let ((`((,f1 . (,_ . ,f2)) . ,f3) bf)) + (setq bf `((,f1 . (nil . ,f2)) . ,f3))))) + (when bf + ;; If we modified bf, re-build body and form as + ;; copies with the modified bits. + (setq body (if (stringp (car body)) + (cons (car body) bf) + bf) + form `(function (lambda ,args . ,body) . ,rest)) + ;; Also, remove the current old entry on the alist, replacing + ;; it with the new one. + (let ((entry (pop cconv-freevars-alist))) + (push (cons body (cdr entry)) cconv-freevars-alist))) + (setq cf (cconv--convert-function args body env form docstring)) + (if (not cif) ;; Normal case, the interactive form needs no special treatment. cf [-- Attachment #2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply related [flat|nested] 10+ messages in thread
* bug#60974: 30.0.50; byte-compile-preprocess mutates self evaluating forms in expanded macro bodies 2023-01-27 12:44 ` Vibhav Pant @ 2023-01-28 23:10 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 2023-01-31 13:52 ` Vibhav Pant 0 siblings, 1 reply; 10+ messages in thread From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-01-28 23:10 UTC (permalink / raw) To: Vibhav Pant; +Cc: 60974, emacs-devel > Ah, right. Theother way I could think of a fix is setq-ing `form` to a > shallow copy of the original form, with only the place(s) changed. This > patch tries to do that by using `pcase-let` to destructure forms. Hmm... yes, that's closer. It's pretty ugly, tho. Yet it's hard to make it less ugly here because the `cconv-freevars-alist` really depends on `eq` equality. Maybe we should pass `cif` to `cconv--convert-function` (or maybe even move most of that `cconv--interactive-form-funs`-handling to that function) and arrange for that function to do the "non-side-effecting-equivalent-of" (setf (cadr (car bf)) form)? Stefan ^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#60974: 30.0.50; byte-compile-preprocess mutates self evaluating forms in expanded macro bodies 2023-01-28 23:10 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-01-31 13:52 ` Vibhav Pant 2023-01-31 14:34 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 0 siblings, 1 reply; 10+ messages in thread From: Vibhav Pant @ 2023-01-31 13:52 UTC (permalink / raw) To: Stefan Monnier; +Cc: 60974, emacs-devel [-- Attachment #1: Type: text/plain, Size: 1086 bytes --] On Sat, 2023-01-28 at 18:10 -0500, Stefan Monnier wrote: > > Ah, right. Theother way I could think of a fix is setq-ing `form` > > to a > > shallow copy of the original form, with only the place(s) changed. > > This > > patch tries to do that by using `pcase-let` to destructure forms. > > Hmm... yes, that's closer. It's pretty ugly, tho. > Yet it's hard to make it less ugly here because the > `cconv-freevars-alist` really depends on `eq` equality. > > Maybe we should pass `cif` to `cconv--convert-function` (or maybe > even > move most of that `cconv--interactive-form-funs`-handling to that > function) and arrange for that function to do the > "non-side-effecting-equivalent-of" (setf (cadr (car bf)) form)? > > > Stefan > I tried to shift the `cif` related bits to `cconc--convert-function`, but my understanding of cconv.el isn't that great, so I wasn't successful at doing that :(. Should I add a TODO to the change for the future? -- 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] 10+ messages in thread
* bug#60974: 30.0.50; byte-compile-preprocess mutates self evaluating forms in expanded macro bodies 2023-01-31 13:52 ` Vibhav Pant @ 2023-01-31 14:34 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 2023-02-01 7:41 ` Vibhav Pant 0 siblings, 1 reply; 10+ messages in thread From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-01-31 14:34 UTC (permalink / raw) To: Vibhav Pant; +Cc: 60974, emacs-devel >> > Ah, right. Theother way I could think of a fix is setq-ing `form` >> > to a >> > shallow copy of the original form, with only the place(s) changed. >> > This >> > patch tries to do that by using `pcase-let` to destructure forms. >> >> Hmm... yes, that's closer. It's pretty ugly, tho. >> Yet it's hard to make it less ugly here because the >> `cconv-freevars-alist` really depends on `eq` equality. >> >> Maybe we should pass `cif` to `cconv--convert-function` (or maybe >> even >> move most of that `cconv--interactive-form-funs`-handling to that >> function) and arrange for that function to do the >> "non-side-effecting-equivalent-of" (setf (cadr (car bf)) form)? >> >> >> Stefan >> > > I tried to shift the `cif` related bits to `cconc--convert-function`, > but my understanding of cconv.el isn't that great, so I wasn't > successful at doing that :( Should I add a TODO to the change for the > future? Yes, please, Stefan ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: bug#60974: 30.0.50; byte-compile-preprocess mutates self evaluating forms in expanded macro bodies 2023-01-31 14:34 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-02-01 7:41 ` Vibhav Pant 2023-02-01 14:33 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 0 siblings, 1 reply; 10+ messages in thread From: Vibhav Pant @ 2023-02-01 7:41 UTC (permalink / raw) To: Stefan Monnier; +Cc: 60974, emacs-devel [-- Attachment #1.1: Type: text/plain, Size: 1295 bytes --] On Tue, 2023-01-31 at 09:34 -0500, Stefan Monnier wrote: > > > > Ah, right. Theother way I could think of a fix is setq-ing > > > > `form` > > > > to a > > > > shallow copy of the original form, with only the place(s) > > > > changed. > > > > This > > > > patch tries to do that by using `pcase-let` to destructure > > > > forms. > > > > > > Hmm... yes, that's closer. It's pretty ugly, tho. > > > Yet it's hard to make it less ugly here because the > > > `cconv-freevars-alist` really depends on `eq` equality. > > > > > > Maybe we should pass `cif` to `cconv--convert-function` (or maybe > > > even > > > move most of that `cconv--interactive-form-funs`-handling to that > > > function) and arrange for that function to do the > > > "non-side-effecting-equivalent-of" (setf (cadr (car bf)) form)? > > > > > > > > > Stefan > > > > > > > I tried to shift the `cif` related bits to `cconc--convert- > > function`, > > but my understanding of cconv.el isn't that great, so I wasn't > > successful at doing that :( Should I add a TODO to the change for > > the > > future? > > Yes, please, > > > Stefan > Done, thoughts? -- Vibhav Pant vibhavp@gmail.com GPG: 7ED1 D48C 513C A024 BE3A 785F E3FB 28CB 6AB5 9598 [-- Attachment #1.2: 60974-3.patch --] [-- Type: text/x-patch, Size: 2591 bytes --] diff --git a/lisp/emacs-lisp/cconv.el b/lisp/emacs-lisp/cconv.el index e715bd90a00..5a6ae798c93 100644 --- a/lisp/emacs-lisp/cconv.el +++ b/lisp/emacs-lisp/cconv.el @@ -477,20 +477,40 @@ cconv-convert branch)) cond-forms))) - (`(function (lambda ,args . ,body) . ,_) + (`(function (lambda ,args . ,body) . ,rest) (let* ((docstring (if (eq :documentation (car-safe (car body))) (cconv-convert (cadr (pop body)) env extend))) (bf (if (stringp (car body)) (cdr body) body)) (if (when (eq 'interactive (car-safe (car bf))) (gethash form cconv--interactive-form-funs))) (cif (when if (cconv-convert if env extend))) - (_ (pcase cif - (`#'(lambda () ,form) (setf (cadr (car bf)) form) (setq cif nil)) - ('nil nil) - ;; The interactive form needs special treatment, so the form - ;; inside the `interactive' won't be used any further. - (_ (setf (cadr (car bf)) nil)))) - (cf (cconv--convert-function args body env form docstring))) + (cf nil)) + ;; TODO: Because we need to non-destructively modify body, this code + ;; is particularly ugly. This should ideally be moved to + ;; cconv--convert-function. + (pcase cif + (`#'(lambda () ,form) + (pcase-let ((`((,f1 . (,_ . ,f2)) . ,f3) bf)) + (setq bf `((,f1 . (,form . ,f2)) . ,f3))) + (setq cif nil)) + ('nil (setq bf nil)) + ;; The interactive form needs special treatment, so the form + ;; inside the `interactive' won't be used any further. + (_ (pcase-let ((`((,f1 . (,_ . ,f2)) . ,f3) bf)) + (setq bf `((,f1 . (nil . ,f2)) . ,f3))))) + (when bf + ;; If we modified bf, re-build body and form as + ;; copies with the modified bits. + (setq body (if (stringp (car body)) + (cons (car body) bf) + bf) + form `(function (lambda ,args . ,body) . ,rest)) + ;; Also, remove the current old entry on the alist, replacing + ;; it with the new one. + (let ((entry (pop cconv-freevars-alist))) + (push (cons body (cdr entry)) cconv-freevars-alist))) + (setq cf (cconv--convert-function args body env form docstring)) + (if (not cif) ;; Normal case, the interactive form needs no special treatment. cf [-- Attachment #2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply related [flat|nested] 10+ messages in thread
* bug#60974: 30.0.50; byte-compile-preprocess mutates self evaluating forms in expanded macro bodies 2023-02-01 7:41 ` Vibhav Pant @ 2023-02-01 14:33 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 2023-02-02 12:35 ` Vibhav Pant 0 siblings, 1 reply; 10+ messages in thread From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-02-01 14:33 UTC (permalink / raw) To: Vibhav Pant; +Cc: 60974, emacs-devel >> Yes, please, > Done, thoughts? I think we can go with that for now. I'll try to fix the todo at some point, but I'm short on time for now, Stefan ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: bug#60974: 30.0.50; byte-compile-preprocess mutates self evaluating forms in expanded macro bodies 2023-02-01 14:33 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-02-02 12:35 ` Vibhav Pant 2023-02-02 14:26 ` Eli Zaretskii 0 siblings, 1 reply; 10+ messages in thread From: Vibhav Pant @ 2023-02-02 12:35 UTC (permalink / raw) To: Stefan Monnier; +Cc: 60974, emacs-devel [-- Attachment #1: Type: text/plain, Size: 508 bytes --] On Wed, 2023-02-01 at 09:33 -0500, Stefan Monnier wrote: > > > Yes, please, > > Done, thoughts? > > I think we can go with that for now. I'll try to fix the todo at > some > point, but I'm short on time for now, > > > Stefan > Sure. Do we need to install this to the release branch? The bug doesn't really break anything AFAIK, so I dont think it's really a release blocker. -- 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] 10+ messages in thread
* Re: bug#60974: 30.0.50; byte-compile-preprocess mutates self evaluating forms in expanded macro bodies 2023-02-02 12:35 ` Vibhav Pant @ 2023-02-02 14:26 ` Eli Zaretskii 0 siblings, 0 replies; 10+ messages in thread From: Eli Zaretskii @ 2023-02-02 14:26 UTC (permalink / raw) To: Vibhav Pant; +Cc: monnier, 60974, emacs-devel > From: Vibhav Pant <vibhavp@gmail.com> > Cc: 60974@debbugs.gnu.org, emacs-devel <emacs-devel@gnu.org> > Date: Thu, 02 Feb 2023 18:05:13 +0530 > > Sure. Do we need to install this to the release branch? The bug doesn't > really break anything AFAIK, so I dont think it's really a release > blocker. In that case, please don't install on the release branch. ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-02-02 14:26 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <b979003119097f23f6b13d5bc4f561596cdb9704.camel@gmail.com> 2023-01-20 21:35 ` bug#60974: 30.0.50; byte-compile-preprocess mutates self evaluating forms in expanded macro bodies Vibhav Pant 2023-01-21 5:43 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 2023-01-27 12:44 ` Vibhav Pant 2023-01-28 23:10 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 2023-01-31 13:52 ` Vibhav Pant 2023-01-31 14:34 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 2023-02-01 7:41 ` Vibhav Pant 2023-02-01 14:33 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors 2023-02-02 12:35 ` Vibhav Pant 2023-02-02 14:26 ` Eli Zaretskii
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).