all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Basil L. Contovounesios" <contovob@tcd.ie>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: Predicate for true lists
Date: Tue, 09 Apr 2019 17:20:00 +0100	[thread overview]
Message-ID: <87mukzb173.fsf@tcd.ie> (raw)
In-Reply-To: <jwv36mrtcyv.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Tue, 9 Apr 2019 11:33:59 -0400")

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: 0001-Optimize-byte-compilation-of-proper-list-p.patch --]
[-- Type: text/x-diff, Size: 1888 bytes --]

From 430fcb473608a4501826a982a29efa8c31ed6c5c Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <contovob@tcd.ie>
Date: Tue, 9 Apr 2019 16:51:55 +0100
Subject: [PATCH 1/2] Optimize byte-compilation of proper-list-p

* lisp/emacs-lisp/byte-opt.el: Optimize proper-list-p as a
predicate.
* src/fns.c (syms_of_fns): Mark proper-list-p as pure and
side-effect-free.
---
 lisp/emacs-lisp/byte-opt.el | 3 ++-
 src/fns.c                   | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
index 33d4964763..44cca6136c 100644
--- a/lisp/emacs-lisp/byte-opt.el
+++ b/lisp/emacs-lisp/byte-opt.el
@@ -879,7 +879,8 @@ byte-optimize-memq
 (put 'symbolp 'byte-optimizer 'byte-optimize-predicate)
 (put 'stringp 'byte-optimizer 'byte-optimize-predicate)
 (put 'string< 'byte-optimizer 'byte-optimize-predicate)
-(put 'string-lessp 'byte-optimizer 'byte-optimize-predicate)
+(put 'string-lessp  'byte-optimizer 'byte-optimize-predicate)
+(put 'proper-list-p 'byte-optimizer 'byte-optimize-predicate)
 
 (put 'logand 'byte-optimizer 'byte-optimize-predicate)
 (put 'logior 'byte-optimizer 'byte-optimize-predicate)
diff --git a/src/fns.c b/src/fns.c
index c3202495da..c840019456 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -5326,6 +5326,12 @@ syms_of_fns (void)
   DEFSYM (Qcursor_in_echo_area, "cursor-in-echo-area");
   DEFSYM (Qwidget_type, "widget-type");
 
+  DEFSYM (Qpure, "pure");
+  DEFSYM (Qside_effect_free, "side-effect-free");
+  DEFSYM (Qproper_list_p, "proper-list-p");
+  Fput (Qproper_list_p, Qpure, Qt);
+  Fput (Qproper_list_p, Qside_effect_free, Qt);
+
   DEFVAR_LISP ("overriding-plist-environment", Voverriding_plist_environment,
                doc: /* An alist that overrides the plists of the symbols which it lists.
 Used by the byte-compiler to apply `define-symbol-prop' during
-- 
2.20.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-Move-proper-list-p-tests-to-fns-tests.el.patch --]
[-- Type: text/x-diff, Size: 2750 bytes --]

From 82399337d891f8c078b78f0de013ba240d1fc236 Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <contovob@tcd.ie>
Date: Tue, 9 Apr 2019 17:05:27 +0100
Subject: [PATCH 2/2] Move proper-list-p tests to fns-tests.el

This follows the move of proper-list-p from lisp/subr.el to
src/fns.c in 2018-07-24T15:58:46-07:00!eggert@cs.ucla.edu.
* test/lisp/subr-tests.el (subr-tests--proper-list-p): Move from
here...
* test/src/fns-tests.el (test-proper-list-p): ...to here.
---
 test/lisp/subr-tests.el | 18 ------------------
 test/src/fns-tests.el   | 18 ++++++++++++++++++
 2 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index 7465aac5ea..c458eef2f9 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -318,24 +318,6 @@ subr-test--frames-1
   (should (eq (string-to-char (symbol-name (gensym))) ?g))
   (should (eq (string-to-char (symbol-name (gensym "X"))) ?X)))
 
-(ert-deftest subr-tests--proper-list-p ()
-  "Test `proper-list-p' behavior."
-  (dotimes (length 4)
-    ;; Proper and dotted lists.
-    (let ((list (make-list length 0)))
-      (should (= (proper-list-p list) length))
-      (should (not (proper-list-p (nconc list 0)))))
-    ;; Circular lists.
-    (dotimes (n (1+ length))
-      (let ((circle (make-list (1+ length) 0)))
-        (should (not (proper-list-p (nconc circle (nthcdr n circle))))))))
-  ;; Atoms.
-  (should (not (proper-list-p 0)))
-  (should (not (proper-list-p "")))
-  (should (not (proper-list-p [])))
-  (should (not (proper-list-p (make-bool-vector 0 nil))))
-  (should (not (proper-list-p (make-symbol "a")))))
-
 (ert-deftest subr-tests--assq-delete-all ()
   "Test `assq-delete-all' behavior."
   (cl-flet ((new-list-fn
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el
index d6cc99e8e3..6ebab4287f 100644
--- a/test/src/fns-tests.el
+++ b/test/src/fns-tests.el
@@ -648,4 +648,22 @@ dot2
           (should (equal (list (eq a b) n len)
                          (list t n len))))))))
 
+(ert-deftest test-proper-list-p ()
+  "Test `proper-list-p' behavior."
+  (dotimes (length 4)
+    ;; Proper and dotted lists.
+    (let ((list (make-list length 0)))
+      (should (= (proper-list-p list) length))
+      (should (not (proper-list-p (nconc list 0)))))
+    ;; Circular lists.
+    (dotimes (n (1+ length))
+      (let ((circle (make-list (1+ length) 0)))
+        (should (not (proper-list-p (nconc circle (nthcdr n circle))))))))
+  ;; Atoms.
+  (should (not (proper-list-p 0)))
+  (should (not (proper-list-p "")))
+  (should (not (proper-list-p [])))
+  (should (not (proper-list-p (make-bool-vector 0 nil))))
+  (should (not (proper-list-p (make-symbol "a")))))
+
 (provide 'fns-tests)
-- 
2.20.1


[-- Attachment #3: Type: text/plain, Size: 1792 bytes --]


Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> @@ -1160,8 +1161,8 @@ byte-optimize-set
>>  	 make-list make-string make-symbol marker-buffer max member memq min
>>  	 minibuffer-selected-window minibuffer-window
>>  	 mod multibyte-char-to-unibyte next-window nth nthcdr number-to-string
>> -	 parse-colon-path plist-get plist-member
>> -	 prefix-numeric-value previous-window prin1-to-string propertize
>> +         parse-colon-path plist-get plist-member prefix-numeric-value
>> +         previous-window prin1-to-string proper-list-p propertize
>>  	 degrees-to-radians
>>  	 radians-to-degrees rassq rassoc read-from-string regexp-quote
>>  	 region-beginning region-end reverse round
>
> I think it'd be better to add a `side-effect-free` property rather than
> add to this list.  We should be moving away from having this list in
> byte-opt.el since that info can also be used when byte-opt is not
> loaded.

Makes sense, how's the attached?  Is there a better place to do this
than in syms_of_fns?  (I followed the example in src/json.c.)

>> diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
>> index 8bbe6292d9..0e953dc96b 100644
>> --- a/lisp/emacs-lisp/bytecomp.el
>> +++ b/lisp/emacs-lisp/bytecomp.el
>> @@ -3566,6 +3566,7 @@ byte-defop-compiler-1
>>  
>>  ;;####(byte-defop-compiler move-to-column	1)
>>  (byte-defop-compiler-1 interactive byte-compile-noop)
>> +(byte-defop-compiler-1 proper-list-p 1)
>
> I don't think this is needed.

Right.  For some reason the byte-compiler wasn't complaining about wrong
numbers of arguments without this compiler-form, but I can no longer
reproduce that.

I also attach a second patch which moves the proper-list-p tests to the
correct file following the function's rewriting in C.  WDYT?

Thanks,

-- 
Basil

  reply	other threads:[~2019-04-09 16:20 UTC|newest]

Thread overview: 100+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-16 19:34 Predicate for true lists Basil L. Contovounesios
2018-06-04 12:12 ` Basil L. Contovounesios
2018-06-04 14:08   ` Stefan Monnier
2018-06-04 14:46     ` Basil L. Contovounesios
2018-06-04 15:31       ` Drew Adams
2018-06-04 16:14         ` Basil L. Contovounesios
2018-06-04 16:38           ` Drew Adams
2018-06-04 16:57             ` Stefan Monnier
2018-06-05  1:23   ` Paul Eggert
2018-06-05  2:57     ` Drew Adams
2018-06-05  3:08       ` Drew Adams
2018-06-05  3:12         ` Drew Adams
2018-06-05  3:25       ` Drew Adams
2018-06-05 15:05     ` Basil L. Contovounesios
2018-06-06  7:42       ` Paul Eggert
2018-06-06  9:40         ` Van L
2018-06-06 13:44           ` Stefan Monnier
2018-06-06 17:40             ` Stefan Monnier
2018-06-07  7:03             ` Van L
2018-07-05 22:31         ` Basil L. Contovounesios
2018-07-06  5:57           ` Eli Zaretskii
2018-07-06 17:16             ` Drew Adams
2018-07-06 17:38               ` Eli Zaretskii
     [not found]               ` <<83601sl0wo.fsf@gnu.org>
2018-07-06 18:00                 ` Drew Adams
2018-07-07  6:54                   ` Eli Zaretskii
     [not found]               ` <<<83601sl0wo.fsf@gnu.org>
     [not found]                 ` <<95fda70b-5893-4788-83c5-a0bb5d708304@default>
     [not found]                   ` <<8336wvleml.fsf@gnu.org>
2018-07-07 14:42                     ` Drew Adams
2018-07-06 18:04             ` Paul Eggert
2018-07-07  6:58               ` Eli Zaretskii
2018-07-07  7:20                 ` martin rudalics
2018-07-07  8:41                 ` Paul Eggert
2018-07-07 10:04                   ` Eli Zaretskii
2018-07-07 15:04                     ` Basil L. Contovounesios
2018-07-07 16:12                       ` Eli Zaretskii
2018-07-07 16:52                         ` Basil L. Contovounesios
2018-07-07 17:07                           ` Eli Zaretskii
2018-07-07 17:14                             ` Paul Eggert
2018-07-07 17:34                               ` Eli Zaretskii
2018-07-08  0:15                               ` Drew Adams
2018-07-08  4:48                                 ` Paul Eggert
2018-07-08 15:15                                   ` Drew Adams
2018-07-08 16:00                                     ` Paul Eggert
2018-07-08 17:42                                       ` Drew Adams
2018-07-08 17:47                                         ` Paul Eggert
2018-07-07 17:06                     ` Basil L. Contovounesios
2018-07-09 19:25             ` Basil L. Contovounesios
2018-07-09 19:40               ` Basil L. Contovounesios
2018-07-10  2:02                 ` Paul Eggert
2018-07-10  5:46                   ` Basil L. Contovounesios
2018-07-11  3:02                     ` Paul Eggert
2018-07-11  6:27                       ` Basil L. Contovounesios
2018-07-15 22:55                         ` Wilfred Hughes
2018-07-16  1:37                           ` Paul Eggert
2018-07-11 14:01                       ` [Emacs-diffs] master babe0d4: Rearrange definition of zerop in subr.el Karl Fogel
2018-07-11 17:12                         ` Basil L. Contovounesios
2018-07-11 17:33                           ` Paul Eggert
2018-07-12 15:34                             ` Basil L. Contovounesios
2018-07-12 15:43                               ` Basil L. Contovounesios
2019-04-09 12:51                       ` Predicate for true lists Basil L. Contovounesios
2019-04-09 15:33                         ` Stefan Monnier
2019-04-09 16:20                           ` Basil L. Contovounesios [this message]
2019-04-09 16:32                             ` Stefan Monnier
2019-04-09 16:54                               ` Daniel Colascione
2019-04-09 17:27                                 ` Basil L. Contovounesios
2019-04-09 17:27                               ` Basil L. Contovounesios
2019-04-09 20:08                               ` Unused value of error-free function warning (was: Predicate for true lists) Basil L. Contovounesios
2019-04-09 20:40                                 ` Unused value of error-free function warning Stefan Monnier
2019-04-09 20:12                           ` Predicate for true lists Basil L. Contovounesios
2019-04-09 20:41                             ` Stefan Monnier
2019-04-10  2:32                             ` Eli Zaretskii
2019-04-10 14:16                               ` Alex Branham
2019-04-10 14:34                                 ` Basil L. Contovounesios
2019-04-10 15:01                                   ` Drew Adams
2019-04-10 15:45                                     ` Basil L. Contovounesios
2019-04-10 16:04                                       ` Eli Zaretskii
2019-04-17 17:56                                       ` Basil L. Contovounesios
2019-04-17 18:11                                         ` Stefan Monnier
2019-04-21 21:42                                           ` Basil L. Contovounesios
2019-04-17 18:55                                         ` Drew Adams
2019-04-21 21:24                                           ` Basil L. Contovounesios
2019-04-22  0:03                                             ` Drew Adams
2019-04-22  1:12                                               ` Michael Heerdegen
2019-04-22  9:39                                                 ` Drew Adams
2019-04-18 14:37                                         ` Eli Zaretskii
2019-04-21 18:30                                           ` Basil L. Contovounesios
2019-04-21 19:39                                             ` Eli Zaretskii
2019-04-21 21:37                                               ` Basil L. Contovounesios
2019-04-22  0:06                                                 ` Drew Adams
2019-04-22  7:49                                                 ` Eli Zaretskii
2019-04-22 12:59                                                   ` Basil L. Contovounesios
2019-04-22 13:12                                                     ` Eli Zaretskii
2019-04-22 15:19                                                       ` Basil L. Contovounesios
2019-04-21 19:41                                             ` Eli Zaretskii
2019-04-21 21:41                                               ` Basil L. Contovounesios
2019-04-22  6:39                                                 ` Eli Zaretskii
2019-04-22 12:58                                                   ` Basil L. Contovounesios
2018-07-06 17:00           ` Drew Adams
2018-07-06 17:20             ` Paul Eggert
2018-07-06 17:33             ` Eli Zaretskii
2018-07-08 22:38             ` Basil L. Contovounesios
2018-07-06 17:30           ` Paul Eggert
     [not found] <<<87fu3vdjjk.fsf@tcd.ie>
     [not found] <<87fu3vdjjk.fsf@tcd.ie>

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mukzb173.fsf@tcd.ie \
    --to=contovob@tcd.ie \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.