GNU bug report logs - #42147
28.0.50; pure vs side-effect-free, missing optimizations?

Previous Next

Package: emacs;

Reported by: Andrea Corallo <andrea_corallo <at> yahoo.it>

Date: Tue, 30 Jun 2020 22:28:02 UTC

Severity: normal

Found in version 28.0.50

Done: Mattias EngdegÄrd <mattiase <at> acm.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Mattias EngdegÄrd <mattiase <at> acm.org>
To: Andrea Corallo <andrea_corallo <at> yahoo.it>
Cc: Paul Eggert <eggert <at> cs.ucla.edu>, Stefan Monnier <monnier <at> iro.umontreal.ca>, 42147 <at> debbugs.gnu.org
Subject: bug#42147: 28.0.50; pure vs side-effect-free, missing  optimizations? 
Date: Wed, 1 Jul 2020 14:44:28 +0200
Actually, pure functions are side-effect-free but not necessarily error-free. But in essence, you are right.

The following functions look like they could be marked pure. Given that they currently aren't, there may be a good reason for their omission -- do correct me!

 integerp
 natnump
 floatp
 characterp
 numberp
 arrayp
 vectorp
 bool-vector-p
 char-or-string-p
 integer-or-marker-p
 keywordp
 number-or-marker-p
 sequencep
 length
 safe-length

... and some more (symbolp, stringp etc) that are already explicitly optimised.

Regarding fixnump, we could add an optimiser since this predicate can be constant-folded for certain arguments, but it's unclear whether it's worth the trouble since this predicate (and bignump) are less commonly used today. Most uses of fixnump (in Emacs) are in Calc, and those are probably relics that should be replaced.

More useful would be the ability to constant-fold ash, expt, %, mod and abs for a subset of each respective domain. I can write a patch.

We could also decide that it's not a problem if an operation returns either a fixnum or bignum depending on the platform, on the grounds that

 (1) the distinction is not directly carried over through numeric constants (bignums and fixnums look the same in .elc files)
 (2) any attempt to discriminate between fixnums and bignums is non-portable anyway (and we can punt the discrimination to runtime)

and thus constant-fold all integer operations (+, -, * etc), not just those resulting in a portable fixnum.





This bug report was last modified 4 years and 281 days ago.

Previous Next


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