unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Optimise 'while' bodies for effect
@ 2019-12-26 16:59 Mattias Engdegård
  2019-12-26 18:19 ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Mattias Engdegård @ 2019-12-26 16:59 UTC (permalink / raw)
  To: Emacs developers

[-- Attachment #1: Type: text/plain, Size: 569 bytes --]

Optimising the body of 'while' forms for effect (proposed patch attached) finds the following:

In nnheader-find-nov-line:
~/emacs/lisp/gnus/nnheader.el:449:32:Warning: value returned from (= (setq num
    (read cur)) article) is unused

In ldap-search-internal:
~/emacs/lisp/net/ldap.el:528:30:Warning: value returned from (1+ numres) is
    unused

In org-babel-screen-test:
~/emacs/lisp/org/ob-screen.el:120:4:Warning: value returned from (format
    "org-babel-screen: File not readable yet.") is unused

Not much, perhaps, but worth doing anyway?


[-- Attachment #2: 0001-Optimise-while-bodies-for-effect.patch --]
[-- Type: application/octet-stream, Size: 1291 bytes --]

From c8cdd32aac98721e2f543fe94134db32a280e371 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Thu, 26 Dec 2019 17:50:19 +0100
Subject: [PATCH] Optimise 'while' bodies for effect

* lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker):
Treat all expressions in the body of 'while' as for-effect,
since their values are discarded.  This also finds some errors.
---
 lisp/emacs-lisp/byte-opt.el | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
index 22fea1b8da..07fd548dec 100644
--- a/lisp/emacs-lisp/byte-opt.el
+++ b/lisp/emacs-lisp/byte-opt.el
@@ -480,6 +480,13 @@ byte-optimize-form-code-walker
                                                  backwards)))))
 	     (cons fn (mapcar 'byte-optimize-form (cdr form)))))
 
+	  ((eq fn 'while)
+           (unless (consp (cdr form))
+	     (byte-compile-warn "too few arguments for `while'"))
+           (cons fn
+                 (cons (byte-optimize-form (cadr form) nil)
+                       (byte-optimize-body (cddr form) t))))
+
 	  ((eq fn 'interactive)
 	   (byte-compile-warn "misplaced interactive spec: `%s'"
 			      (prin1-to-string form))
-- 
2.21.0 (Apple Git-122.2)


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: Optimise 'while' bodies for effect
  2019-12-26 16:59 Optimise 'while' bodies for effect Mattias Engdegård
@ 2019-12-26 18:19 ` Stefan Monnier
  2019-12-26 18:46   ` Mattias Engdegård
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2019-12-26 18:19 UTC (permalink / raw)
  To: Mattias Engdegård; +Cc: Emacs developers

> Not much, perhaps, but worth doing anyway?

LGTM,


        Stefan




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Optimise 'while' bodies for effect
  2019-12-26 18:19 ` Stefan Monnier
@ 2019-12-26 18:46   ` Mattias Engdegård
  2020-04-14 15:05     ` Basil L. Contovounesios
  0 siblings, 1 reply; 6+ messages in thread
From: Mattias Engdegård @ 2019-12-26 18:46 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs developers

26 dec. 2019 kl. 19.19 skrev Stefan Monnier <monnier@iro.umontreal.ca>:

> LGTM,

Thanks, pushed to master, along with the missing setq in ldap.el.
I leave the other warnings to Gnus and Org specialists.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Optimise 'while' bodies for effect
  2019-12-26 18:46   ` Mattias Engdegård
@ 2020-04-14 15:05     ` Basil L. Contovounesios
  2020-04-16 10:52       ` Mattias Engdegård
  0 siblings, 1 reply; 6+ messages in thread
From: Basil L. Contovounesios @ 2020-04-14 15:05 UTC (permalink / raw)
  To: Mattias Engdegård; +Cc: Stefan Monnier, Emacs developers

[-- Attachment #1: Type: text/plain, Size: 274 bytes --]

Mattias Engdegård <mattiase@acm.org> writes:

> I leave the other warnings to Gnus and Org specialists.

I'm not an Org specialist, but I think the only warning currently
emitted during 'make bootstrap' can be easily avoided by doing something
like the following:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-effect-free-warning-in-ob-screen.el-while-loop.patch --]
[-- Type: text/x-diff, Size: 1358 bytes --]

From a9fbf6612c1303beef0b313acd9dd7febc432084 Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <contovob@tcd.ie>
Date: Tue, 14 Apr 2020 15:26:04 +0100
Subject: [PATCH] Fix effect-free warning in ob-screen.el while loop

The warning was introduced and detected by an optimizer addition
proposed in the following thread:
https://lists.gnu.org/archive/html/emacs-devel/2019-12/msg00711.html

* lisp/org/ob-screen.el (org-babel-screen-test): Avoid 'value
returned from (format "...") is unused' warning by doing something
more useful than busy string manipulation while waiting for an
asynchronous subprocess to make the temporary file readable.
---
 lisp/org/ob-screen.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/org/ob-screen.el b/lisp/org/ob-screen.el
index ad00ee070d..837c18f840 100644
--- a/lisp/org/ob-screen.el
+++ b/lisp/org/ob-screen.el
@@ -126,7 +126,7 @@ org-babel-screen-test
     ;; XXX: need to find a better way to do the following
     (while (not (file-readable-p tmpfile))
       ;; do something, otherwise this will be optimized away
-      (format "org-babel-screen: File not readable yet."))
+      (sit-for 0.1))
     (setq tmp-string (with-temp-buffer
                        (insert-file-contents-literally tmpfile)
                        (buffer-substring (point-min) (point-max))))
-- 
2.25.1


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


The whole function/library could use some love, but since
org-babel-screen-test is intended as a manual test command,
I think the proposed tweak is good enough.  WDYT?

Thanks,

-- 
Basil

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: Optimise 'while' bodies for effect
  2020-04-14 15:05     ` Basil L. Contovounesios
@ 2020-04-16 10:52       ` Mattias Engdegård
  2020-04-17 10:41         ` Basil L. Contovounesios
  0 siblings, 1 reply; 6+ messages in thread
From: Mattias Engdegård @ 2020-04-16 10:52 UTC (permalink / raw)
  To: Basil L. Contovounesios; +Cc: Stefan Monnier, Emacs developers

14 apr. 2020 kl. 17.05 skrev Basil L. Contovounesios <contovob@tcd.ie>:

>     ;; XXX: need to find a better way to do the following
>     (while (not (file-readable-p tmpfile))
>       ;; do something, otherwise this will be optimized away
> -      (format "org-babel-screen: File not readable yet."))
> +      (sit-for 0.1))

This can only be an improvement!




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Optimise 'while' bodies for effect
  2020-04-16 10:52       ` Mattias Engdegård
@ 2020-04-17 10:41         ` Basil L. Contovounesios
  0 siblings, 0 replies; 6+ messages in thread
From: Basil L. Contovounesios @ 2020-04-17 10:41 UTC (permalink / raw)
  To: Mattias Engdegård; +Cc: Stefan Monnier, Emacs developers

Mattias Engdegård <mattiase@acm.org> writes:

> 14 apr. 2020 kl. 17.05 skrev Basil L. Contovounesios <contovob@tcd.ie>:
>
>>     ;; XXX: need to find a better way to do the following
>>     (while (not (file-readable-p tmpfile))
>>       ;; do something, otherwise this will be optimized away
>> -      (format "org-babel-screen: File not readable yet."))
>> +      (sit-for 0.1))
>
> This can only be an improvement!

Thanks, pushed to master.

Fix effect-free warning in ob-screen.el while loop
7f1dae114d 2020-04-17 11:38:25 +0100
https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=7f1dae114dffbf4bdec60e38ada4eb0673cfb4e2

-- 
Basil



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-04-17 10:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-12-26 16:59 Optimise 'while' bodies for effect Mattias Engdegård
2019-12-26 18:19 ` Stefan Monnier
2019-12-26 18:46   ` Mattias Engdegård
2020-04-14 15:05     ` Basil L. Contovounesios
2020-04-16 10:52       ` Mattias Engdegård
2020-04-17 10:41         ` Basil L. Contovounesios

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).