GNU bug report logs -
#64127
30.0.50; mutate-constant warning with pure function
Previous Next
Reported by: Basil Contovounesios <contovob <at> tcd.ie>
Date: Sat, 17 Jun 2023 11:33:02 UTC
Severity: normal
Tags: notabug, wontfix
Found in version 30.0.50
Done: Basil Contovounesios <contovob <at> tcd.ie>
Bug is archived. No further changes may be made.
Full log
Message #8 received at 64127 <at> debbugs.gnu.org (full text, mbox):
17 juni 2023 kl. 13.32 skrev Basil Contovounesios <contovob <at> tcd.ie>:
> Given a file foo.el that defines a pure function foo:
> (defun foo (x) (declare (pure t)) (list x))
> and another file bar.el that mutates the result of foo:
> (setcar (foo nil) t)
> byte-compiling bar.el emits a mutate-constant warning, even though the
> result of foo is a fresh list:
No, the `pure` declaration means that the function can be evaluated at compile time which the compiler happily does, yielding a constant list, which your code then attempts to modify.
This is why the function `list` itself is not declared `pure` -- while it does look like a pure function when speaking informally, users relies on it returning a freshly allocated list that can be modified and that makes it non-pure. (If lists were immutable, then `list` would naturally be pure.)
Only the mutate-constant warning is new here; previously, the compiler would have let you make this mistake undisturbed.
Thus either you remove the pure-declaration from your function, or you don't mutate what it returns.
This bug report was last modified 1 year and 342 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.