Commit graph

652 commits

Author SHA1 Message Date
Andrea Corallo
89f064104c * Some clean-up in comp.el
* lisp/emacs-lisp/comp.el (comp-emit-cond-jump, comp-emit-switch)
	(comp-limplify-block, comp-compute-edges)
	(comp-ssa-rename, comp-fwprop*, comp-effective-async-max-jobs)
	(comp-run-async-workers): Respect max 80 columns.
	(batch-byte-native-compile-for-bootstrap): Improve doc + remove
	some now unnecessary error handling.
2020-09-29 17:14:22 +02:00
Andrea Corallo
3129b3ffcb Rename in docstrings "non nil" into "non-nil"
* lisp/emacs-lisp/comp.el: Rename non nil -> non-nil in doc.

	* src/comp.c: Likewise.
2020-09-28 21:09:00 +02:00
Andrea Corallo
e5b052d60d Rename comp--subr-safe-advice -> comp-subr-safe-advice
* lisp/emacs-lisp/comp.el (comp-subr-safe-advice): Rename
	comp--subr-safe-advice -> comp-subr-safe-advice.
	* lisp/emacs-lisp/nadvice.el (advice--add-function): Likewise.
	* lisp/emacs-lisp/advice.el (ad-add-advice): Likewise.
2020-09-24 09:57:17 +02:00
Andrea Corallo
6d83902ffd * lisp/emacs-lisp/comp.el (comp-body-eff): Improve style. 2020-09-24 09:57:17 +02:00
Andrea Corallo
94736c413f Do not install a subr trampoline twice
* src/comp.c (syms_of_comp): Define and initialize
	'Vcomp_installed_trampolines_h'.
	(Fcomp__install_trampoline): Fill 'Vcomp_installed_trampolines_h'
	* lisp/emacs-lisp/comp.el (comp--subr-safe-advice): Make use of
	`comp-installed-trampolines-h' to guard against installing a
	trampoline twice.
2020-09-24 09:57:17 +02:00
Andrea Corallo
b94a0a931e * lisp/emacs-lisp/comp.el (comp-never-optimize-functions): Clean-up. 2020-09-24 09:57:17 +02:00
Andrea Corallo
3ec1b932c9 * Add `comp--subr-safe-advice' entry point
Add a Lisp side entry-point to be called to make primitive adivicing
effective.

	* lisp/emacs-lisp/comp.el (comp-trampoline-sym)
	(comp-trampoline-filename): New substs.
	(comp-make-lambda-list-from-subr, comp-search-trampoline)
	(comp-tampoline-compile): New functions
2020-09-24 09:57:17 +02:00
Andrea Corallo
9d4fd669cf * lisp/emacs-lisp/comp.el (comp-final): Log when interactively invoked. 2020-09-23 20:48:23 +02:00
Andrea Corallo
63c65b4fe0 * lisp/emacs-lisp/comp.el (native-compile): Add OUTPUT parameter. 2020-09-23 20:47:34 +02:00
Andrea Corallo
69c32e0187 * Sandbox syncronous libgccjit invocation on interactive sessions
Avoid unnecessary memory fragmentation/leakeage

	* lisp/emacs-lisp/comp.el (comp-final1): New function.
	(comp-final): Invoke `comp-final1' in a child process if in an
	interactive session or directly otherwhise.
2020-09-21 21:46:07 +02:00
Andrea Corallo
e972837576 * Fix free function compilation load process.
* lisp/emacs-lisp/comp.el (comp-clean-up-stale-eln): Do not crash
	if the eln filename is not canonical (tmp file or manual load).
2020-09-14 23:06:42 +02:00
Andrea Corallo
82171a8f0d * Add gv-setters for compiler hints
* lisp/emacs-lisp/comp.el (comp-hint-fixnum, comp-hint-cons): Add
	gv-setters so type hinted expressions can be used as places.
	Read we can now have like: '(cl-incf (cl-the fixnum x))'.
2020-09-14 23:06:42 +02:00
Andrea Corallo
2da2ad29b8 * lisp/emacs-lisp/comp.el (comp-sp): Better style gv-setter declaration. 2020-09-14 23:06:42 +02:00
Andrea Corallo
a3dc11e9cc * Remove type check emission from type hints low level primitives
These have to be emitted by higher level primitves as `cl-the'.

	* lisp/emacs-lisp/comp.el (comp-hint-fixnum, comp-hint-cons): Do
	not emit type checks.
2020-09-14 23:06:42 +02:00
Andrea Corallo
3c58403b0f By default when building native compile only what's part of the dump image
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.
2020-09-11 11:01:11 +02:00
Andrea Corallo
dc4b50ce0b * Do not crash compilation if user eln-cache wasn't already created.
* lisp/emacs-lisp/comp.el (comp-clean-up-stale-eln): Guard
	against calling `directory-files' on non existent directories.
2020-09-07 23:18:36 +02:00
Andrea Corallo
a71f54eff8 Rework eln deletion strategy for new eln-cache folder structure
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.
2020-09-06 18:17:00 +02:00
Andrea Corallo
bce9cad421 * Store raw documentation during native compilation (bug#42974)
* lisp/emacs-lisp/comp.el (comp-spill-lap-function)
	(comp-intern-func-in-ctxt): Use raw documentation.
2020-08-30 10:23:49 +02:00
Andrea Corallo
aa526c9470 Merge branch 'add_driver_option' into HEAD 2020-08-26 21:40:00 +02:00
Andreas Fuchs
2772e835b6 Set native driver options in async compiles, also
Ensure the variable is set to the value that was customized in the
parent process in child compilation processes, also.
2020-08-26 21:25:45 +02:00
Andrea Corallo
337367a733 * lisp/emacs-lisp/comp.el (native-compile): Fix free function compilation. 2020-08-23 12:58:52 +02:00
Andreas Fuchs
bec2adebc6 Pass driver options to libgccjit where supported
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.
2020-08-19 17:12:21 +02:00
Andrew Whatson
fc9b68636b * Fix async compilation `comp-eln-load-path' effectiveness (bug#42909)
* lisp/emacs-lisp/comp.el (comp-run-async-workers): Forward
	`comp-eln-load-path' to async workers.
2020-08-18 11:34:27 +02:00
Andrea Corallo
da54406077 Allow for native compiling .el.gz files
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'.
2020-08-17 18:04:23 +02:00
Andrea Corallo
b6238d826e * Deferred compilation must always compile despite source file timestamp
* lisp/emacs-lisp/comp.el (comp-run-async-workers): Always compile
	if load is set.
2020-08-17 18:04:23 +02:00
Andrea Corallo
377ffdb528 * Do not fail if more then one level of directories has to be created
* lisp/emacs-lisp/comp.el (native-compile-async): Call
	make-directory if necessary.
2020-08-17 18:04:22 +02:00
Andrea Corallo
df774c4947 * Prevent recursive load
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.
2020-08-17 18:04:22 +02:00
Andrea Corallo
88b860ef6c Make comp-deferred-compilation a simple global and set it on by default
* 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.
2020-08-17 18:04:22 +02:00
Andrea Corallo
3224a44306 Move eln files into dedicated cache directories
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'.
2020-08-17 18:04:22 +02:00
Andrea Corallo
3882e8fd24 * Fix excessive echo area usage
* lisp/emacs-lisp/comp.el (comp-run-async-workers): Use
	`with-temp-file' to fill temp-file.
2020-08-14 08:33:07 +02:00
Andrea Corallo
f6502f9592 ; * lisp/emacs-lisp/comp.el (comp-deferred-compilation): Fix doc. 2020-08-13 12:21:28 +02:00
Andrea Corallo
6c108e44c9 * Add `comp-ensure-native-compiler' guarding entry points
* 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'.
2020-07-26 09:36:09 +02:00
Andrea Corallo
4c46f8bac0 * Add a simple major mode for coloring LIMPLE in the log buffer
* 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.
2020-07-15 09:34:16 +02:00
Andrea Corallo
eb091c8647 * Rename comp-propagate' into fw-prop'
* 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.
2020-07-13 14:44:29 +02:00
Andrea Corallo
36c289ec8b * Clean-up now unnecessary backward propagation in comp.el
* lisp/emacs-lisp/comp.el (comp-passes): Invoke 'comp-propagate'
	instead of 'comp-propagate-alloc'.
	(comp-mvar): Remove unnecessary `array-idx' slot.
	(comp-propagate-prologue): Remove.
	(comp-propagate-prologue): Remove `backward' parameter and
	backward propagation logic.
	(comp-propagate1): Remove and move logic into `comp-propagate'.
	(comp-propagate-alloc): Remove pass.
2020-07-13 14:40:07 +02:00
Andrea Corallo
9aaca828fc * Add `comp-disabled-passes'
* lisp/emacs-lisp/comp.el (comp-disabled-passes): New special
	variable.
	(native-compile): Make use of `comp-disabled-passes'.
2020-07-09 16:23:34 +01:00
Andrea Corallo
b4de6baa7b * Optimize pure functions defined by the compilation environment
* lisp/emacs-lisp/comp.el (comp-apply-in-env): New macro.
	(comp-function-call-maybe-remove): Update to make use of
	`comp-apply-in-env'.
2020-07-09 16:22:48 +01:00
Andrea Corallo
7622740e29 * Introduce a new pass ipa-pure
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.
2020-07-09 16:22:48 +01:00
Andrea Corallo
5688739c5b * Add `comp-call-op-p'
* lisp/emacs-lisp/comp.el (comp-call-op-p): New predicate.
	(comp-limple-insn-call-p): Make use of.
2020-07-09 16:22:48 +01:00
Andrea Corallo
3db6ace804 * Define `comp-symbol-func-to-fun'
* lisp/emacs-lisp/comp.el (comp-symbol-func-to-fun): New function.
	(comp-func-in-unit): Make use of the `comp-symbol-func-to-fun'.
2020-07-09 16:22:48 +01:00
Andrea Corallo
0b81044e7e * Clean-up some const folding logic and add `comp-function-pure-p'
* lisp/emacs-lisp/comp.el (comp-function-pure-p): New predicate.
	(comp-function-call-maybe-remove): Update to use the
	`comp-function-pure-p'.
2020-07-08 17:26:51 +01:00
Andrea Corallo
2593bbee51 * Relax constant folding rules
* lisp/emacs-lisp/comp.el (comp-function-optimizable-p): No need to
check for operands or result to be fixnums.
2020-07-04 15:55:48 +01:00
Andrea Corallo
b0f683ec16 * Fix missing tail recursion elimination
* lisp/emacs-lisp/comp.el (comp-tco-func): Fix tail recursion
	elimination given now functions in LIMPLE are expressed with
	the C name.
2020-07-02 22:55:42 +02:00
Andrea Corallo
8f81859497 Rework `comp-c-func-name' arguments
* 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.
2020-07-02 22:39:39 +02:00
Andrea Corallo
b67e156041 * Add to possibility to write per pass specific tests
* lisp/emacs-lisp/comp.el (comp-post-pass-hooks): New special
	variable.
	(native-compile): Run what is registered in
	`comp-post-pass-hooks'.
2020-07-02 22:39:32 +02:00
Andrea Corallo
4681f33071 Fix lambda-list relocation class
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.
2020-06-30 21:30:35 +02:00
Andrea Corallo
0ce4bf3ede * Do not skip native compilation for leim subfolder during boostrap
* lisp/emacs-lisp/comp.el (comp-bootstrap-black-list): Remove
	"^leim/".
2020-06-28 21:23:45 +01:00
Andrea Corallo
cfb871add4 * Handle correctly pure delaration specifier.
* 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.
2020-06-22 00:13:43 +02:00
Andrea Corallo
decced8337 Allow per function speed declaration
* 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.
2020-06-22 00:05:29 +02:00
Andrea Corallo
29b2a08c36 Execute top level forms in the right lex/dyn scope.
* lisp/emacs-lisp/bytecomp.el (byte-to-native-top-level): Add
	'lexical' slot.
	(byte-compile-output-file-form): Update for new slot.
	(byte-compile-file-form-defmumble): Capture scope.

	* lisp/emacs-lisp/comp.el (comp-emit-for-top-level): Specify
	execution scope.
2020-06-22 00:03:23 +02:00