diff options
| author | Andrea Corallo | 2020-03-15 21:44:05 +0000 |
|---|---|---|
| committer | Andrea Corallo | 2020-03-16 23:08:34 +0000 |
| commit | 159f61baa9e374cfd17acf1a45c0d553b57b7ac9 (patch) | |
| tree | 6832e7e815fb71c2f95e69af4056122ed1bbd1d8 | |
| parent | ea8864fb672a7ff2d1da1b91885239f60e16b359 (diff) | |
| download | emacs-159f61baa9e374cfd17acf1a45c0d553b57b7ac9.tar.gz emacs-159f61baa9e374cfd17acf1a45c0d553b57b7ac9.zip | |
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.
| -rw-r--r-- | lisp/emacs-lisp/comp.el | 5 | ||||
| -rw-r--r-- | src/comp.c | 38 | ||||
| -rw-r--r-- | src/comp.h | 10 | ||||
| -rw-r--r-- | src/data.c | 2 | ||||
| -rw-r--r-- | src/lisp.h | 1 | ||||
| -rw-r--r-- | 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 c00a68307b0..0728c4f0a81 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el | |||
| @@ -40,6 +40,11 @@ | |||
| 40 | "Emacs Lisp native compiler." | 40 | "Emacs Lisp native compiler." |
| 41 | :group 'lisp) | 41 | :group 'lisp) |
| 42 | 42 | ||
| 43 | (defcustom comp-deferred-compilation nil | ||
| 44 | "If t compile asyncronously all lexically bound .elc files being loaded." | ||
| 45 | :type 'boolean | ||
| 46 | :group 'comp) | ||
| 47 | |||
| 43 | (defcustom comp-speed 2 | 48 | (defcustom comp-speed 2 |
| 44 | "Compiler optimization level. From 0 to 3. | 49 | "Compiler optimization level. From 0 to 3. |
| 45 | - 0 no optimizations are performed, compile time is favored. | 50 | - 0 no optimizations are performed, compile time is favored. |
diff --git a/src/comp.c b/src/comp.c index b9ecef07f32..74b74a83b77 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, | |||
| 492 | 492 | ||
| 493 | /* String containing the function ptr name. */ | 493 | /* String containing the function ptr name. */ |
| 494 | Lisp_Object f_ptr_name = | 494 | Lisp_Object f_ptr_name = |
| 495 | CALLN (Ffuncall, intern_c_string (STR (comp-c-func-name)), | 495 | CALLN (Ffuncall, intern_c_string ("comp-c-func-name"), |
| 496 | subr_sym, make_string ("R", 1)); | 496 | subr_sym, make_string ("R", 1)); |
| 497 | 497 | ||
| 498 | gcc_jit_type *f_ptr_type = | 498 | gcc_jit_type *f_ptr_type = |
| @@ -3360,6 +3360,40 @@ helper_PSEUDOVECTOR_TYPEP_XUNTAG (Lisp_Object a, enum pvec_type code) | |||
| 3360 | } | 3360 | } |
| 3361 | 3361 | ||
| 3362 | 3362 | ||
| 3363 | /***********************************/ | ||
| 3364 | /* Deferred compilation mechanism. */ | ||
| 3365 | /***********************************/ | ||
| 3366 | |||
| 3367 | void | ||
| 3368 | maybe_defer_native_compilation (Lisp_Object function_name, | ||
| 3369 | Lisp_Object definition) | ||
| 3370 | { | ||
| 3371 | Lisp_Object src = Qnil; | ||
| 3372 | Lisp_Object load_list = Vcurrent_load_list; | ||
| 3373 | |||
| 3374 | FOR_EACH_TAIL (load_list) | ||
| 3375 | { | ||
| 3376 | src = XCAR (load_list); | ||
| 3377 | if (!CONSP (src)) | ||
| 3378 | break; | ||
| 3379 | } | ||
| 3380 | |||
| 3381 | if (!comp_deferred_compilation | ||
| 3382 | || noninteractive | ||
| 3383 | || !NILP (Vpurify_flag) | ||
| 3384 | || !COMPILEDP (definition) | ||
| 3385 | || !FIXNUMP (AREF (definition, COMPILED_ARGLIST)) | ||
| 3386 | || !STRINGP (src) | ||
| 3387 | || !suffix_p (src, ".elc")) | ||
| 3388 | return; | ||
| 3389 | |||
| 3390 | src = concat2 (CALL1I (file-name-sans-extension, src), | ||
| 3391 | build_pure_c_string (".el")); | ||
| 3392 | if (!NILP (Ffile_exists_p (src))) | ||
| 3393 | CALLN (Ffuncall, intern_c_string ("native-compile-async"), src, Qnil); | ||
| 3394 | } | ||
| 3395 | |||
| 3396 | |||
| 3363 | /**************************************/ | 3397 | /**************************************/ |
| 3364 | /* Functions used to load eln files. */ | 3398 | /* Functions used to load eln files. */ |
| 3365 | /**************************************/ | 3399 | /**************************************/ |
| @@ -3552,6 +3586,8 @@ void | |||
| 3552 | syms_of_comp (void) | 3586 | syms_of_comp (void) |
| 3553 | { | 3587 | { |
| 3554 | /* Compiler control customizes. */ | 3588 | /* Compiler control customizes. */ |
| 3589 | DEFVAR_BOOL ("comp-deferred-compilation", comp_deferred_compilation, | ||
| 3590 | doc: /* If t compile asyncronously every .elc file loaded. */); | ||
| 3555 | DEFSYM (Qcomp_speed, "comp-speed"); | 3591 | DEFSYM (Qcomp_speed, "comp-speed"); |
| 3556 | DEFSYM (Qcomp_debug, "comp-debug"); | 3592 | DEFSYM (Qcomp_debug, "comp-debug"); |
| 3557 | 3593 | ||
diff --git a/src/comp.h b/src/comp.h index 070ec4d5ca9..f3bcd4c09bc 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, | |||
| 68 | bool loading_dump); | 68 | bool loading_dump); |
| 69 | extern void syms_of_comp (void); | 69 | extern void syms_of_comp (void); |
| 70 | 70 | ||
| 71 | extern void maybe_defer_native_compilation (Lisp_Object function_name, | ||
| 72 | Lisp_Object definition); | ||
| 73 | #else | ||
| 74 | |||
| 75 | static inline void | ||
| 76 | maybe_defer_native_compilation (Lisp_Object function_name, | ||
| 77 | Lisp_Object definition) | ||
| 78 | {} | ||
| 79 | |||
| 71 | #endif | 80 | #endif |
| 81 | |||
| 72 | #endif | 82 | #endif |
diff --git a/src/data.c b/src/data.c index 8a0546ce09b..173b92c5bf4 100644 --- a/src/data.c +++ b/src/data.c | |||
| @@ -814,6 +814,8 @@ The return value is undefined. */) | |||
| 814 | Ffset (symbol, definition); | 814 | Ffset (symbol, definition); |
| 815 | } | 815 | } |
| 816 | 816 | ||
| 817 | maybe_defer_native_compilation (symbol, definition); | ||
| 818 | |||
| 817 | if (!NILP (docstring)) | 819 | if (!NILP (docstring)) |
| 818 | Fput (symbol, Qfunction_documentation, docstring); | 820 | Fput (symbol, Qfunction_documentation, docstring); |
| 819 | /* We used to return `definition', but now that `defun' and `defmacro' expand | 821 | /* We used to return `definition', but now that `defun' and `defmacro' expand |
diff --git a/src/lisp.h b/src/lisp.h index cd543f5047d..96959764879 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -4102,6 +4102,7 @@ LOADHIST_ATTACH (Lisp_Object x) | |||
| 4102 | if (initialized) | 4102 | if (initialized) |
| 4103 | Vcurrent_load_list = Fcons (x, Vcurrent_load_list); | 4103 | Vcurrent_load_list = Fcons (x, Vcurrent_load_list); |
| 4104 | } | 4104 | } |
| 4105 | extern bool suffix_p (Lisp_Object, const char *); | ||
| 4105 | extern Lisp_Object save_match_data_load (Lisp_Object, Lisp_Object, Lisp_Object, | 4106 | extern Lisp_Object save_match_data_load (Lisp_Object, Lisp_Object, Lisp_Object, |
| 4106 | Lisp_Object, Lisp_Object); | 4107 | Lisp_Object, Lisp_Object); |
| 4107 | extern int openp (Lisp_Object, Lisp_Object, Lisp_Object, | 4108 | extern int openp (Lisp_Object, Lisp_Object, Lisp_Object, |
diff --git a/src/lread.c b/src/lread.c index 32c83bfae8b..2d90bccdc07 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -1077,7 +1077,7 @@ effective_load_path (void) | |||
| 1077 | } | 1077 | } |
| 1078 | 1078 | ||
| 1079 | /* Return true if STRING ends with SUFFIX. */ | 1079 | /* Return true if STRING ends with SUFFIX. */ |
| 1080 | static bool | 1080 | bool |
| 1081 | suffix_p (Lisp_Object string, const char *suffix) | 1081 | suffix_p (Lisp_Object string, const char *suffix) |
| 1082 | { | 1082 | { |
| 1083 | ptrdiff_t suffix_len = strlen (suffix); | 1083 | ptrdiff_t suffix_len = strlen (suffix); |