aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Corallo2020-10-13 22:48:22 +0200
committerAndrea Corallo2020-10-14 11:04:36 +0200
commit03e98f93f72c8a158a3584355bca174e2c63dce6 (patch)
treec22476153cfddbdd50bc6f257ad71c4751a1035b
parente9c150b5c2efee4fad0e41668f5bf1ecb9fad0df (diff)
downloademacs-03e98f93f72c8a158a3584355bca174e2c63dce6.tar.gz
emacs-03e98f93f72c8a158a3584355bca174e2c63dce6.zip
Use form native compilation in `comp-trampoline-compile'
* lisp/emacs-lisp/comp.el (comp-trampoline-sym): Remove function. (comp-trampoline-filename): As we are introducing an ABI change in the eln trampoline format change the trampoline filename to disambiguate. (comp-trampoline-search): Rename from `comp-search-trampoline' and return directly the trampoline. (comp-trampoline-compile): Rework to use native form compilation in place of un-evaluating a function and return directly the trampoline. (comp-subr-trampoline-install): Update for `comp-trampoline-search' and `comp-trampoline-compile' new interfaces. * src/comp.c (Fcomp__install_trampoline): Store the trampoline itself as value in `comp-installed-trampolines-h'. (syms_of_comp): Doc update `comp-installed-trampolines-h'.
-rw-r--r--lisp/emacs-lisp/comp.el66
-rw-r--r--src/comp.c6
2 files changed, 34 insertions, 38 deletions
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index cd13c44fa91..a460340102a 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -2598,13 +2598,9 @@ Prepare every function for final compilation and drive the C back-end."
2598 2598
2599;; Primitive funciton advice machinery 2599;; Primitive funciton advice machinery
2600 2600
2601(defsubst comp-trampoline-sym (subr-name)
2602 "Given SUBR-NAME return the trampoline function name."
2603 (intern (concat "--subr-trampoline-" (symbol-name subr-name))))
2604
2605(defsubst comp-trampoline-filename (subr-name) 2601(defsubst comp-trampoline-filename (subr-name)
2606 "Given SUBR-NAME return the filename containing the trampoline." 2602 "Given SUBR-NAME return the filename containing the trampoline."
2607 (concat (comp-c-func-name subr-name "subr-trampoline-" t) ".eln")) 2603 (concat (comp-c-func-name subr-name "subr--trampoline-" t) ".eln"))
2608 2604
2609(defun comp-make-lambda-list-from-subr (subr) 2605(defun comp-make-lambda-list-from-subr (subr)
2610 "Given SUBR return the equivalent lambda-list." 2606 "Given SUBR return the equivalent lambda-list."
@@ -2621,39 +2617,38 @@ Prepare every function for final compilation and drive the C back-end."
2621 (push (gensym "arg") lambda-list)) 2617 (push (gensym "arg") lambda-list))
2622 (reverse lambda-list))) 2618 (reverse lambda-list)))
2623 2619
2624(defun comp-search-trampoline (subr-name) 2620(defun comp-trampoline-search (subr-name)
2625 "Search a trampoline file for SUBR-NAME. 2621 "Search a trampoline file for SUBR-NAME.
2626Return the its filename if found or nil otherwise." 2622Return the trampoline if found or nil otherwise."
2627 (cl-loop 2623 (cl-loop
2628 with rel-filename = (comp-trampoline-filename subr-name) 2624 with rel-filename = (comp-trampoline-filename subr-name)
2629 for dir in comp-eln-load-path 2625 for dir in comp-eln-load-path
2630 for filename = (expand-file-name rel-filename 2626 for filename = (expand-file-name rel-filename
2631 (concat dir comp-native-version-dir)) 2627 (concat dir comp-native-version-dir))
2632 when (file-exists-p filename) 2628 when (file-exists-p filename)
2633 do (cl-return filename))) 2629 do (cl-return (native-elisp-load filename))))
2634 2630
2635(defun comp-trampoline-compile (subr-name) 2631(defun comp-trampoline-compile (subr-name)
2636 "Synthesize and compile a trampoline for SUBR-NAME and return its filename." 2632 "Synthesize compile and return a trampoline for SUBR-NAME."
2637 (let ((trampoline-sym (comp-trampoline-sym subr-name)) 2633 (let* ((lambda-list (comp-make-lambda-list-from-subr
2638 (lambda-list (comp-make-lambda-list-from-subr 2634 (symbol-function subr-name)))
2639 (symbol-function subr-name))) 2635 ;; The synthesized trampoline must expose the exact same ABI of
2640 ;; Use speed 0 to maximize compilation speed and not to 2636 ;; the primitive we are replacing in the function reloc table.
2641 ;; optimize away funcall calls! 2637 (form `(lambda ,lambda-list
2642 (byte-optimize nil) 2638 (let ((f #',subr-name))
2643 (comp-speed 0)) 2639 (,(if (memq '&rest lambda-list) #'apply 'funcall)
2644 ;; The synthesized trampoline must expose the exact same ABI of 2640 f
2645 ;; the primitive we are replacing in the function reloc table. 2641 ,@(cl-loop
2646 (defalias trampoline-sym 2642 for arg in lambda-list
2647 `(closure nil ,lambda-list 2643 unless (memq arg '(&optional &rest))
2648 (let ((f #',subr-name)) 2644 collect arg)))))
2649 (,(if (memq '&rest lambda-list) #'apply 'funcall) 2645 ;; Use speed 0 to maximize compilation speed and not to
2650 f 2646 ;; optimize away funcall calls!
2651 ,@(cl-loop 2647 (byte-optimize nil)
2652 for arg in lambda-list 2648 (comp-speed 0)
2653 unless (memq arg '(&optional &rest)) 2649 (lexical-binding t))
2654 collect arg)))))
2655 (native-compile 2650 (native-compile
2656 trampoline-sym nil 2651 form nil
2657 (cl-loop 2652 (cl-loop
2658 for load-dir in comp-eln-load-path 2653 for load-dir in comp-eln-load-path
2659 for dir = (concat load-dir comp-native-version-dir) 2654 for dir = (concat load-dir comp-native-version-dir)
@@ -2674,14 +2669,13 @@ Return the its filename if found or nil otherwise."
2674 "Make SUBR-NAME effectively advice-able when called from native code." 2669 "Make SUBR-NAME effectively advice-able when called from native code."
2675 (unless (or (memq subr-name comp-never-optimize-functions) 2670 (unless (or (memq subr-name comp-never-optimize-functions)
2676 (gethash subr-name comp-installed-trampolines-h)) 2671 (gethash subr-name comp-installed-trampolines-h))
2677 (let ((trampoline-sym (comp-trampoline-sym subr-name))) 2672 (cl-assert (subr-primitive-p (symbol-function subr-name)))
2678 (cl-assert (subr-primitive-p (symbol-function subr-name))) 2673 (comp--install-trampoline
2679 (load (or (comp-search-trampoline subr-name) 2674 subr-name
2680 (comp-trampoline-compile subr-name)) 2675 (or (comp-trampoline-search subr-name)
2681 nil t) 2676 (comp-trampoline-compile subr-name)
2682 (cl-assert 2677 ;; Should never happen.
2683 (subr-native-elisp-p (symbol-function trampoline-sym))) 2678 (cl-assert nil)))))
2684 (comp--install-trampoline subr-name (symbol-function trampoline-sym)))))
2685 2679
2686 2680
2687;; Some entry point support code. 2681;; Some entry point support code.
diff --git a/src/comp.c b/src/comp.c
index f80172e89bf..0c555578f81 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -4158,7 +4158,7 @@ DEFUN ("comp--install-trampoline", Fcomp__install_trampoline,
4158 if (EQ (subr, orig_subr)) 4158 if (EQ (subr, orig_subr))
4159 { 4159 {
4160 freloc.link_table[i] = XSUBR (trampoline)->function.a0; 4160 freloc.link_table[i] = XSUBR (trampoline)->function.a0;
4161 Fputhash (subr_name, Qt, Vcomp_installed_trampolines_h); 4161 Fputhash (subr_name, trampoline, Vcomp_installed_trampolines_h);
4162 return Qt; 4162 return Qt;
4163 } 4163 }
4164 i++; 4164 i++;
@@ -5296,7 +5296,9 @@ The last directory of this list is assumed to be the system one. */);
5296 redefinable effectivelly. */); 5296 redefinable effectivelly. */);
5297 5297
5298 DEFVAR_LISP ("comp-installed-trampolines-h", Vcomp_installed_trampolines_h, 5298 DEFVAR_LISP ("comp-installed-trampolines-h", Vcomp_installed_trampolines_h,
5299 doc: /* Hash table subr-name -> bool. */); 5299 doc: /* Hash table subr-name -> installed trampoline.
5300This is used to prevent double trampoline instantiation but also to
5301protect the trampolines against GC. */);
5300 Vcomp_installed_trampolines_h = CALLN (Fmake_hash_table); 5302 Vcomp_installed_trampolines_h = CALLN (Fmake_hash_table);
5301 5303
5302 Fprovide (intern_c_string ("nativecomp"), Qnil); 5304 Fprovide (intern_c_string ("nativecomp"), Qnil);