all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#67116: byte-compile-let: reversing the order of evaluation of the clauses CAN make a difference.
@ 2023-11-11 22:48 Alan Mackenzie
  2023-11-12  4:52 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-11-12 14:21 ` Mattias Engdegård
  0 siblings, 2 replies; 13+ messages in thread
From: Alan Mackenzie @ 2023-11-11 22:48 UTC (permalink / raw)
  To: 67116; +Cc: Stefan Monnier

Hello, Emacs.

Emacs master branch.

In lisp/emacs-lisp/bytecomp.el (byte-compile-let), when the following
form (from jit-lock--debug-fontify):

                          (let
                              ((beg pos)
                                (end (setq pos
                                               (next-single-property-change
                                                pos 'fontified
                                                nil (point-max)))))
                            (put-text-property beg end 'fontified nil)
                            (jit-lock-fontify-now beg end))

gets byte compiled, the order of evaluating BEG and END gets reversed so
that END gets evaluated first.  Since the value for END contains (setq
pos ...), BEG gets this updated value of POS rather then the original
intended value.

This particular bug in jit-lock.el can be fixed by using let* rather
than let, but this isn't the point.  I believe (without testing) that
the interpreted code for the form would evaluate BEG before END, hence
testing it interpreted (e.g. under edebug) will give a false sense of
correctness.

The comment in byte-compile-let:

      ;; Bind the variables.
      ;; For `let', do it in reverse order, because it makes no
      ;; semantic difference, but it is a lot more efficient since the
      ;; values are now in reverse order on the stack.

, is not true.  It can make a semantic difference.  So doing the binding
in reverse order is a bug.

-- 
Alan Mackenzie (Nuremberg, Germany).





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

end of thread, other threads:[~2023-11-14  2:56 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-11 22:48 bug#67116: byte-compile-let: reversing the order of evaluation of the clauses CAN make a difference Alan Mackenzie
2023-11-12  4:52 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-12  6:13   ` Eli Zaretskii
2023-11-12 14:22     ` Alan Mackenzie
2023-11-12 19:32       ` Drew Adams
2023-11-14  2:56         ` Richard Stallman
2023-11-12 16:49     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-12 14:54   ` Alan Mackenzie
2023-11-12 17:06     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-12 14:21 ` Mattias Engdegård
2023-11-12 14:41   ` Mattias Engdegård
2023-11-13 11:19     ` Mattias Engdegård
2023-11-13 13:14       ` Alan Mackenzie

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.