emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: optimizing defconst


From: Kim F. Storm
Subject: Re: optimizing defconst
Date: Mon, 29 Oct 2007 11:46:38 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)

Richard Stallman <address@hidden> writes:

>     One can make the argument that we can also use the analogy with
>     defmacro. If a macro is redefined at run time, the compiled code does
>     not know about it. It's not far fetched to do the same about defconst.
>
> I don't want the compiler to optimize away defconst values.
> It is asking for trouble (and it is work we don't need to do).

What about an option to make a constant read-only, something like

(defconst ...
   :read-only t)

The C-code already checks that constants (e.g nil and t) are not
modified via SYMBOL_CONSTANT_P, so there is no extra work at the
C-level for such a change (except provide accessor functions
set-variable-read-only and variable-read-only for the "constant"
field of a variable).

Then the byte-compiler could check to see if a constant (or any
variable for that matter) is really read-only and optimize it away.

But I see that enable-multibyte-characters is marked as read-only -
not because it cannot change, but because we don't want users to
modify it directly.  

So to make the byte-compiler aware of such things, it may be necessary
to mark some constants as "are constant, but don't optimize away", e.g.:

(put 'enable-multibyte-characters 'bytecomp-dont-optimize)

-- 
Kim F. Storm <address@hidden> http://www.cua.dk





reply via email to

[Prev in Thread] Current Thread [Next in Thread]