Function: comp-finalize-relocs

comp-finalize-relocs is a byte-compiled function defined in comp.el.gz.

Signature

(comp-finalize-relocs)

Documentation

Finalize data containers for each relocation class.

Remove immediate duplicates within relocation classes. Update all insn accordingly.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/comp.el.gz
(defun comp-finalize-relocs ()
  "Finalize data containers for each relocation class.
Remove immediate duplicates within relocation classes.
Update all insn accordingly."
  ;; Symbols imported by C inlined functions.  We do this here because
  ;; is better to add all objs to the relocation containers before we
  ;; compacting them.
  (mapc #'comp-add-const-to-relocs '(nil t consp listp))

  (let* ((d-default (comp-ctxt-d-default comp-ctxt))
         (d-default-idx (comp-data-container-idx d-default))
         (d-impure (comp-ctxt-d-impure comp-ctxt))
         (d-impure-idx (comp-data-container-idx d-impure))
         (d-ephemeral (comp-ctxt-d-ephemeral comp-ctxt))
         (d-ephemeral-idx (comp-data-container-idx d-ephemeral)))
    ;; We never want compiled lambdas ending up in pure space.  A copy must
    ;; be already present in impure (see `comp-emit-lambda-for-top-level').
    (cl-loop for obj being each hash-keys of d-default-idx
             when (gethash obj (comp-ctxt-lambda-fixups-h comp-ctxt))
               do (cl-assert (gethash obj d-impure-idx))
                  (remhash obj d-default-idx))
    ;; Remove entries in d-impure already present in d-default.
    (cl-loop for obj being each hash-keys of d-impure-idx
             when (gethash obj d-default-idx)
               do (remhash obj d-impure-idx))
    ;; Remove entries in d-ephemeral already present in d-default or
    ;; d-impure.
    (cl-loop for obj being each hash-keys of d-ephemeral-idx
             when (or (gethash obj d-default-idx) (gethash obj d-impure-idx))
               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))
    ;; 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))
    ;; And now we conclude with the following: We need to pass to
    ;; `comp--register-lambda' the index in the impure relocation
    ;; array to store revived lambdas, but given we know it only now
    ;; we fix it up as last.
    (cl-loop for f being each hash-keys of (comp-ctxt-lambda-fixups-h comp-ctxt)
             using (hash-value mvar)
             with reverse-h = (make-hash-table) ;; Make sure idx is unique.
             for idx = (gethash f d-impure-idx)
             do
             (cl-assert (null (gethash idx reverse-h)))
             (cl-assert (fixnump idx))
             (setf (comp-mvar-valset mvar) ()
                   (comp-mvar-range mvar) (list (cons idx idx)))
             (puthash idx t reverse-h))))