From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.devel Subject: Re: Bug#38708: eq vs eql in byte-compiled code Date: Wed, 1 Jan 2020 13:38:57 +0100 Message-ID: References: <8cd1b5b2-b94e-ce64-0d70-c1b8b012d685@cs.ucla.edu> Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_E93E5E59-F13B-48FA-8390-9D733BFE1865" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="89975"; mail-complaints-to="usenet@blaine.gmane.org" Cc: Pip Cet , Emacs developers To: Paul Eggert Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jan 01 13:39:35 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1imdHj-000NIi-Bd for ged-emacs-devel@m.gmane.org; Wed, 01 Jan 2020 13:39:35 +0100 Original-Received: from localhost ([::1]:58168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1imdHi-0005lg-7m for ged-emacs-devel@m.gmane.org; Wed, 01 Jan 2020 07:39:34 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51381) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1imdHW-0005lW-2l for emacs-devel@gnu.org; Wed, 01 Jan 2020 07:39:23 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1imdHU-0006KJ-L2 for emacs-devel@gnu.org; Wed, 01 Jan 2020 07:39:21 -0500 Original-Received: from mail1472c50.megamailservers.eu ([91.136.14.72]:59080 helo=mail102c50.megamailservers.eu) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1imdHP-0006CB-Re for emacs-devel@gnu.org; Wed, 01 Jan 2020 07:39:20 -0500 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1577882341; bh=tf7UeNUCjthmmv9Bq77tgPjqcYocGyL+zEUYL6KVs9w=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=GFpU9yw17o6Hml0m1fLY5a+0ypGAHX2nDuo384bHCc3gF1S2wGRWN1aie4+Vz2nOd pEhKzPJ09RbL4pkVkBIVGtrIsei1Xi7RAyHvU4al/A5mb/fJyOOPk1/LMaN0vsQ9ga cKPRo3Uth0LObVzYSyVRry2PnjFhW5yUgK/r5b4o= Feedback-ID: mattiase@acm.or Original-Received: from [192.168.0.4] (c188-150-171-71.bredband.comhem.se [188.150.171.71]) (authenticated bits=0) by mail102c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id 001Ccw9J011171; Wed, 1 Jan 2020 12:39:00 +0000 In-Reply-To: <8cd1b5b2-b94e-ce64-0d70-c1b8b012d685@cs.ucla.edu> X-Mailer: Apple Mail (2.3445.104.11) X-CTCH-RefID: str=0001.0A0B0205.5E0C92E5.0020, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-CSC: 0 X-CHA: v=2.3 cv=Q8qsHL+a c=1 sm=1 tr=0 a=SF+I6pRkHZhrawxbOkkvaA==:117 a=SF+I6pRkHZhrawxbOkkvaA==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=M51BFTxLslgA:10 a=5-41wYVo5RD_tHhxxh0A:9 a=CjuIK1q_8ugA:10 a=2tPwtGmRmW61so5VGrIA:9 a=B2y7HmGcmWMA:10 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.136.14.72 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:243830 Archived-At: --Apple-Mail=_E93E5E59-F13B-48FA-8390-9D733BFE1865 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 31 dec. 2019 kl. 18.38 skrev Paul Eggert : > One possible compromise would be to duplicate only bignums in the = emacs-27 > branch, while reserving flonum deduplication for the master branch. = This would > help a bit with now-incorrect code that uses eq to compare bignum = values, while > not introducing flonum "paradoxes". The flonum/bignum deduplication patch is only in master at this point. = If you think it emacs-27 would benefit from a version of it that = specifically excludes flonums, this could of course be arranged. In general, though, my impression is that the likelihood of any trouble = in practice is nil (speaking as the author of the change, of course). More important is how to present equality semantics to the user, through = documentation, NEWS, and examples. This includes: - What 'eq' can be used for: what we recommend, and what we guarantee. - Which equality relation to use and when: eq, eql, equal, =3D, = string-equal, etc. For example, while we have to guarantee that 'eq' works for fixnums for = compatibility, it may be unwise to give this fact prominence in the = documentation. One of the benefits of bignums is that users no longer = have to worry about fixnum ranges in most cases. The standard rule = should be not to use 'eq' for numbers of any kind. Whether to specifically mention characters as eq-comparable is a matter = of judgement. (Neither CL nor Scheme guarantee that characters can be = used with eq/eq?.) Of course my own code is littered with eq for = characters, but do as I say... Attached is a proposed documentation patch for emacs-27. While not = perfect, it should at least be an improvement (and fixes at least one = error). > How about going a bit further, and globally deduplicating all flonums = and > bignums that result from low-level text-to-number conversion and = module imports? > That conversion is slow and/or rare already, and if we're lucky = deduplication > wouldn't make things noticeably slower and wouldn't be much work. Maybe, but wouldn't that slow down reading .elc files (and still not = shorten individual constant vectors)? --Apple-Mail=_E93E5E59-F13B-48FA-8390-9D733BFE1865 Content-Disposition: attachment; filename=0001-Clarify-eq-on-numbers.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Clarify-eq-on-numbers.patch" Content-Transfer-Encoding: quoted-printable =46rom=20fdb4519ca621fbfd893f23f62ef0b97379f9c8a9=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Mattias=3D20Engdeg=3DC3=3DA5rd?=3D=20= =0ADate:=20Wed,=201=20Jan=202020=2013:06:39=20+0100=0A= Subject:=20[PATCH]=20Clarify=20'eq'=20on=20numbers=0A=0A*=20= doc/lispref/numbers.texi=20(Integer=20Basics):=0A*=20= doc/lispref/objects.texi=20(Integer=20Type,=20Equality=20Predicates):=0A= *=20etc/NEWS:=0A=0ARecommend=20that=20'eq'=20not=20be=20used=20to=20= compare=20numbers,=20and=20fix=20some=0Aerroneous=20or=20misleading=20= examples.=20=20See=20discussion=20starting=20at=0A= https://lists.gnu.org/archive/html/emacs-devel/2019-12/msg00856.html=0A= and=20bug#38708.=0A---=0A=20doc/lispref/numbers.texi=20|=20=202=20++=0A=20= doc/lispref/objects.texi=20|=2032=20+++++++++++++++++---------------=0A=20= etc/NEWS=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20|=20=203=20= ++-=0A=203=20files=20changed,=2021=20insertions(+),=2016=20deletions(-)=0A= =0Adiff=20--git=20a/doc/lispref/numbers.texi=20= b/doc/lispref/numbers.texi=0Aindex=20e952980f26..1c6f8ae7be=20100644=0A= ---=20a/doc/lispref/numbers.texi=0A+++=20b/doc/lispref/numbers.texi=0A@@=20= -41,6=20+41,8=20@@=20Integer=20Basics=0A=20Some=20functions=20in=20Emacs=20= accept=20only=20fixnums.=20=20Also,=20while=20fixnums=20can=0A=20always=20= be=20compared=20for=20numeric=20equality=20with=20@code{eq},=20bignums=0A= =20require=20more-heavyweight=20equality=20predicates=20like=20= @code{eql}.=0A+To=20avoid=20any=20concern=20about=20fixnum=20ranges,=20= use=20@code{eql}=20or=20@code{=3D}=0A+for=20comparing=20numbers.=0A=20=0A= =20=20=20The=20range=20of=20values=20for=20bignums=20is=20limited=20by=20= the=20amount=20of=20main=0A=20memory,=20by=20machine=20characteristics=20= such=20as=20the=20size=20of=20the=20word=20used=0Adiff=20--git=20= a/doc/lispref/objects.texi=20b/doc/lispref/objects.texi=0Aindex=20= 4be2eb6918..a0ce7aebd0=20100644=0A---=20a/doc/lispref/objects.texi=0A+++=20= b/doc/lispref/objects.texi=0A@@=20-270,7=20+270,9=20@@=20Integer=20Type=0A= =20@code{eql}=20or=20@code{=3D}.=20=20To=20test=20whether=20an=20integer=20= is=20a=20fixnum=20or=20a=0A=20bignum,=20you=20can=20compare=20it=20to=20= @code{most-negative-fixnum}=20and=0A=20@code{most-positive-fixnum},=20or=20= you=20can=20use=20the=20convenience=20predicates=0A-@code{fixnump}=20and=20= @code{bignump}=20on=20any=20object.=0A+@code{fixnump}=20and=20= @code{bignump}=20on=20any=20object.=20=20Most=20of=20the=20time,=0A= +however,=20it=20is=20more=20convenient=20to=20ignore=20the=20difference=20= and=20use=0A+@code{eql}=20or=20@code{=3D}=20for=20comparing=20any=20kind=20= of=20number.=0A=20=0A=20=20=20The=20read=20syntax=20for=20integers=20is=20= a=20sequence=20of=20(base=20ten)=20digits=20with=20an=0A=20optional=20= sign=20at=20the=20beginning=20and=20an=20optional=20period=20at=20the=20= end.=20=20The=0A@@=20-2167,19=20+2169,20=20@@=20Equality=20Predicates=0A=20= This=20function=20returns=20@code{t}=20if=20@var{object1}=20and=20= @var{object2}=20are=0A=20the=20same=20object,=20and=20@code{nil}=20= otherwise.=0A=20=0A-If=20@var{object1}=20and=20@var{object2}=20are=20= fixnums=20with=20the=20same=20value,=0A-they=20are=20considered=20to=20= be=20the=20same=20object=20(i.e.,=20@code{eq}=20returns=0A-@code{t}).=20=20= If=20@var{object1}=20and=20@var{object2}=20are=20symbols=20with=20the=0A= +Numbers=20in=20general=20do=20not=20have=20an=20object=20identity=20and=20= therefore=20cannot=0A+be=20compared=20reliably=20using=20@code{eq}.=20=20= While=20fixnums=20(and=20characters)=0A+with=20the=20same=20value=20are=20= considered=20to=20be=20the=20same=20object=20(i.e.,=0A+@code{eq}=20= returns=20@code{t}),=20this=20is=20not=20true=20for=20bignums=20and=20= floats.=0A+For=20maximum=20portability=20and=20robustness,=20avoid=20= using=20@code{eq}=20for=0A+numbers=20(@pxref{Comparison=20of=20= Numbers}).=0A+=0A+If=20@var{object1}=20and=20@var{object2}=20are=20= symbols=20with=20the=0A=20same=20name,=20they=20are=20normally=20the=20= same=20object---but=20see=20@ref{Creating=0A=20Symbols}=20for=20= exceptions.=20=20For=20other=20types=20(e.g.,=20lists,=20vectors,=0A=20= strings),=20two=20arguments=20with=20the=20same=20contents=20or=20= elements=20are=20not=0A=20necessarily=20@code{eq}=20to=20each=20other:=20= they=20are=20@code{eq}=20only=20if=20they=0A=20are=20the=20same=20= object,=20meaning=20that=20a=20change=20in=20the=20contents=20of=20one=20= will=0A=20be=20reflected=20by=20the=20same=20change=20in=20the=20= contents=20of=20the=20other.=0A-For=20other=20types=20of=20objects=20= whose=20contents=20cannot=20be=20changed=20(e.g.,=0A-bignums=20and=20= floats),=20two=20arguments=20with=20the=20same=20contents=20might=20or=20= might=20not=20be=0A-the=20same=20object,=20and=20@code{eq}=20returns=20= @code{t}=20or=20@code{nil}=0A-depending=20on=20whether=20the=20Lisp=20= interpreter=20created=20one=20object=20or=20two.=0A=20=0A=20@example=0A=20= @group=0A@@=20-2188,26=20+2191,25=20@@=20Equality=20Predicates=0A=20@end=20= group=0A=20=0A=20@group=0A-(eq=20456=20456)=0A+(eq=20?A=20?A)=0A=20=20=20= =20=20=20@result{}=20t=0A=20@end=20group=0A=20=0A=20@group=0A=20(eq=20= 3.0=203.0)=0A=20=20=20=20=20=20@result{}=20t=20@r{or}=20nil=0A-;;=20= @r{The=20result=20is=20implementation-dependent.}=0A+;;=20@r{Equal=20= floats=20may=20or=20may=20not=20be=20the=20same=20object.}=0A=20@end=20= group=0A=20=0A=20@group=0A-(eq=20"asdf"=20"asdf")=0A+(eq=20(make-string=20= 3=20?A)=20(make-string=203=20?A))=0A=20=20=20=20=20=20@result{}=20nil=0A=20= @end=20group=0A=20=0A=20@group=0A-(eq=20""=20"")=0A-=20=20=20=20=20= @result{}=20t=0A-;;=20@r{This=20exception=20occurs=20because=20Emacs=20= Lisp}=0A-;;=20@r{makes=20just=20one=20multibyte=20empty=20string,=20to=20= save=20space.}=0A+(eq=20"asdf"=20"asdf")=0A+=20=20=20=20=20@result{}=20t=20= @r{or}=20nil=0A+;;=20@r{Equal=20string=20constants=20may=20or=20may=20= not=20be=20the=20same=20object.}=0A=20@end=20group=0A=20=0A=20@group=0A= diff=20--git=20a/etc/NEWS=20b/etc/NEWS=0Aindex=20a8c8e2763e..efcd63e35c=20= 100644=0A---=20a/etc/NEWS=0A+++=20b/etc/NEWS=0A@@=20-2879,7=20+2879,8=20= @@=20All=20the=20arithmetic,=20comparison,=20and=20logical=20(a.k.a.=20= "bitwise")=0A=20operations=20where=20bignums=20make=20sense=20now=20= support=20both=20fixnums=20and=0A=20bignums.=20=20However,=20note=20that=20= unlike=20fixnums,=20bignums=20will=20not=20compare=0A=20equal=20with=20= 'eq',=20you=20must=20use=20'eql'=20instead.=20=20(Numerical=20comparison=0A= -with=20'=3D'=20works=20on=20both,=20of=20course.)=0A+with=20'=3D'=20= works=20on=20both,=20of=20course.)=20=20To=20avoid=20mistakes,=20we=20= recommend=0A+that=20you=20do=20not=20use=20'eq'=20for=20comparing=20= numbers=20at=20all.=0A=20=0A=20Since=20large=20bignums=20consume=20a=20= lot=20of=20memory,=20Emacs=20limits=20the=20size=20of=0A=20the=20largest=20= bignum=20a=20Lisp=20program=20is=20allowed=20to=20create.=20=20The=0A--=20= =0A2.21.0=20(Apple=20Git-122.2)=0A=0A= --Apple-Mail=_E93E5E59-F13B-48FA-8390-9D733BFE1865--