From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Aliasing EQ to EQL (was: [RFC PATCH] Per-window face support) Date: Sun, 17 Jun 2018 18:25:00 -0400 Message-ID: References: <5e08587a56ad528599ed5fb259be6335.squirrel@dancol.org> <83muw5vdtr.fsf@gnu.org> <83zhzvyqfy.fsf@gnu.org> <83lgbezs6q.fsf@gnu.org> <6b522145569975d52266e29e8122e86b.squirrel@dancol.org> <50a1e0f98f6cfc5e55fdc2b7df5000b5.squirrel@dancol.org> <49478aa579597ea6557a3976779a234a.squirrel@dancol.org> <1c706afb-47c7-a8a7-3d3c-d4c8ea95cf70@cs.ucla.edu> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1529274196 1852 195.159.176.226 (17 Jun 2018 22:23:16 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 17 Jun 2018 22:23:16 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jun 18 00:23:12 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fUg4l-0000NQ-PB for ged-emacs-devel@m.gmane.org; Mon, 18 Jun 2018 00:23:12 +0200 Original-Received: from localhost ([::1]:56601 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUg6s-0000Vh-N2 for ged-emacs-devel@m.gmane.org; Sun, 17 Jun 2018 18:25:22 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40458) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUg6l-0000VU-6N for emacs-devel@gnu.org; Sun, 17 Jun 2018 18:25:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fUg6f-0000er-Tl for emacs-devel@gnu.org; Sun, 17 Jun 2018 18:25:15 -0400 Original-Received: from [195.159.176.226] (port=59229 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fUg6f-0000cJ-LU for emacs-devel@gnu.org; Sun, 17 Jun 2018 18:25:09 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1fUg4V-0008W3-F4 for emacs-devel@gnu.org; Mon, 18 Jun 2018 00:22:55 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 128 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:942gA1OtVuipYRWa+3eghWGvAuQ= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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:226442 Archived-At: >> Getting rid of `eq' is just lying to programmers about object identity. > > I don't see how it would be lying to equate eq and eql for numbers. An > object's identity is not the same thing as a machine-level address, and > whether two instances of the same number are eq is an implementation detail > that Lisp programmers should not rely upon. > > This doesn't mean that we should equate eq and eql. Perhaps there are good > efficiency reasons to continue to distinguish them. But these would be > merely pragmatic, not philosophical. BTW, if someone is tempted to measure the impact, here's the naive patch I've been using recently. It doesn't try to be clever: other than NILP, all uses of EQ are changed to use EQL. Clearly, we could improve on that, but I think such improvements should be "profile-guided". In terms of code size it added 100KB (out of a 4MB stripped binary, so about 0.25%) which is not insignificant, but is a cost I'm willing to live with. Stefan diff --git a/src/fns.c b/src/fns.c index de1dad3736..11709ae266 100644 --- a/src/fns.c +++ b/src/fns.c @@ -2108,10 +2108,7 @@ DEFUN ("eql", Feql, Seql, 2, 2, 0, Floating-point numbers of equal value are `eql', but they may not be `eq'. */) (Lisp_Object obj1, Lisp_Object obj2) { - if (FLOATP (obj1)) - return equal_no_quit (obj1, obj2) ? Qt : Qnil; - else - return EQ (obj1, obj2) ? Qt : Qnil; + return EQL (obj1, obj2) ? Qt : Qnil; } DEFUN ("equal", Fequal, Sequal, 2, 2, 0, @@ -2192,7 +2189,7 @@ internal_equal (Lisp_Object o1, Lisp_Object o2, enum equal_kind equal_kind, } } - if (EQ (o1, o2)) + if (lisp_h_EQ (o1, o2)) return true; if (XTYPE (o1) != XTYPE (o2)) return false; @@ -3684,7 +3681,7 @@ cmpfn_user_defined (struct hash_table_test *ht, in a Lisp integer. */ static EMACS_UINT -hashfn_eq (struct hash_table_test *ht, Lisp_Object key) +hashfn__eq (struct hash_table_test *ht, Lisp_Object key) { return XHASH (key) ^ XTYPE (key); } @@ -3706,7 +3703,13 @@ hashfn_equal (struct hash_table_test *ht, Lisp_Object key) static EMACS_UINT hashfn_eql (struct hash_table_test *ht, Lisp_Object key) { - return FLOATP (key) ? hashfn_equal (ht, key) : hashfn_eq (ht, key); + return FLOATP (key) ? hashfn_equal (ht, key) : hashfn__eq (ht, key); +} + +static EMACS_UINT +hashfn_eq (struct hash_table_test *ht, Lisp_Object key) +{ + return hashfn_eql (ht, key); } /* Value is a hash code for KEY for use in hash table H which uses as diff --git a/src/lisp.h b/src/lisp.h index 56ad8b814b..e3b2cd9cf0 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -322,7 +322,7 @@ error !; #define lisp_h_INTEGERP(x) ((XTYPE (x) & (Lisp_Int0 | ~Lisp_Int1)) == Lisp_Int0) #define lisp_h_MARKERP(x) (MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Marker) #define lisp_h_MISCP(x) (XTYPE (x) == Lisp_Misc) -#define lisp_h_NILP(x) EQ (x, Qnil) +#define lisp_h_NILP(x) lisp_h_EQ (x, Qnil) #define lisp_h_SET_SYMBOL_VAL(sym, v) \ (eassert ((sym)->u.s.redirect == SYMBOL_PLAINVAL), \ (sym)->u.s.val.value = (v)) @@ -374,7 +374,7 @@ error !; # define CHECK_SYMBOL(x) lisp_h_CHECK_SYMBOL (x) # define CHECK_TYPE(ok, predicate, x) lisp_h_CHECK_TYPE (ok, predicate, x) # define CONSP(x) lisp_h_CONSP (x) -# define EQ(x, y) lisp_h_EQ (x, y) +# define EQ(x, y) EQL (x, y) # define FLOATP(x) lisp_h_FLOATP (x) # define INTEGERP(x) lisp_h_INTEGERP (x) # define MARKERP(x) lisp_h_MARKERP (x) @@ -1040,10 +1040,21 @@ make_natnum (EMACS_INT n) /* Return true if X and Y are the same object. */ +extern bool equal_no_quit (Lisp_Object o1, Lisp_Object o2); + +INLINE bool +EQL (Lisp_Object x, Lisp_Object y) +{ + if (lisp_h_FLOATP (x)) + return equal_no_quit (x, y); + else + return lisp_h_EQ (x, y); +} + INLINE bool (EQ) (Lisp_Object x, Lisp_Object y) { - return lisp_h_EQ (x, y); + return EQL (x, y); } /* True if the possibly-unsigned integer I doesn't fit in a Lisp fixnum. */ @@ -3432,7 +3443,6 @@ extern Lisp_Object merge (Lisp_Object, Lisp_Object, Lisp_Object); extern Lisp_Object do_yes_or_no_p (Lisp_Object); extern Lisp_Object concat2 (Lisp_Object, Lisp_Object); extern Lisp_Object concat3 (Lisp_Object, Lisp_Object, Lisp_Object); -extern bool equal_no_quit (Lisp_Object, Lisp_Object); extern Lisp_Object nconc2 (Lisp_Object, Lisp_Object); extern Lisp_Object assq_no_quit (Lisp_Object, Lisp_Object); extern Lisp_Object assoc_no_quit (Lisp_Object, Lisp_Object);