bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Noam Postavsky
Subject: bug#31688: 26.1.50; Byte compiler confuses two string variables
Date: Sat, 02 Jun 2018 19:54:40 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

Phil Sainty <psainty@orcon.net.nz> 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? ;)






reply via email to

[Prev in Thread] Current Thread [Next in Thread]