]> git.eshelyaron.com Git - emacs.git/commitdiff
Add some 'compilation-safety' documentation
authorAndrea Corallo <acorallo@gnu.org>
Sat, 4 May 2024 06:55:56 +0000 (08:55 +0200)
committerEshel Yaron <me@eshelyaron.com>
Thu, 16 May 2024 08:18:57 +0000 (10:18 +0200)
* lisp/emacs-lisp/bytecomp.el (compilation-safety): Better doc.
* doc/lispref/functions.texi (Declare Form): Add 'safety'.
* doc/lispref/compile.texi (Native-Compilation Variables): Add
'compilation-safety'.

(cherry picked from commit 04e7078d5e2a61c92e61946ffedea25c11951dec)

doc/lispref/compile.texi
doc/lispref/functions.texi
lisp/emacs-lisp/bytecomp.el

index 19451f317403dbd1a3c4d1bf8d87b20be43a138d..f8f1242586e0eb5220fafe3fd050e232fef74fab 100644 (file)
@@ -987,6 +987,24 @@ form, @pxref{Declare Form}.)
 The default value is 2.
 @end defopt
 
+@defopt compilation-safety
+This variable specifies the safetyness level used for the code emitted
+native code.  The value of compilation-safety should be a number between
+zero and one with the following meaning:
+
+@table @asis
+@item 0
+Emitted code can misbehave or crash Emacs if function declarations are
+not correct and the function is native compiled.
+@item 1
+Emitted code is generated in a safe matter even if function are
+miss-declared."
+@end table
+
+This can be controlled at function granularity as well by using the
+@code{safety} @code{declare} form, @pxref{Declare Form}.
+@end defopt
+
 @defopt native-comp-debug
 This variable specifies the level of debugging information produced by
 native-compilation.  Its value should be a number between zero and 3,
index a77bf6e233d1535a9d839589d6c6f223eb9892bc..9d4ecd8da250c607953f3bef80eab92c7443c63b 100644 (file)
@@ -2709,6 +2709,12 @@ native code emitted for the function.  In particular, if @var{n} is
 @minus{}1, native compilation of the function will emit bytecode
 instead of native code for the function.
 
+@item (safety @var{n})
+Specify the value of @code{compilation-safety} in effect for this
+function.  This allows function-level control of the safety level used
+for the code emitted for the function (@pxref{Native-Compilation
+Variables}).
+
 @item (type @var{type})
 Declare @var{type} to be the type of this function.  This is used for
 documentation by @code{describe-function}.  Also it can be used by the
@@ -2756,9 +2762,10 @@ For description of additional types, see @ref{Lisp Data Types}).
 
 Declaring a function with an incorrect type produces undefined behavior
 and could lead to unexpected results or might even crash Emacs when code
-is native-compiled and loaded.  Note also that when redefining (or
-advising) a type declared function the replacement should respect the
-original signature to avoid undefined behavior.
+is native-compiled and loaded if compiled with @ref{compilation-safety}
+0.  Note also that when redefining (or advising) a type declared
+function the replacement should respect the original signature to avoid
+undefined behavior.
 
 @item no-font-lock-keyword
 This is valid for macros only.  Macros with this declaration are
index 732a1629177ad350cbaac13d9063bcdb86d92032..3e7674eeef6197fab78934f15ddeba20dd10cdfe 100644 (file)
   :group 'lisp)
 
 (defcustom compilation-safety 1
-  "Safety level."
+  "Safety level for compilation.
+Possible values are:
+0 emitted code can misbehave or crash Emacs if function declarations are not
+correct.
+1 emitted code is generated in a safe matter even if function are miss-declared."
   :type 'integer
   :safe #'integerp
   :version "30.1")