GNU bug report logs - #18767
24.4; incorrect byte-compile on arithmatic comparisons

Previous Next

Package: emacs;

Reported by: Shigeru Fukaya <shigeru.fukaya <at> gmail.com>

Date: Sat, 18 Oct 2014 20:00:02 UTC

Severity: normal

Found in version 24.4

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 18767 in the body.
You can then email your comments to 18767 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#18767; Package emacs. (Sat, 18 Oct 2014 20:00:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Shigeru Fukaya <shigeru.fukaya <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 18 Oct 2014 20:00:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Shigeru Fukaya <shigeru.fukaya <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.4; incorrect byte-compile on arithmatic comparisons
Date: Sun, 19 Oct 2014 04:58:31 +0900
Hello,

byte-compile of arithmatic comparison operators on more than two
arguments is incorrect.

(disassemble (lambda () (< (a) (b) (c))))

byte code:
  args: nil
0	constant  a
1	call	  0
2	constant  b
3	call	  0
4	lss	  
5	goto-if-nil-else-pop 1
8	constant  b
9	call	  0
10	constant  c
11	call	  0
12	lss	  
13:1	return	  


Functions a, b, c should be called once respectively if the function
has possibility of side effect.
But b may be called twice, and c may not be called.


I'm sorry for late report at the very time of release, but I noticed
just now.

Regards,
Shigeru





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18767; Package emacs. (Sun, 19 Oct 2014 10:22:01 GMT) Full text and rfc822 format available.

Message #8 received at 18767 <at> debbugs.gnu.org (full text, mbox):

From: Shigeru Fukaya <shigeru.fukaya <at> gmail.com>
To: 18767 <at> debbugs.gnu.org
Subject: bug#18767: Acknowledgement (24.4;
 incorrect byte-compile on arithmatic comparisons)
Date: Sun, 19 Oct 2014 19:20:51 +0900
[Message part 1 (text/plain, inline)]
I tried to fix with the attached patch.

Regards,
Shigeru
[bytecomp.diff (application/octet-stream, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18767; Package emacs. (Mon, 20 Oct 2014 21:44:01 GMT) Full text and rfc822 format available.

Message #11 received at 18767 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Shigeru Fukaya <shigeru.fukaya <at> gmail.com>
Cc: 18767 <at> debbugs.gnu.org
Subject: Re: bug#18767: 24.4; incorrect byte-compile on arithmatic comparisons
Date: Mon, 20 Oct 2014 17:42:56 -0400
Version:24.5

> byte-compile of arithmatic comparison operators on more than two
> arguments is incorrect.

Indeed, I was not very awake when I committed that code.  I just
reverted the change so the byte-compiler simply doesn't optimize this case.
To do any better, I think we'll have to do something like:

loop over all args, doing "byte-compile-form" + "dup", and then apply
the comparisons backward, combining them with "and".


        Stefan




bug closed, send any further explanations to 18767 <at> debbugs.gnu.org and Shigeru Fukaya <shigeru.fukaya <at> gmail.com> Request was from Stefan Monnier <monnier <at> iro.umontreal.ca> to control <at> debbugs.gnu.org. (Mon, 20 Oct 2014 21:44:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18767; Package emacs. (Wed, 22 Oct 2014 09:17:01 GMT) Full text and rfc822 format available.

Message #16 received at 18767 <at> debbugs.gnu.org (full text, mbox):

From: Shigeru Fukaya <shigeru.fukaya <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 18767 <at> debbugs.gnu.org
Subject: Re: bug#18767: 24.4; incorrect byte-compile on arithmatic comparisons
Date: Wed, 22 Oct 2014 18:16:42 +0900
I think your change of reversion will cause byte-compile error when
more than two args are specified.
Maybe you had better call byte-compile-normal-call for that case at least.

>loop over all args, doing "byte-compile-form" + "dup", and then apply
>the comparisons backward, combining them with "and".

Alternative is,

If non-first args are all constants or simple reference, fold them with AND,
otherwise call them at once by byte-compile-normal-call.


Shigeru


>Version:24.5
>
>> byte-compile of arithmatic comparison operators on more than two
>> arguments is incorrect.
>
>Indeed, I was not very awake when I committed that code.  I just
>reverted the change so the byte-compiler simply doesn't optimize this case.
>To do any better, I think we'll have to do something like:
>
>loop over all args, doing "byte-compile-form" + "dup", and then apply
>the comparisons backward, combining them with "and".
>
>
>        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18767; Package emacs. (Wed, 22 Oct 2014 13:40:02 GMT) Full text and rfc822 format available.

Message #19 received at 18767 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Shigeru Fukaya <shigeru.fukaya <at> gmail.com>
Cc: 18767 <at> debbugs.gnu.org
Subject: Re: bug#18767: 24.4; incorrect byte-compile on arithmatic comparisons
Date: Wed, 22 Oct 2014 09:39:27 -0400
> I think your change of reversion will cause byte-compile error when
> more than two args are specified.

No errors, but yes, warnings.

>> loop over all args, doing "byte-compile-form" + "dup", and then apply
>> the comparisons backward, combining them with "and".
> Alternative is, If non-first args are all constants or simple
> reference, fold them with AND, otherwise call them at once by
> byte-compile-normal-call.

I guess that's OK, indeed.
I was worried that (<= 1 0 "a" nil) would return nil rather than
signal an error, but I see that this is already the case if you use
a normal call.  I installed your patch (except, using `cl-every').
Thank you,


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18767; Package emacs. (Wed, 22 Oct 2014 16:27:01 GMT) Full text and rfc822 format available.

Message #22 received at 18767 <at> debbugs.gnu.org (full text, mbox):

From: Shigeru Fukaya <shigeru.fukaya <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 18767 <at> debbugs.gnu.org
Subject: Re: bug#18767: 24.4; incorrect byte-compile on arithmatic comparisons
Date: Thu, 23 Oct 2014 01:26:22 +0900
>I was worried that (<= 1 0 "a" nil) would return nil rather than
>signal an error, but I see that this is already the case if you use
>a normal call.  I installed your patch (except, using `cl-every').

How about adding the sentence to their help document, implying the
behavior, like,

  All args are evaluateed (without checking type) at first,
  then compared left to right.


Shigeru




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18767; Package emacs. (Wed, 22 Oct 2014 17:40:01 GMT) Full text and rfc822 format available.

Message #25 received at 18767 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Shigeru Fukaya <shigeru.fukaya <at> gmail.com>
Cc: 18767 <at> debbugs.gnu.org
Subject: Re: bug#18767: 24.4; incorrect byte-compile on arithmatic comparisons
Date: Wed, 22 Oct 2014 13:39:04 -0400
> How about adding the sentence to their help document, implying the
> behavior, like,
>   All args are evaluateed (without checking type)

This is necessarily true by virtue of being a function, so I don't think
we should repeat it.

> at first,
>   then compared left to right.

We could document that some of the later comparisons might be skipped, indeed.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18767; Package emacs. (Wed, 22 Oct 2014 17:59:02 GMT) Full text and rfc822 format available.

Message #28 received at 18767 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 18767 <at> debbugs.gnu.org, Shigeru Fukaya <shigeru.fukaya <at> gmail.com>
Subject: Re: bug#18767: 24.4; incorrect byte-compile on arithmatic comparisons
Date: Wed, 22 Oct 2014 13:58:22 -0400
Stefan Monnier wrote:

> (except, using `cl-every').

This fails to bootstrap:

  simple.el:2490:32:Error: Symbol's function definition is void: cl-every




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 20 Nov 2014 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 9 years and 167 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.