Subject: Re: bug#31688: 26.1.50; Byte compiler confuses two string variables

From: Noam Postavsky <[email-masked]>
Date: Sat, 02 Jun 2018 19:54:40 -0400

Phil Sainty <[email-masked]> writes:

> On 2018-06-03 06:02, Noam Postavsky wrote:
>> I don't think this is a bug, the compiler coalesces equal string
>> literals.
>
> Ouch.  Has this always been the case?  I've been firmly under the
> impression that the lisp reader creates a new lisp objects whenever
> it reads a string,

Strictly speaking, that is correct.  The reader does that.  The byte
compiler doesn't preserve the object identity.

(byte-compile (lambda () (let ((str1 "abc")
                               (str2 "abc"))
                           (eq str1 str2))))
;=> #[0 "<bytecode>" ["abc"] 4]

> But this is nil regardless:
>
> (eq "abc" "abc")

Oh, looks like the compiler performs the `eq' call at compile time.

(byte-compile (lambda () (eq "abc" "abc")))
;=> #[0 "\300\207" [nil] 1]

> This seems kinda horrible?

What, you don't like optimization? ;)