9

I sometimes run multiple versions of Emacs from the same home directory. I have a number of byte-compiled files. Bytecode is not compatible across all Emacs versions, so I maintain separate directories for .elc files for each version range.

What are the version ranges for which the bytecode is compatible? I currently have

gnu-19.29
gnu-20
gnu-21
gnu-22
gnu-23
gnu-24
source
x-19
x-20
x-21

i.e. directories for each major release, with an additional separation at 19.29 (I've never used an older version on this machine, otherwise there'd be gnu-19), and separate directories for GNU Emacs and XEmacs. I'm probably overly cautious, though.

What is the official policy regarding bytecode compatibility across Emacs versions? Can I confidently keep using the major version? Can I merge some versions? Is there a bytecode version indication or checksum that I could query when compiling to create the directory name instead of relying on the Emacs version?

Note that I'm primarily interested in full compatibility, not just backward compatibility. I might run Emacs 27.3 and byte-compile some files, and then later Emacs 27.2 with the same home directory.

9

As maintainer, I strive to preserve the following:

  • Backward compatibility of byte-code. I.e. you should be able to take your .elc file compiled with Emacs-19 and run it in Emacs-27 successfully. Of course, in practice it doesn't always work, because backward incompatibilities are introduced either by accident or consciously (tho these are usually not specific to bytecompiled files).
  • Full byte-code compatibility within a major version. This is followed with less care, mostly because it tends to happen automatically, but normally you should be able to byte-compile on 27.N and run it successfully on 27.1. This said, it's always recommended to byte-compile on the older version.

Of course, the above is specifically about the byte compiled code, and still depends on actual general compatibility: if foo.el runs in Emacs-19 and Emacs-27, then a foo.elc compiled on Emacs-19 should work on Emacs-27. But if that foo.el doesn't work on Emacs-19 or on Emacs-27, then the foo.elc compiled on Emacs-19 probably won't work on Emacs-27.

Also, there are a few cases where we consciously break backward compatibility of byte-compiled code.

5

You should not expect bytecode files to be compatible between different Emacs versions. The actual bytecode format is mostly upwards compatible, but you will run into trouble with expanded macros.

Let me explain. When the byte-compiler encounters a macro, it computes the macro's expansion and compiles the result. If the macro expanded to a call to a function, then the resulting bytecode file will contain a reference to the function. If an internal function that appears in the expansion of a macro changes between Emacs versions, then the bytecode will not be compatible.

Obviously, the Emacs developers try to avoid macros that expand to internal functions that might change. However, this is sometimes difficult to achieve, and I would not count on that, especially in the presence of large changes such as the introduction of gv.el in Emacs 24.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.