emacs-diffs
[Top][All Lists]
Advanced

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

feature/native-comp bb4cf13 1/2: Convert before final function doc hash


From: Andrea Corallo
Subject: feature/native-comp bb4cf13 1/2: Convert before final function doc hash into a vector.
Date: Sun, 26 Apr 2020 05:40:20 -0400 (EDT)

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

    Convert before final function doc hash into a vector.
    
        * lisp/emacs-lisp/comp.el (comp-finalize-relocs): Convert doc hash
        table into vector befor final.
        (comp-emit-for-top-level): Rename `comp-ctxt-doc-index-h' ->
        `comp-ctxt-function-docs'.
        (comp-ctxt): Likewise.
    
        * src/comp.c (native_function_doc): Update logic for documentation
        being a vector.
        (emit_ctxt_code): Update for 'comp-ctxt-doc-index-h' slot rename.
    
        * src/comp.h (struct Lisp_Native_Comp_Unit): Rename 'data_fdoc_h'
        into data_fdoc_v.
    
        * src/pdumper.c (dump_native_comp_unit): Likewise.
---
 lisp/emacs-lisp/comp.el | 14 +++++++++++---
 src/comp.c              | 16 +++++++---------
 src/comp.h              |  2 +-
 src/pdumper.c           |  2 +-
 4 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index 5096a14..f8e30f0 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -216,7 +216,7 @@ Can be one of: 'd-default', 'd-impure' or 'd-ephemeral'.  
See `comp-ctxt'.")
   (sym-to-c-name-h (make-hash-table :test #'eq) :type hash-table
                    :documentation "symbol-function -> c-name.
 This is only for optimizing intra CU calls at speed 3.")
-  (doc-index-h (make-hash-table :test #'eql) :type hash-table
+  (function-docs (make-hash-table :test #'eql) :type (or hash-table vector)
                :documentation "Documentation index -> documentation")
   (d-default (make-comp-data-container) :type comp-data-container
              :documentation "Standard data relocated in use by functions.")
@@ -1218,7 +1218,7 @@ the annotation emission."
                           (make-comp-mvar :constant c-name)
                           (make-comp-mvar
                            :constant
-                           (let* ((h (comp-ctxt-doc-index-h comp-ctxt))
+                           (let* ((h (comp-ctxt-function-docs comp-ctxt))
                                   (i (hash-table-count h)))
                              (puthash i (comp-func-doc f) h)
                              i))
@@ -2103,7 +2103,15 @@ Update all insn accordingly."
                do (remhash obj d-ephemeral-idx))
     ;; Fix-up indexes in each relocation class and fill corresponding
     ;; reloc lists.
-    (mapc #'comp-finalize-container (list d-default d-impure d-ephemeral))))
+    (mapc #'comp-finalize-container (list d-default d-impure d-ephemeral))
+    ;; Make a vector from the function documentation hash table.
+    (cl-loop with h = (comp-ctxt-function-docs comp-ctxt)
+             with v = (make-vector (hash-table-count h) nil)
+             for idx being each hash-keys of h
+             for doc = (gethash idx h)
+             do (setf (aref v idx) doc)
+             finally
+             do (setf (comp-ctxt-function-docs comp-ctxt) v))))
 
 (defun comp-compile-ctxt-to-file (name)
   "Compile as native code the current context naming it NAME.
diff --git a/src/comp.c b/src/comp.c
index b33ef92..d021be4 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -2102,7 +2102,7 @@ emit_ctxt_code (void)
   emit_static_object (TEXT_OPTIM_QLY_SYM, Flist (2, opt_qly));
 
   emit_static_object (TEXT_FDOC_SYM,
-                     CALL1I (comp-ctxt-doc-index-h, Vcomp_ctxt));
+                     CALL1I (comp-ctxt-function-docs, Vcomp_ctxt));
 
   comp.current_thread_ref =
     gcc_jit_lvalue_as_rvalue (
@@ -3677,14 +3677,12 @@ native_function_doc (Lisp_Object function)
   struct Lisp_Native_Comp_Unit *cu =
     XNATIVE_COMP_UNIT (Fsubr_native_comp_unit (function));
 
-  if (NILP (cu->data_fdoc_h))
-    cu->data_fdoc_h = load_static_obj (cu, TEXT_FDOC_SYM);
-
-  eassert (!NILP (cu->data_fdoc_h));
-
-  return Fgethash (make_fixnum (XSUBR (function)->doc),
-                  cu->data_fdoc_h,
-                  Qnil);
+  if (NILP (cu->data_fdoc_v))
+    cu->data_fdoc_v = load_static_obj (cu, TEXT_FDOC_SYM);
+  if (!VECTORP (cu->data_fdoc_v))
+    xsignal2 (Qnative_lisp_file_inconsistent, cu->file,
+             build_string ("missing documentation vector"));
+  return AREF (cu->data_fdoc_v, XSUBR (function)->doc);
 }
 
 DEFUN ("comp--register-subr", Fcomp__register_subr, Scomp__register_subr,
diff --git a/src/comp.h b/src/comp.h
index 73baa27..cbdcacc 100644
--- a/src/comp.h
+++ b/src/comp.h
@@ -38,7 +38,7 @@ struct Lisp_Native_Comp_Unit
   Lisp_Object file;
   Lisp_Object optimize_qualities;
   /* Hash doc-idx -> function documentaiton. */
-  Lisp_Object data_fdoc_h;
+  Lisp_Object data_fdoc_v;
   /* Analogous to the constant vector but per compilation unit.  */
   Lisp_Object data_vec;
   /* Same but for data that cannot be moved to pure space.
diff --git a/src/pdumper.c b/src/pdumper.c
index c9015d5..f837dfc 100644
--- a/src/pdumper.c
+++ b/src/pdumper.c
@@ -2982,7 +2982,7 @@ dump_native_comp_unit (struct dump_context *ctx,
                       struct Lisp_Native_Comp_Unit *comp_u)
 {
   /* Have function documentation always lazy loaded to optimize load-time.  */
-  comp_u->data_fdoc_h = Qnil;
+  comp_u->data_fdoc_v = Qnil;
   START_DUMP_PVEC (ctx, &comp_u->header, struct Lisp_Native_Comp_Unit, out);
   dump_pseudovector_lisp_fields (ctx, &out->header, &comp_u->header);
   out->handle = NULL;



reply via email to

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