* lisp/emacs-lisp/comp.el (comp-symbol-values-optimizable): New
defconst.
(comp-function-call-maybe-remove): New logic to to remove
unnecessary `symbol-value' calls.
Do not perform trampoline optimization at speed 3 on function if their
name is not unique inside the compilation unit. Note that the
function can still be redefined in any other way therefore this is a
mitigation.
* lisp/emacs-lisp/comp.el (comp-func-unique-in-cu-p): New
predicate.
(comp-call-optim-form-call): Perform trampoline optimization
for named functions only if they are unique within the current
compilation unit.
Is cleaner to have the function c-name as first argument of
'direct-call' 'direct-callref'. This is preparatory to anonymous
lambdas optimization.
* lisp/emacs-lisp/comp.el (comp-propagate-insn): Use c-name when
gathering the comp-func definition for direct calls.
(comp-call-optim-form-call): Add put c-name as first argument of
direct-call direct-callref when optimizing.
* src/comp.c (emit_call): Update logic for having c-name as
first arg of direct calls.
(emit_call_ref): Rename 'subr_sym' into 'func'.
* lisp/emacs-lisp/comp.el (comp-loop-insn-in-block): New macro.
(comp-call-optim-func, comp-dead-assignments-func)
(comp-remove-type-hints-func): Use `comp-loop-insn-in-block'.
Given SSA prop overwrite mvar type slot we clean-up the compiler type
hints as last.
* lisp/emacs-lisp/comp.el (comp-passes): Add comp-remove-type-hints.
(comp-remove-type-hints-func): Code move.
(comp-dead-code): Do not call `comp-remove-type-hints-func'.
(comp-remove-type-hints): Add as new pass.
When closing emacs will inspect all directories from which it loaded
native compilation units. If it finds a ".eln.old" file it will try to
delete it, if it fails that means that another Emacs instance is using it.
When compiling a file we rename the file that was in the output path
in case it has been loaded into another Emacs instance.
When deleting a package we move any ".eln" or ".eln.old" files in the
package folder that we can't delete to `package-user-dir`. Emacs will
check that directory when closing and delete them.
* lisp/emacs-lisp/comp.el (comp--replace-output-file): Function called
from C code to finish the compilation process. It performs renaming of
the old file if necessary.
* lisp/emacs-lisp/package.el (package--delete-directory): Function to
delete a package directory. It moves native compilation units that it
can't delete to `package-user-dir'.
* src/alloc.c (cleanup_vector): Call dispose_comp_unit().
(garbage_collect): Call finish_delayed_disposal_of_comp_units().
* src/comp.c: Restore the signal mask using unwind-protect. Store
loaded native compilation units in a hash table for disposal on
close. Store filenames of native compilation units GC'd in a linked
list to finish their disposal when the GC is over.
(clean_comp_unit_directory): Delete all *.eln.old files in a
directory.
(clean_package_user_dir_of_old_comp_units): Delete all *.eln.old files
in `package-user-dir'.
(dispose_all_remaining_comp_units): Dispose of native compilation
units that are still loaded.
(dispose_comp_unit): Close handle and cleanup directory or arrange for
later cleanup if DELAY is true.
(finish_delayed_disposal_of_comp_units): Dispose of native compilation
units that were GC'd.
(register_native_comp_unit): Register native compilation unit for
disposal when Emacs closes.
* src/comp.h: Introduce cfile member in Lisp_Native_Comp_Unit.
Add declarations of functions that: clean directories of unused native
compilation units, handle disposal of native compilation units.
* src/emacs.c (kill-emacs): Dispose all remaining compilation units
right right before calling exit().
* src/eval.c (internal_condition_case_3, internal_condition_case_4):
Add functions.
* src/lisp.h (internal_condition_case_3, internal_condition_case_4):
Add functions.
* src/pdumper.c (dump_do_dump_relocation): Set cfile to a copy of the
Lisp string specifying the file path.
* lisp/emacs-lisp/comp.el (comp-effective-async-max-jobs): Use
NUMBER_OF_PROCESSORS environment variable if system is Windows NT,
"nproc" if it is in PATH or a default of 1.
* lisp/emacs-lisp/comp.el (comp-run-async-workers): Pass the
compilation commands through a temporary file that is loaded by the
child process. This is also done all other operating systems, even
those that support long command lines. It should not be a problem
since libgccjit uses temporary files too.
* lisp/emacs-lisp/comp.el (comp-num-cpus): New special variable.
(comp-effective-async-max-jobs): Make use of `comp-num-cpus'.
(comp-call-optim-form-call): Remove unnecessary parameter.
(comp-call-optim-func): Reflect `comp-call-optim-form-call'
parameter removal.
* lisp/emacs-lisp/comp.el (comp-never-optimize-functions):
Blacklist all primitives advised by evil-mode from trampoline
optimization.
(comp-call-optim-form-call): Prevent trampoline optimization for
recursive calls at speed 2 to respect elisp original semantic.
* lisp/emacs-lisp/comp.el (comp-lex-byte-func-p): New subst.
(comp-intern-func-in-ctxt): Do not crash if we still encounter a
non lexical scoped lambda.
* src/pdumper.c (dump_do_dump_relocation): While fixing up lambda
relocation verify placeholder coherency.
* src/comp.c (syms_of_comp): Define symbol 'lambda-fixup'.
* lisp/emacs-lisp/comp.el (comp-finalize-container): Leave a
lambda-fixup as placeholder in the relocation as a sanity check.
* lisp/emacs-lisp/comp.el (comp-spill-lap-function): Move code
from to comp-intern-func-in-ctxt.
(comp-intern-func-in-ctxt): New function, this guard
in case byte-to-native-lambda-byte-func is nil.
* lisp/emacs-lisp/comp.el (comp-spill-lap-function): Make use of
byte-to-native-lambdas-h and update for 'byte-to-native-func-def'.
(comp-spill-lap-function): Rework logic to retrive LAP using
'byte-to-native-lambdas-h'.
(comp-emit-for-top-level): Update for 'byte-to-native-function'.
* lisp/emacs-lisp/bytecomp.el: Add commentary on new spill LAP
mechanism.
(byte-to-native-lambda, byte-to-native-func-def): New structures.
(byte-to-native-top-level): Indent.
(byte-to-native-lambdas-h): Update doc.
(byte-compile-lapcode): Add a 'byte-to-native-lambda' instance
into byte-to-native-lambdas-h instead of just LAP.
(byte-compile-file-form-defmumble): Store into
'byte-to-native-func-def' only the byte compiled function, the LAP
will be retrived through 'byte-to-native-lambdas-h'.
(byte-compile-lambda): Return the byte compiled function.
* lisp/emacs-lisp/comp.el (comp-deferred-compilation-black-list):
New customize.
(native-compile-async): Make use of
'comp-deferred-compilation-black-list'.
* lisp/emacs-lisp/comp.el (comp-bootstrap-black-list): New customize.
(batch-native-compile): Rework to make use of
'comp-bootstrap-black-list'.
(batch-byte-native-compile-for-bootstrap): Add assertion to make
logic assumption explicit.
* lisp/emacs-lisp/comp.el (comp-spill-lap-function): No need anymore
to have `byte-native-compiling' bound to free-func.
(comp-spill-lap-function): Make use of `byte-to-native-lap-h' and
clean-up.
(comp-spill-lap-function): Likewise.
* lisp/emacs-lisp/bytecomp.el (byte-to-native-function): Add lap slot.
(byte-to-native-lap): Rename into byte-to-native-lap-h.
(byte-compile-lapcode): Spill lap after having int assembled and
store it into `byte-to-native-lap-h'.
(byte-compile-not-top-level): Remove.
(byte-compile-file-form-defmumble): Fill directly lap slot.
(byte-compile-lambda): Remove `byte-compile-not-top-level'.
(byte-compile-out-toplevel): Restore original code.
(byte-compile-form): Remove `byte-compile-not-top-level'.
(byte-compile-function-form): Likewise.
(byte-compile-flush-pending): No need anymore to set
`byte-compile-current-form' so restore orignal code.
* src/pdumper.c (dump_subr): Update Lisp_Subr hash.
(dump_subr): Update for new compilation unit layout.
(dump_vectorlike): Update pvec_type hash.
* src/lisp.h (struct Lisp_Subr): Remove 'native_doc' index.
(DEFUN): Update macro for new compilation unit
layout.
* src/doc.c (Fdocumentation): Update for new compilation unit
layout.
* src/comp.h (struct Lisp_Native_Comp_Unit):
Add 'data_fdoc_h' field.
* src/comp.c (TEXT_FDOC_SYM): New macro.
(emit_ctxt_code): Emit function documentations.
(load_comp_unit): Load function documentation.
(Fcomp__register_subr): Rename parameter.
(Fcomp__register_subr): Update for new compilation unit
layout.
* src/alloc.c (mark_object): Update for new compilation unit
layout.
(syms_of_alloc): Likewise.
* lisp/emacs-lisp/comp.el (comp-ctxt): Add doc-index-h slot.
(comp-emit-for-top-level): Emit doc index as 'comp--register-subr'
doc parameter.
* lisp/emacs-lisp/comp.el (comp-async-processes): Rename as
`comp-async-compilations'.
(comp-async-runnings): Make use as `comp-async-compilations'.
(comp-run-async-workers): Likewise.