[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/native-comp 159f61b 4/5: Trigger native compilation when loading
From: |
Andrea Corallo |
Subject: |
feature/native-comp 159f61b 4/5: Trigger native compilation when loading bytecode |
Date: |
Tue, 17 Mar 2020 04:28:54 -0400 (EDT) |
branch: feature/native-comp
commit 159f61baa9e374cfd17acf1a45c0d553b57b7ac9
Author: Andrea Corallo <address@hidden>
Commit: Andrea Corallo <address@hidden>
Trigger native compilation when loading bytecode
Introduce a first mechanism to trigger compilation when lex elc files
are loaded. This is off by default and has to be better tested.
---
lisp/emacs-lisp/comp.el | 5 +++++
src/comp.c | 38 +++++++++++++++++++++++++++++++++++++-
src/comp.h | 10 ++++++++++
src/data.c | 2 ++
src/lisp.h | 1 +
src/lread.c | 2 +-
6 files changed, 56 insertions(+), 2 deletions(-)
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index c00a683..0728c4f 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -40,6 +40,11 @@
"Emacs Lisp native compiler."
:group 'lisp)
+(defcustom comp-deferred-compilation nil
+ "If t compile asyncronously all lexically bound .elc files being loaded."
+ :type 'boolean
+ :group 'comp)
+
(defcustom comp-speed 2
"Compiler optimization level. From 0 to 3.
- 0 no optimizations are performed, compile time is favored.
diff --git a/src/comp.c b/src/comp.c
index b9ecef0..74b74a8 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -492,7 +492,7 @@ declare_imported_func (Lisp_Object subr_sym, gcc_jit_type
*ret_type,
/* String containing the function ptr name. */
Lisp_Object f_ptr_name =
- CALLN (Ffuncall, intern_c_string (STR (comp-c-func-name)),
+ CALLN (Ffuncall, intern_c_string ("comp-c-func-name"),
subr_sym, make_string ("R", 1));
gcc_jit_type *f_ptr_type =
@@ -3360,6 +3360,40 @@ helper_PSEUDOVECTOR_TYPEP_XUNTAG (Lisp_Object a, enum
pvec_type code)
}
+/***********************************/
+/* Deferred compilation mechanism. */
+/***********************************/
+
+void
+maybe_defer_native_compilation (Lisp_Object function_name,
+ Lisp_Object definition)
+{
+ Lisp_Object src = Qnil;
+ Lisp_Object load_list = Vcurrent_load_list;
+
+ FOR_EACH_TAIL (load_list)
+ {
+ src = XCAR (load_list);
+ if (!CONSP (src))
+ break;
+ }
+
+ if (!comp_deferred_compilation
+ || noninteractive
+ || !NILP (Vpurify_flag)
+ || !COMPILEDP (definition)
+ || !FIXNUMP (AREF (definition, COMPILED_ARGLIST))
+ || !STRINGP (src)
+ || !suffix_p (src, ".elc"))
+ return;
+
+ src = concat2 (CALL1I (file-name-sans-extension, src),
+ build_pure_c_string (".el"));
+ if (!NILP (Ffile_exists_p (src)))
+ CALLN (Ffuncall, intern_c_string ("native-compile-async"), src, Qnil);
+}
+
+
/**************************************/
/* Functions used to load eln files. */
/**************************************/
@@ -3552,6 +3586,8 @@ void
syms_of_comp (void)
{
/* Compiler control customizes. */
+ DEFVAR_BOOL ("comp-deferred-compilation", comp_deferred_compilation,
+ doc: /* If t compile asyncronously every .elc file loaded. */);
DEFSYM (Qcomp_speed, "comp-speed");
DEFSYM (Qcomp_debug, "comp-debug");
diff --git a/src/comp.h b/src/comp.h
index 070ec4d..f3bcd4c 100644
--- a/src/comp.h
+++ b/src/comp.h
@@ -68,5 +68,15 @@ extern void load_comp_unit (struct Lisp_Native_Comp_Unit
*comp_u,
bool loading_dump);
extern void syms_of_comp (void);
+extern void maybe_defer_native_compilation (Lisp_Object function_name,
+ Lisp_Object definition);
+#else
+
+static inline void
+maybe_defer_native_compilation (Lisp_Object function_name,
+ Lisp_Object definition)
+{}
+
#endif
+
#endif
diff --git a/src/data.c b/src/data.c
index 8a0546c..173b92c 100644
--- a/src/data.c
+++ b/src/data.c
@@ -814,6 +814,8 @@ The return value is undefined. */)
Ffset (symbol, definition);
}
+ maybe_defer_native_compilation (symbol, definition);
+
if (!NILP (docstring))
Fput (symbol, Qfunction_documentation, docstring);
/* We used to return `definition', but now that `defun' and `defmacro' expand
diff --git a/src/lisp.h b/src/lisp.h
index cd543f5..9695976 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4102,6 +4102,7 @@ LOADHIST_ATTACH (Lisp_Object x)
if (initialized)
Vcurrent_load_list = Fcons (x, Vcurrent_load_list);
}
+extern bool suffix_p (Lisp_Object, const char *);
extern Lisp_Object save_match_data_load (Lisp_Object, Lisp_Object, Lisp_Object,
Lisp_Object, Lisp_Object);
extern int openp (Lisp_Object, Lisp_Object, Lisp_Object,
diff --git a/src/lread.c b/src/lread.c
index 32c83bf..2d90bcc 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1077,7 +1077,7 @@ effective_load_path (void)
}
/* Return true if STRING ends with SUFFIX. */
-static bool
+bool
suffix_p (Lisp_Object string, const char *suffix)
{
ptrdiff_t suffix_len = strlen (suffix);