all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tom Gillespie <tgbugs@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Lars Ingebrigtsen <larsi@gnus.org>, 55645@debbugs.gnu.org
Subject: bug#55645: src/print.c; print_object changes make it impossible to compare elisp code across versions
Date: Sun, 29 May 2022 14:03:11 -0700	[thread overview]
Message-ID: <CA+G3_PNrEEZmV+ECGG9Ukp4MpRBT4WxBhujudM5TcsG3Axr6FQ@mail.gmail.com> (raw)
In-Reply-To: <83v8tojrr5.fsf@gnu.org>

Hi Eli,
  I have included an example below, with some additional context. Best!
Tom

I'm using my own use case as an example, but I suspect that there are
other users out there who may have similar use cases where stability
of the printed representation of read code is important.

Some examples from a quick search on github that will or could be
affected by this (beyond my own). I only searched for cases matching
my own involving secure-hash and prin1-to-string, but there are surely
other cases that would be affected that I have not imagined.
https://github.com/skeeto/elfeed/blob/162d7d545ed41c27967d108c04aa31f5a61c8e16/web/elfeed-web.el#L73-L75
https://github.com/mrmekon/snitch-el/blob/3b3e7f1bf612c4624764d1ec4b1a96e4d2850b05/snitch-timer.el#L164-L181
https://github.com/radian-software/straight.el/blob/af5437f2afd00936c883124d6d3098721c2d306c/straight.el#L5627

https://github.com/search?q=prin1-to-string+secure-hash&type=Code
You can filter out some of the noise by adding the follow to the search
-elfeed -orgstrap -quelpa -litable -xah-elisp-mode -subr.el

The use case that I have is to store the checksum of a code block to
make sure that it has not changed. The checksum needs to be invariant
to changes in formatting e.g. whitespace and needs to be backward and
forward compatible across Emacs versions. In order to compute the
checksum I need a serialized representation of the code. Note when I
say "compare" two pieces of elisp code, one of them may no longer be
available to be read, because only a checksum was retained, so direct
comparison of the two structures in memory is not possible and defeats
the point of having something that is simple to audit and store.

This is discussed in more detail in the orgstrap readme.
https://github.com/tgbugs/orgstrap/blob/master/README.org#normalization-functions
https://github.com/tgbugs/orgstrap/blob/master/README.org#specification

From Emacs 18 through 28 prin1-to-string and the existing print
variables have been able to provide the needed stability.

There is currently no way to compensate for the change introduced in
637dde4aba921435f78d0de769ad74c4f3230aa6 short of reimplementing the
old behavior of prin1-to-string from scratch, which would ultimately
increase the maintenance load across the whole community.

The example below works on emacs-18 (had to remove the number 1.0
example because emacs 18 does not have support for reading floats).

The output of this code is unchanged from emacs-18 through emacs-28,
however it is now different in emacs-29.
Emacs 18-28:
"(progn (+ 1 2) (a b\\.c d) (defun hello nil world)) (progn (some
elisp code I want to normalize\\. That has strings \"1.0\" and symbols
a\\.b))"
Emacs 29:
"(progn (+ 1 2) (a b.c d) (defun hello nil world)) (progn (some elisp
code I want to normalize. That has strings \"1.0\" and symbols a.b))"

#+begin_src elisp :tangle /tmp/example.el
(defun normalize-elisp-code (body)
  (let (print-quoted print-length print-level) ; proposed variable
would be added here
    (prin1-to-string (read (concat "(progn\n" body "\n)")))))

(defvar example-body-1 "(+ 1 2) (a b\\.c d) (defun hello () world)")
(defvar example-body-2 (prin1-to-string '(some elisp code I want to
normalize\. That has strings "1.0" and symbols a\.b)))
(message "%s %s"
         (normalize-elisp-code example-body-1)
         (normalize-elisp-code example-body-2))
#+end_src

The additional step in my use case is the checksum, which cannot be
read back in, and changes from 28 -> 29 due to the differences in the
output of prin1-to-string seen above.

#+begin_src elisp
(defun checksum-elisp-code (body)
  (secure-hash 'sha256 (normalize-elisp-code body)))

(message "%s %s"
         (checksum-elisp-code example-body-1)
         (checksum-elisp-code example-body-2))
#+end_src





  reply	other threads:[~2022-05-29 21:03 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-25 23:12 bug#55645: src/print.c; print_object changes make it impossible to compare elisp code across versions Tom Gillespie
2022-05-26 12:03 ` Lars Ingebrigtsen
2022-05-26 15:56   ` Tom Gillespie
2022-05-27 10:33     ` Lars Ingebrigtsen
2022-05-27 19:19       ` Tom Gillespie
2022-05-28 10:39         ` Lars Ingebrigtsen
2022-05-28 17:54           ` Tom Gillespie
2022-05-29 13:15             ` Lars Ingebrigtsen
2022-05-29 15:14               ` Eli Zaretskii
2022-05-29 21:03                 ` Tom Gillespie [this message]
2022-06-04  9:15                   ` Eli Zaretskii
2022-06-04 11:35                     ` Lars Ingebrigtsen
2022-06-04 11:53                       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-06-04 12:09                         ` Lars Ingebrigtsen
2022-06-04 12:18                           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-06-04 13:14                             ` Lars Ingebrigtsen
2022-06-04 13:30                               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-06-04 13:35                                 ` Lars Ingebrigtsen
2022-06-04 13:47                                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-06-06 23:30                     ` Tom Gillespie
2022-06-07 16:35                       ` Eli Zaretskii
2022-07-11 11:22                         ` Lars Ingebrigtsen
2022-07-11 18:43                           ` Tom Gillespie
2022-07-12 12:44                             ` Lars Ingebrigtsen
2022-07-13 23:26                               ` Tom Gillespie
2022-07-14 17:22                                 ` Lars Ingebrigtsen
2022-07-14 21:36                                   ` Tom Gillespie
2022-07-18 18:13                                     ` Tom Gillespie
2022-07-12  3:04                           ` Richard Stallman
2022-07-12 12:45                             ` Lars Ingebrigtsen
2022-07-13  3:16                               ` Richard Stallman
2022-05-28 23:14         ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CA+G3_PNrEEZmV+ECGG9Ukp4MpRBT4WxBhujudM5TcsG3Axr6FQ@mail.gmail.com \
    --to=tgbugs@gmail.com \
    --cc=55645@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.