From e13ecd4443275eb386ba15424947a9ee5977c8db Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Sat, 4 May 2024 08:55:56 +0200 Subject: [PATCH] Add some 'compilation-safety' documentation * 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 | 18 ++++++++++++++++++ doc/lispref/functions.texi | 13 ++++++++++--- lisp/emacs-lisp/bytecomp.el | 6 +++++- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/doc/lispref/compile.texi b/doc/lispref/compile.texi index 19451f31740..f8f1242586e 100644 --- a/doc/lispref/compile.texi +++ b/doc/lispref/compile.texi @@ -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, diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi index a77bf6e233d..9d4ecd8da25 100644 --- a/doc/lispref/functions.texi +++ b/doc/lispref/functions.texi @@ -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 diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 732a1629177..3e7674eeef6 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -138,7 +138,11 @@ :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") -- 2.39.5