To Ahead of Time compile the whole Emacs distro define NATIVE_FULL_AOT
when invoking make ex: 'make NATIVE_FULL_AOT=1'.
* lisp/Makefile.in (NATIVE_SKIP_NONDUMP): New variable.
(compile-main): Use it + rename NATIVE_DISABLE -> NATIVE_DISABLED.
* lisp/emacs-lisp/comp.el
(batch-byte-native-compile-for-bootstrap): Rename NATIVE_DISABLE
-> NATIVE_DISABLED.
When recompiling remove the corresponding stale elns found in the
`comp-eln-load-path'.
When removing a package remove the corresponding elns too.
On Windows both of these are performed only when possible, when it's
not the file is renamed as .eln.old and a last attempt to remove this
is performed closing the Emacs session. When a file being deleted was
loaded by multiple Emacs sessions the last one being closed should
delete it.
* lisp/emacs-lisp/comp.el (comp-clean-up-stale-eln): New function.
(comp-delete-or-replace-file): Rename from
`comp--replace-output-file' and update so it can be used for
replacing or deleting shared libs safetly.
* lisp/emacs-lisp/package.el (package--delete-directory): When
native compiled just call `comp-clean-up-stale-eln' for each
eln file we want to clean-up.
* src/alloc.c (cleanup_vector): Call directly the dynlib_close.
* src/comp.c (syms_of_comp): Update for comp_u->cfile removal.
Make 'all_loaded_comp_units_h' key-value weak as now the key will
be the filename.
(load_comp_unit): Register the compilation unit only when the load
is fully completed.
(register_native_comp_unit): Make the key of
all_loaded_comp_units_h the load filename.
(eln_load_path_final_clean_up): New function.
(dispose_comp_unit)
(finish_delayed_disposal_of_comp_units)
(dispose_all_remaining_comp_units)
(clean_package_user_dir_of_old_comp_units): Remove.
(Fcomp__compile_ctxt_to_file): Update for
`comp--replace-output-file' -> `comp-delete-or-replace-file'
rename.
* src/comp.h (dispose_comp_unit)
(finish_delayed_disposal_of_comp_units)
(dispose_all_remaining_comp_units)
(clean_package_user_dir_of_old_comp_units): Remove.
(eln_load_path_final_clean_up): Add.
(struct Lisp_Native_Comp_Unit): Remove cfile field.
* src/emacs.c (Fkill_emacs): Call 'eln_load_path_final_clean_up'.
* src/pdumper.c (dump_do_dump_relocation): Do not set comp_u->cfile.
Add a customizable variable for driver options (such as linker flags)
to pass to libgccjit (Bug #42761).
* lisp/emacs-lisp/comp.el (comp-native-driver-options): New
customization variable.
* src/comp.c: Use comp-native-driver-options to set libgccjit's driver
options, if supported on the library's ABI version.
This is needed for installed instances compiled with NATIVE_FAST_BOOT
* src/comp.c (maybe_defer_native_compilation): Search for .el.gz
too as a source if the .el is not found.
(Fcomp_el_to_eln_filename): Remove the .gz in case to
generate the hash.
* lisp/emacs-lisp/comp.el (comp-valid-source-re): New defconst.
(comp-run-async-workers, native-compile-async): Make use of
`comp-valid-source-re'.
Prevent autoload to kicks in while running `native-compile-async'.
Autoload cannot be used safely by functions serving deferred
compilation as a circular load can be triggered if the dependency is
not native compiled already.
* lisp/emacs-lisp/comp.el (warnings): Add require.
* src/comp.c (comp_deferred_compilation): Doc update and set it to
true by default.
* lisp/emacs-lisp/comp.el (comp-deferred-compilation): Remove
customize.
When loading a elc file search for a corresponding eln one into
`comp-eln-load-path' directories and load it if available.
`comp-eln-load-path' contains by default two directory (user and
system one).
* src/pdumper.c (dump_do_dump_relocation): While resurrecting from
load set eln cache sys dir in `Vcomp_eln_load_path'.
* src/lread.c (maybe_swap_for_eln): New function.
(Fload): Clean-up some now unnecessary code going
back to the master one.
(Fload): Make use of Vcomp_eln_to_el_h for the reverse file
look-up.
(openp_add_middle_dir_to_suffixes)
(openp_max_middledir_and_suffix_len, openp_fill_filename_buffer):
Remove functions.
(openp): As for Fload revert code modifications.
(openp): When a .elc file is being loaded check if a corresponding
eln can be loaded in place.
* src/comp.c (ELN_FILENAME_HASH_LEN): New macro.
(comp_hash_string): New function.
(hash_native_abi): Make use of 'comp_hash_string'.
(hash_native_abi): Change `comp-native-path-postfix' format.
(Fcomp_el_to_eln_filename): New function.
(Fcomp__compile_ctxt_to_file): Have file_name as a input.
(Vcomp_eln_to_el_h, Vcomp_eln_load_path): New global varaibles.
* lisp/startup.el (normal-top-level): Add user eln cache directory
in `comp-eln-load-path'.
* lisp/help-fns.el (find-lisp-object-file-name): Reverse look-up
files using `comp-eln-to-el-h'.
* lisp/files.el (locate-file): Likewise.
* lisp/emacs-lisp/find-func.el (find-library-name): Likewise.
* lisp/emacs-lisp/comp.el (comp-output-directory)
(comp-output-base-filename, comp-output-filename): Remove function.
(comp-compile-ctxt-to-file): Create parent directories if
necessary.
(comp-run-async-workers, native-compile, native-compile-async):
Make use `comp-el-to-eln-filename'.
* lisp/emacs-lisp/comp.el (comp-ensure-native-compiler): New function.
(native-compile, batch-native-compile)
(batch-byte-native-compile-for-bootstrap, native-compile-async):
Make use of `comp-ensure-native-compiler'.
* lisp/emacs-lisp/comp.el (comp-limple-lock-keywords): New const.
(comp-limple-mode): New major mode.
(comp-log-to-buffer): Enable `comp-limple-mode' in the log buffer.
* lisp/emacs-lisp/comp.el (comp-passes): Rename `comp-propagate'
-> `comp-fwprop'.
(comp-fwprop-prologue): Rename from `comp-propagate-prologue'.
(comp-fwprop-insn): Rename from `comp-fwprop-insn'.
(comp-propagate*): Rename from `comp-propagate*' and update.
(comp-fwprop): Rename from `comp-propagate' and update.
Add a simple pass to infer pure functions not explicitly declared as
such. Use this information only during compilation (speed 3) to
optimize out function calls whe possible.
* lisp/emacs-lisp/comp.el (comp-c-func-name): Add FIRST argument
to ignore the compiler context and return the first name.
* lisp/emacs-lisp/disass.el (disassemble-internal): Update the
`comp-c-func-name' call.
Lambda-lists must stay in the same relocation class of the object
referenced by code to respect uninterned symbols.
* lisp/emacs-lisp/comp.el (comp-prepare-args-for-top-level): Break
the original function in a generic specializing for
dynamic/lexical functions. When allocating the lambda-list for
dynamic functions do that in the default relocation class.
(comp-emit-for-top-level): Make use of the new
`comp-prepare-args-for-top-level'.
(comp-emit-lambda-for-top-level): Likewise.
* lisp/emacs-lisp/comp.el (comp-func): New slot 'pure'.
(comp-spill-decl-spec): New function.
(comp-spill-speed): Rework to use the later.
(comp-spill-lap-function, comp-intern-func-in-ctxt): Spill pure
decl value.
(comp-function-optimizable-p): Check in the compiler env too if
pure.
* src/comp.c (COMP_SPEED): Rename.
(comp_t): Add 'func_speed' field.
(emit_mvar_lval, compile_function): Update for per function speed.
(Fcomp__compile_ctxt_to_file): COMP_SPEED renamed.
* lisp/emacs-lisp/comp.el (comp-speed): Doc update.
(comp-func): New 'speed' slot.
(comp-spill-speed): New function.
(comp-spill-lap-function, comp-intern-func-in-ctxt): Fill 'speed'
slot.
(comp-spill-lap-function): Gate -1 speed functions for native
compilation and emit bytecode instead.
(comp-spill-lap): Close over `byte-to-native-plist-environment'.
(comp-latch-make-fill): Update for per function speed.
(comp-limplify-top-level): Fill speed.
(comp-propagate1, comp-call-optim-form-call, comp-call-optim)
(comp-dead-code, comp-tco, comp-remove-type-hints): Update for per
function speed.
Add an initial implementation to support dynamic scope. Arg
parsing/binding it's done using the existing code in use for
bytecode (no ad-hoc code is synthetized for that).
* src/lisp.h (struct Lisp_Subr): Add lambda_list field.
(SUBR_NATIVE_COMPILED_DYNP): New inliner.
* src/alloc.c (mark_object): Update for Add lambda_list field.
* src/eval.c (eval_sub, Ffuncall, funcall_lambda): Handle native
compiled dynamic scope
* src/comp.c (declare_lex_function): Rename from declare_function
and rework.
(declare_function): New function.
(make_subr): Handle daynamic scope
* src/pdumper.c (dump_subr): Update for lambda_list field.
* lisp/emacs-lisp/comp.el (comp-func): Remove args slot.
(comp-func-l, comp-func-d): New classes deriving from `comp-func'.
(comp-spill-lap-function): Rework.
(comp-prepare-args-for-top-level): New function.
(comp-emit-for-top-level, comp-emit-lambda-for-top-level): Make
use of `comp-prepare-args-for-top-level'.
(comp-limplify-top-level): Use `comp-func-l'.
(comp-limplify-function): Emit arg prologue only for dynamic
scoped functions.
(comp-call-optim-form-call): Use `comp-func-l'.
(comp-call-optim, comp-tco): Do not optimize dynamic scoped code.
Define a new kind of basic block 'latch' to close over loops. Its
purpose is for now to emit calls to `comp-maybe-gc-or-quit' but in
future will be usefull for the loop optimizer to exploit unboxes.
* lisp/emacs-lisp/comp.el (comp-block): New base class.
(comp-block-lap): New class for LAP derived basic blocks.
(comp-latch): New class.
(comp-bb-maybe-add, comp-make-curr-block, comp-emit-handler)
(comp-emit-switch, comp-emit-switch, comp-limplify-top-level)
(comp-addr-to-bb-name, comp-limplify-block)
(comp-limplify-function): Update logic for new bb objects
arrangment.
(comp-latch-make-fill): New function.
(comp-emit-uncond-jump, comp-emit-cond-jump): Update to emit
latches.
(comp-new-block-sym): Add a postfix paramenter.
As function folding can generate 'setimm' insns handle them in the
`comp-propagate-insn'.
* lisp/emacs-lisp/comp.el (comp-propagate-insn): Handle 'setimm'
insn.
* 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.