[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: pure-fns in byte-opt.el
From: |
Stefan Monnier |
Subject: |
Re: pure-fns in byte-opt.el |
Date: |
Sun, 24 Sep 2017 12:23:29 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) |
> A side-effect-free function is one where all of the following is true:
> - After exiting the function (whether normally or nonlocally), the
> `match-data' are `equal' to the `match-data' before entering the function.
> - After exiting the function, all dynamic variables, their default values,
> their symbol cells, etc., are `eq' to the respective values before entering
> the function. Exceptions are variables only used for debugging/tracing,
> such as `cons-cells-consed'.
> - All buffer contents, markers, point values etc. are
> `equal-including-properties' to their previous values.
> - The same buffers and threads still exist.
I don't think we want to enumerate all the manners that side-effects can
occur, since we will inevitably forget some (and the list will get out
of date).
I think we should define it more as something like:
side-effect-free means: if the result of the function is not used,
calling the function or not does not affect the behavior of the program,
except that the function may signal an error.
side-effect-and-error-free means: like side-effect-free but cannot
signal an error. This means that the optimizer can eliminate calls
to those functions if the result is not used.
pure: like side-effect-free but additionally, the function always
returns the same value when called with the same arguments, so the
compiler can precompute the call if it knows the arguments.
-- Stefan