Subject: bug#21237: 25.0.50; defconst vs dump

From: Lars Ingebrigtsen <[email-masked]>
Date: Wed, 09 Oct 2019 06:34:31 +0200

[email-masked] writes:

> Given these two definitions:
>
> (defconst format-1
>   (let ((str "(%s %s)"))
>     (put-text-property 1 3 'face 'font-lock-keyword-face str)
>     (put-text-property 4 6 'face 'font-lock-function-name-face str)
>     str))
>
> (defvar format-2
>   (let ((str "(%s %s %s)"))
>     (put-text-property 1 3 'face 'font-lock-keyword-face str)
>     (put-text-property 4 6 'face 'font-lock-function-name-face str)
>     str))
>
> If I byte-compile a file containing these, and later load that
> byte-compiled file, the text properties are present on both format-1 and
> format-2.
>
> However, if the file is dumped for preloading into emacs, then the text
> properties are not present on format-1; the defconst apparently causes
> them to disappear.

I can confirm that this is still the case in Emacs 27.

> If this is desired/intended behavior, it should be documented in the
> defconst doc string, and there should be a warning during the dump
> process.

I tried looking around in the code a bit, but I don't really know what
to look for.

Does anybody know whether this behaviour is intended?  It seems odd that
defvars and defconsts are handled differently here.

Hm...  Oh!  Here's from defconst:

  if (!NILP (Vpurify_flag))
    tem = Fpurecopy (tem);

and purecopy:

purecopy (Lisp_Object obj)
{
  if (FIXNUMP (obj)
      || (! SYMBOLP (obj) && PURE_P (XPNTR (obj)))
      || SUBRP (obj))
    return obj;    /* Already pure.  */

  if (STRINGP (obj) && XSTRING (obj)->u.s.intervals)
    message_with_string ("Dropping text-properties while making string `%s' pure",
			 obj, true);

And, indeed, I get

Dropping text-properties while making string `(%s %s)' pure

when compiling.  (Side issue: Should that have a "Warning: " prefix or
something so that it gets more noticeable?)

So I guess this is intended behaviour?  I guess it's too obscure a thing
to put in the doc string of defconst.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no