home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / packages / bytecomp / README < prev    next >
Encoding:
Text File  |  1992-07-16  |  15.2 KB  |  343 lines

  1.  
  2.  
  3. This directory contains a new emacs-lisp byte-compiler.
  4. This file describes the compiler and its installation procedure.
  5.  
  6. This compiler is included with Lucid GNU Emacs, a divergent fork of Emacs 19,
  7. and will probably be included in FSF's Emacs 19 release, someday.  For more
  8. information about Lucid GNU Emacs, see the README on labrea.stanford.edu in
  9. the directory /pub/gnu/lucid/.
  10.  
  11. The new compiler has the following improvements:
  12.  
  13.  + optimization of compiled code:
  14.    - removal of unreachable code;
  15.    - removal of calls to side-effectless functions whose return-value
  16.      is unused;
  17.    - compile-time evaluation of safe constant forms, such as (consp nil)
  18.      and (ash 1 6);
  19.    - open-coding of literal lambdas;
  20.    - peephole optimization of emitted code;
  21.    - trivial functions are left uncompiled for speed.
  22.  + support for inline functions;
  23.  + compile-time evaluation of arbitrary expressions;
  24.  + compile-time warning messages for:
  25.    - functions being redefined with incompatible arglists;
  26.    - functions being redefined as macros, or vice-versa;
  27.    - functions or macros defined multiple times in the same file;
  28.    - functions being called with the incorrect number of arguments;
  29.    - functions being called which are not defined globally, in the 
  30.      file, or as autoloads;
  31.    - assignment and reference of undeclared free variables;
  32.    - various syntax errors;
  33.  + correct compilation of nested defuns, defmacros, defvars and defsubsts;
  34.  + correct compilation of top-level uses of macros;
  35.  + the ability to generate a histogram of functions called.
  36.  
  37. It consists of the following files:
  38.  
  39.  bytecomp.el        The guts of the compiler.  This may be autoloaded.
  40.  
  41.  byte-optimize.el    The optimization aspects of the compiler.  This is
  42.             loaded as needed.
  43.  
  44.  bytecomp-runtime.el    New functions and macros that should be around even
  45.             if the byte-compiler proper is not loaded.  This file
  46.             contains the definitions of several macros which are
  47.             advertised interfaces, and should be available to
  48.             interpreted code and compiled code whether the 
  49.             compiler itself is loaded or not.  This  file should
  50.             be loaded by your .emacs file, or (preferably) by
  51.             loadup.el or startup.el.
  52.  
  53.  disass.el        A disassembler for the new compiler.  The old 
  54.             disassembler no longer works.
  55.  
  56.  bytecode.c        For Emacs19 only.  This is a replacement byte-code
  57.             interpreter that defines the new byte-codes.
  58.             You *do not need this* to use the new compiler.
  59.             This file does not work in Emacs version 18.
  60.  
  61.  data.c.patch        For Emacs19 only.  This patch adds a new subr,
  62.             compiled-function-p, which identifies Lisp_Compiled
  63.             objects.
  64.  
  65.  eval.c.patch        This contains a better version of the macroexpand
  66.             function.  The patch is for v19, but you can easily
  67.             extract the function if you're so moved.
  68.  
  69.  lread.c.patch        For Emacs19 only.  This patch adds a new read-syntax,
  70.             #[...], for reading Lisp_Compiled objects directly.
  71.             This patch also removes the change to v19 that causes
  72.             numbers beginning with 0 to be read in octal, as that
  73.             causes a huge amount of existing code to break.
  74.  
  75.  print.c.patch        For Emacs19 only.  This patch adds a new variable,
  76.             print-readably, which, when bound to t, makes lists
  77.             of the form (quote <thing>) to print in the more
  78.             more concise (and faster to read) format of '<thing>.
  79.             Also, when print-readably is true, an error will be
  80.             signalled if there is an attempt to print out an
  81.             unreadable object (the #<...> objects).  This
  82.             is used by the compiler as a way of detecting some
  83.             load-time errors at compile-time.
  84.  
  85.  make-docfile.c        A version of etc/make-docfile which understands the new
  86.             format used in .elc files.  This will work with V18,
  87.             but is only necessary if you are using V19, and are
  88.             building an emacs which preloads things compiled with
  89.             the new compiler.
  90.  
  91. To install the new compiler, you may either place the above .el files in the
  92. standard emacs lisp directory, replacing the existing files called bytecomp.el
  93. and disass.el, or place the above .el files in their own directory, and add
  94. that directory to the front of your load-path.
  95.  
  96. It is important that you not mix up the old and new compilers; the new
  97. disass.el won't work with the old compiler, and the old disass.el will
  98. screw up the new compiler.
  99.  
  100. It is not necessary to install any of the patch files into your emacs; in 
  101. fact, it would be a lot of work to do so unless you are running a prerelease
  102. of version 19.
  103.  
  104. The new compiler can be compiled with the old compiler, but that's probably
  105. not the best idea.  To compile the new compiler with itself, simply do this:
  106.  
  107.  M-x load-file bytecomp-runtime.el
  108.  M-x load-file bytecomp.el
  109.  M-x load-file byte-optimize.el
  110.  M-x byte-compile-and-load-file bytecomp-runtime.el
  111.  M-x byte-compile-and-load-file bytecomp.el
  112.  M-x byte-compile-and-load-file byte-optimize.el
  113.  M-x byte-compile-and-load-file disass.el
  114.  
  115. That is, first load all of the compiler interpreted, and then compile it with
  116. itself.
  117.  
  118. The byte-compiler can be configured to produce files which depend on the 
  119. existence of the new byte-codes and read-syntax, or not.  The defaults should
  120. be correct in whichever version of emacs you happen to be running.
  121.  
  122. If you're not running Epoch, you will get some warnings of the form
  123.  
  124.   While compiling toplevel forms in file bytecomp.el:
  125.     ** reference to free variable epoch::version
  126.  
  127. Ignore them.  Since Epoch doesn't follow the normal Emacs conventions for what
  128. the value of emacs-version looks like, we have to look at epoch::version as
  129. well to decide whether we're running under a v18-vintage emacs, or a v19 one.
  130.  
  131. Questions, comments, and suggestions are more than welcome!
  132.  
  133. (But please do not flood me with requests for a prerelease version of emacs19.
  134. Complaints about the filenames being longer than 14 characters will be 
  135. gleefully ignored.)
  136.  
  137. Enjoy,
  138.       -- Jamie Zawinski <jwz@lucid.com>
  139.  
  140. ------------------------------------------------------------------------------
  141. The following variables may be used to customize the compiler's behavior:
  142.  
  143. byte-compile-verbose    Whether to report the function currently being 
  144.             compiled in the minibuffer (default t).
  145.  
  146. byte-optimize        Whether to do optimizations; this may be t, nil,
  147.             'source, or 'byte (default t).
  148.  
  149. byte-optimize-log    Whether to report (in excruciating detail) exactly
  150.             which optimizations have been made.  This may be t,
  151.             nil, 'source, or 'byte (default nil).
  152.  
  153. byte-compile-error-on-warn    Whether to stop compilation when a warning is
  154.                 produced (default nil).
  155.  
  156. byte-compile-delete-errors    Whether the optimizer may delete calls or 
  157.                 variable references that are side-effect-free
  158.                 except that they may signal an error (default
  159.                 t).  Set this to nil if you use the abysmal
  160.                 style of doing type-assertions this way.
  161.  
  162. byte-compile-generate-call-tree    Whether to generate a histogram of function
  163.                 calls.  This can be useful for finding unused
  164.                 functions, as well as simple performance
  165.                 metering.
  166.  
  167. byte-compile-warnings    List of warnings to issue, or t.  May contain
  168.             free-vars   references to variables not in the current
  169.                         lexical scope
  170.             unresolved  calls to unknown functions
  171.             callargs    function calls with args that don't match
  172.                     the function's definition
  173.             redefine    function cell redefined from a macro to a
  174.                     function or vice versa, or redefined to 
  175.                     take incompatible args
  176.             This defaults to nil in -batch mode, which is slightly
  177.             faster, and t otherwise.
  178.  
  179. byte-compile-emacs18-compatibility    Whether the compiler should generate
  180.             .elc files which can be loaded into generic emacs 18's
  181.             which don't have the file bytecomp-runtime.el loaded.
  182.  
  183. byte-compile-generate-emacs19-bytecodes    Whether to generate bytecodes which
  184.             exist only in emacs19.  This is a more extreme step
  185.             than setting emacs18-compatibility to nil, because
  186.             there is no elisp you can load into an emacs18 to make
  187.             files compiled this way work.
  188.  
  189. byte-compile-single-version    Normally the byte-compiler will consult the
  190.             above two variables at runtime, but if this variable 
  191.             is true before the compiler itself is loaded/compiled,
  192.             then the runtime checks will not be made, and
  193.             compilation will be slightly faster.  To use this, 
  194.             start up a fresh emacs, set this to t, and repeat the
  195.             compiler-compilation steps above.  Make sure you set
  196.             this before loading the .el files, or you will lose.
  197.  
  198. elisp-source-extension-re    Regexp for the extension of elisp source-files;
  199.                 see also the function byte-compile-dest-file.
  200.  
  201. byte-compile-overwrite-file    If nil, old .elc files are deleted before the
  202.             new one is saved, and .elc files will have the same 
  203.             modes as the corresponding .el file.  Otherwise, 
  204.             existing .elc files will simply be overwritten, and 
  205.             the existing modes will not be changed.  If this
  206.             variable is nil, then an .elc file which is a
  207.             symbolic link will be turned into a normal file, 
  208.             instead of the file which the link points to being
  209.             overwritten.
  210.  
  211. Most of the above parameters can also be set on a file-by-file basis; see
  212. the documentation of the `byte-compiler-options' macro.
  213.  
  214. ------------------------------------------------------------------------------
  215. Miscellaneous new features:
  216.  
  217.   o  The form `defsubst' is just like `defun', except that the function
  218.      generated will be open-coded in compiled code which uses it.  This
  219.      means that no function call will be generated, it will simply be
  220.      spliced in.  Elisp functions calls are very slow, so this can be a
  221.      big win.
  222.  
  223.      You can generally accomplish the same thing with `defmacro', but in
  224.      that case, the defined procedure can't be used as an argument to
  225.      mapcar, etc.
  226.  
  227.      Remember that excessive inlining means your .elc file size and memory
  228.      consumption can go way up.
  229.  
  230.   o  You can make a given function be inline even if it has already been
  231.      defined with `defun' by using the `proclaim-inline' form like so:
  232.     (proclaim-inline my-function)
  233.      This is, in fact, exactly what `defsubst' does.  To make a function no
  234.      longer be inline, you must use `proclaim-notinline'.  Beware that if
  235.      you define a function with `defsubst' and later redefine it with 
  236.      `defun', it will still be open-coded until you use proclaim-notinline.
  237.  
  238.   o  You can also open-code one particular call to a function without
  239.      open-coding all calls.  Use the `inline' form to do this, like so:
  240.  
  241.         (inline (foo 1 2 3))    ;; `foo' will be open-coded
  242.     or...
  243.         (inline            ;;  `foo' and `baz' will be 
  244.          (foo 1 2 3 (bar 5))    ;; open-coded, but `bar' will not.
  245.          (baz 0))
  246.  
  247.   o  It is possible to open-code a function in the same file it is defined
  248.      in without having to load that file before compiling it.  the
  249.      byte-compiler has been modified to remember function definitions in
  250.      the compilation environment in the same way that it remembers macro
  251.      definitions.
  252.  
  253.   o  Forms like ((lambda ...) ...) are open-coded.
  254.  
  255.   o  The form `eval-when-compile' is like progn, except that the body
  256.      is evaluated at compile-time.  When it appears at top-level, this
  257.      is analogous to the Common Lisp idiom (eval-when (compile) ...).
  258.      When it does not appear at top-level, it is similar to the
  259.      Common Lisp #. reader macro (but not in interpreted code.)
  260.      If you're thinking of using this, consider whether `provide' and
  261.      `require' might do the job as well.
  262.  
  263.   o  The form `eval-and-compile' is similar to eval-when-compile, but
  264.      the whole form is evalled both at compile-time and at run-time.
  265.      If you're thinking of using this, consider whether `provide' and
  266.      `require' might do the job as well.
  267.  
  268.   o  The command `byte-compile-and-load-file' does what you'd think.
  269.  
  270.   o  The command `elisp-compile-defun' is analogous to `eval-defun'.
  271.      I bind this to ^C^C and bind `eval-defun' to ^C^E.
  272.  
  273.   o  If you run `byte-compile-file' on a filename which is visited in a 
  274.      buffer, and that buffer is modified, you are asked whether you want
  275.      to save the buffer before compiling.
  276.  
  277. ------------------------------------------------------------------------------
  278. The following problems will be seen when compiling the Emacs 18.57 source tree
  279. with the new compiler.  (I mention them here only to point out that they are
  280. not bugs in the compiler itself.)
  281.  
  282. The most obvious problem is that if byte-compile-warnings is t, or a list
  283. containing the symbol 'free-vars, roughly a billion warnings will be produced,
  284. since much of the code in the default emacs library takes advantage of the
  285. fact that emacs-lisp variables have dynamic scope.  I consider it
  286. exceptionally poor style to use dynamic scoping unless absolutely necessary,
  287. and if you agree, then the free-vars warning can be invaluable in tracking
  288. down unintentional variable references and misspellings.
  289.  
  290. The free-variable warning does not mean the compiler has miscompiled the code;
  291. it is merely a sanity-check.  See the comments at the top of byte-optimize.el 
  292. for some meandering thoughts about lexical scope.
  293.  
  294. bibtex.el loses because the Sunwindows macro `defmenu' is undefined, and
  295. without knowing that it's a macro, this file looks like it's invoking
  296. strings as functions.  Perhaps this wouldn't lose if it were compiled under
  297. Sunwindows.
  298.  
  299. While compiling corelate-sequences in file buffer-merge.el:
  300.   ** ifind-longest-subsequence called with 3 arguments, but accepts only 2
  301.  
  302. While compiling the end of the data in file c++-mode.el:
  303.   ** the function strings-to-char is not known to be defined.
  304. (used in c++-uncomment-region, should be string-to-char.)
  305.  
  306. While compiling generate-month in file cal.el:
  307.   ** malformed let binding: (first-day-of-month (day-of-week month 1 year) 7)
  308.  
  309. While compiling doctor-svo in file doctor.el:
  310.   ** malformed let binding: (foo (doctor-subjsearch sent key type) sent)
  311.  
  312. While compiling rmail-widen-to-current-msgbeg in file rmail.el:
  313.   ** malformed let binding: (unwind-protect (progn (narrow-to-region (rmail-msg
  314. beg rmail-current-message) (point-max)) (goto-char (point-min)) (funcall functi
  315. on)) (narrow-to-region (- (point-max) obeg) (point-max)))
  316.  
  317. This is bad news: it means that a form which was intended to be inside of
  318. an unwind-protect is really the value of a variable named unwind-protect.
  319. And the protected clause is being ignored.
  320.  
  321. The file sun-cursors.el cannot be compiled because it exhibits a fundamental
  322. misunderstanding of how macros are supposed to work.  It it written with the
  323. assumption that macroexpand-time and load-time are one and the same, which 
  324. was a bug in the old compiler, which is fixed in this new one.
  325.  
  326. The completer.el package from Thinking Machines (version 10.3 and older)
  327. exhibits the same fatal assumption.
  328.  
  329. The file cl.el must be loaded before it can be compiled, because it is a
  330. very circular, incestuous piece of code.  It makes use of the macro `do' 
  331. before defining it; and even if the `do' macro were earlier in the file,
  332. it's expander makes use of functions defined in the same file, which 
  333. are not defined in the compilation environment.
  334.  
  335. Another thing to realize is that the `gensym' function from cl.el doesn't
  336. really work: when you write an uninterned symbol out to an .elc file, it
  337. looks like an interned symbol, and becomes one when that file is loaded.
  338. So if you've got a function that uses a gensym as a variable name (as any
  339. function which uses the `pop' macro would, for example) that function will
  340. be binding an interned symbol named something like `G_$$5', instead of an
  341. uninterned one.  Gensyms don't exist, and can't until/unless there is some
  342. equivalent of Common Lisp's #: reader macro.
  343.