emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/native-comp f8b07ff 1/2: Guard against function redefinition dur


From: Andrea Corallo
Subject: feature/native-comp f8b07ff 1/2: Guard against function redefinition during deferred load
Date: Mon, 23 Mar 2020 16:58:57 -0400 (EDT)

branch: feature/native-comp
commit f8b07ff4f318d799a471c9363903e3929fd5c844
Author: Andrea Corallo <address@hidden>
Commit: Andrea Corallo <address@hidden>

    Guard against function redefinition during deferred load
---
 lisp/emacs-lisp/comp.el | 10 ++++++++--
 src/comp.c              | 39 +++++++++++++++++++++++++++++++--------
 2 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index 273b41f..c6f2ca13 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -1160,12 +1160,15 @@ the annotation emission."
 (cl-defgeneric comp-emit-for-top-level (form for-late-load)
   "Emit the limple code for top level FORM.")
 
-(cl-defmethod comp-emit-for-top-level ((form byte-to-native-function) _)
+(cl-defmethod comp-emit-for-top-level ((form byte-to-native-function)
+                                       for-late-load)
   (let* ((name (byte-to-native-function-name form))
          (f (gethash name (comp-ctxt-funcs-h comp-ctxt)))
          (args (comp-func-args f)))
     (cl-assert (and name f))
-    (comp-emit (comp-call 'comp--register-subr
+    (comp-emit (comp-call (if for-late-load
+                              'comp--late-register-subr
+                            'comp--register-subr)
                           (make-comp-mvar :constant name)
                           (make-comp-mvar :constant (comp-args-base-min args))
                           (make-comp-mvar :constant (if (comp-args-p args)
@@ -2186,6 +2189,9 @@ display a message."
         (save-excursion
           (goto-char (point-max))
           (insert msg "\n")))
+      ;; `comp-deferred-pending-h' should be empty at this stage.
+      ;; Reset it anyway.
+      (setf comp-deferred-pending-h (make-hash-table :equal #'eq))
       (message msg))))
 
 
diff --git a/src/comp.c b/src/comp.c
index b563f27..3205a29 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -3401,14 +3401,16 @@ maybe_defer_native_compilation (Lisp_Object 
function_name,
   Lisp_Object src =
     concat2 (CALL1I (file-name-sans-extension, Vload_file_name),
             build_pure_c_string (".el"));
-  if (!NILP (Ffile_exists_p (src)))
-    {
-      comp_deferred_compilation = false;
-      Frequire (intern_c_string ("comp"), Qnil, Qnil);
-      comp_deferred_compilation = true;
-      CALLN (Ffuncall, intern_c_string ("native-compile-async"), src, Qnil,
-            Qlate);
-    }
+  if (NILP (Ffile_exists_p (src)))
+    return;
+
+  /* Really happening.  */
+  Fputhash (function_name, definition, Vcomp_deferred_pending_h);
+  comp_deferred_compilation = false;
+  Frequire (intern_c_string ("comp"), Qnil, Qnil);
+  comp_deferred_compilation = true;
+  CALLN (Ffuncall, intern_c_string ("native-compile-async"), src, Qnil,
+        Qlate);
 }
 
 
@@ -3584,6 +3586,21 @@ DEFUN ("comp--register-subr", Fcomp__register_subr, 
Scomp__register_subr,
   return Qnil;
 }
 
+DEFUN ("comp--late-register-subr", Fcomp__late_register_subr,
+       Scomp__late_register_subr, 7, 7, 0,
+       doc: /* This gets called by late_top_level_run during load
+              phase to register each exported subr.  */)
+     (Lisp_Object name, Lisp_Object minarg, Lisp_Object maxarg,
+      Lisp_Object c_name, Lisp_Object doc, Lisp_Object intspec,
+      Lisp_Object comp_u)
+{
+  if (!NILP (Fequal (Fsymbol_function (name),
+                    Fgethash (name, Vcomp_deferred_pending_h, Qnil))))
+    Fcomp__register_subr (name, minarg, maxarg, c_name, doc, intspec, comp_u);
+  Fremhash (name, Vcomp_deferred_pending_h);
+  return Qnil;
+}
+
 /* Load related routines.  */
 DEFUN ("native-elisp-load", Fnative_elisp_load, Snative_elisp_load, 1, 2, 0,
        doc: /* Load native elisp code FILE.
@@ -3714,6 +3731,7 @@ syms_of_comp (void)
   defsubr (&Scomp__release_ctxt);
   defsubr (&Scomp__compile_ctxt_to_file);
   defsubr (&Scomp__register_subr);
+  defsubr (&Scomp__late_register_subr);
   defsubr (&Snative_elisp_load);
 
   staticpro (&comp.exported_funcs_h);
@@ -3742,6 +3760,11 @@ syms_of_comp (void)
   DEFVAR_LISP ("comp-native-path-postfix", Vcomp_native_path_postfix,
               doc: /* Postifix to be added to the .eln compilation path.  */);
   Vcomp_native_path_postfix = Qnil;
+
+  DEFVAR_LISP ("comp-deferred-pending-h", Vcomp_deferred_pending_h,
+              doc: /* Hash table symbol-name -> function-value.  For
+                      internal use during  */);
+  Vcomp_deferred_pending_h = CALLN (Fmake_hash_table, QCtest, Qeq);
 }
 
 #endif /* HAVE_NATIVE_COMP */



reply via email to

[Prev in Thread] Current Thread [Next in Thread]