Commit graph

715 commits

Author SHA1 Message Date
Andrea Corallo
4b924ef87d * As edges are indexed store them in an hash table
* lisp/emacs-lisp/comp.el (comp-edge): Update doc for 'number'
	slot.
	(comp-func): Rename 'edges' slot into 'edges-h'.
	(comp-log-edges): Update logic for edges in an hash table.
	(comp-clean-ssa, comp-compute-edges): Likewise.
2020-10-10 20:25:57 +02:00
Andrea Corallo
96f59a9faf * Add into phi l-value args basic block names
* lisp/emacs-lisp/comp.el (comp-ssa-rename-insn): Clean-up a
	leftover space.
	(comp-finalize-phis): Cons the blasic block name providing the
	mvar together with the mvar itself while forming the phi.
	(comp-fwprop-insn): Destructure correctly the phi.
2020-10-10 20:25:42 +02:00
Andrea Corallo
8b135af5bb Provide feature nativecomp and make use of it
* lisp/emacs-lisp/comp.el (comp-ensure-native-compiler): Use
	`featurep' to identify if the native compiler is available.
	* lisp/emacs-lisp/nadvice.el (advice--add-function): Likewise.
	* lisp/emacs-lisp/package.el (package--delete-directory): Likewise.
	* lisp/loadup.el: Likewise.
	* src/comp.c (syms_of_comp): Provide feature nativecomp.
2020-10-10 18:47:45 +02:00
Andrea Corallo
77fa6befb4 * lisp/emacs-lisp/comp.el (comp-func): Fix doc for blocks slot. 2020-10-10 18:08:23 +02:00
Andrea Corallo
b8772e8b08 * Fix LIMPLE latch block name coloring in "*Native-compile-Log*"
* lisp/emacs-lisp/comp.el (comp-limple-lock-keywords): Fix
	latch block name coloring.
2020-10-10 15:15:49 +02:00
Brian Leung
51f5e487b2 Various typo fixes in native compiler related files
* lisp/emacs-lisp/comp.el (native-compiler-error-dyn-func)
	(comp-func, comp-func-l)
	(comp-func-d, comp-ensure-native-compiler, comp-type-hint-p)
	(comp-func-unique-in-cu-p, comp-alloc-class-to-container)
	(comp-limple-mode, comp-loop-insn-in-block)
	(comp-lex-byte-func-p, comp-c-func-name, comp-decrypt-arg-list)
	(comp-spill-lap-function, comp-intern-func-in-ctxt)
	(comp-spill-lap-function, comp-spill-lap, comp-emit-handler)
	(comp-prepare-args-for-top-level): Various typo fixes.
	* src/comp.c (Fcomp_el_to_eln_filename): Fix typo in error
	message.
2020-10-10 12:19:30 +02:00
Andrea Corallo
138990bbda * Fix failure when compiling a trampoline with no eln-cache dir (bug#43875)
* lisp/emacs-lisp/comp.el (comp-trampoline-compile): Try to create
	the eln-cache dir if this is not existing, if fails to do that
	move on to the next one.
2020-10-10 10:29:17 +02:00
Andrew Whatson
85450f03be * Fix typo name plus make error homogeneous in `comp-trampoline-compile'
* lisp/emacs-lisp/comp.el (comp-trampoline-compile): Fix typo
	renaming `comp-tampoline-compile' -> `comp-trampoline-compile'.
	Change error to be consistent.
	(comp-subr-trampoline-install): Use `comp-trampoline-compile'.
2020-10-10 10:29:14 +02:00
Andrea Corallo
7041c32ec2 * Fix some nits in comp.el
* lisp/emacs-lisp/comp.el (comp-spill-lap-function): Use
	`cl-defmethod' where correct in place of `cl-defgeneric'.
	(comp-tampoline-compile): Add missing #.
2020-10-07 20:43:00 +02:00
Andrea Corallo
58d85f4dbb * Do use echo area for async compilation started/finished messages
* lisp/emacs-lisp/comp.el (comp-run-async-workers)
	(native-compile-async): Do not write into the echo area.
2020-10-07 07:41:00 +02:00
Andrea Corallo
0b58be4941 Rename comp-subr-safe-advice -> comp-subr-trampoline-install 2020-10-05 21:32:38 +02:00
Andrea Corallo
36e0c3fb07 * When advising search in `comp-eln-load-path' the first writable dir
* lisp/emacs-lisp/comp.el (comp-tampoline-compile): Do not crash
	if we can't write in the first entry in `comp-eln-load-path' but
	search for another one.
2020-10-02 14:48:48 +02:00
Andrea Corallo
2cc82563d2 * lisp/emacs-lisp/comp.el (comp-c-func-name): Add autoload cookie. 2020-10-01 07:55:00 +02:00
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