1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-14 09:39:42 +00:00
Commit Graph

396 Commits

Author SHA1 Message Date
Andrea Corallo
a58fef9f63 * Optimize optimizable variables
* 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.
2020-06-07 10:36:58 +02:00
Andrea Corallo
489a79de96 * Mitigate possible speed 3 miss-optimization
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.
2020-06-06 22:03:11 +01:00
Andrea Corallo
dcfcbb14f5 * Allow for optimizing anonymous lambdas in call-optim
* lisp/emacs-lisp/comp.el (comp-func-in-unit): New function.
	(comp-call-optim-form-call): Update logic for optimizing
	anonymous lambdas.
2020-06-06 22:03:11 +01:00
Andrea Corallo
e8ab017b6d Change 'direct-call' 'direct-callref' LIMPLE ops sematinc
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'.
2020-06-06 22:03:11 +01:00
Andrea Corallo
e4e6bb7fdd * Introduce `comp-loop-insn-in-block'
* 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'.
2020-06-03 22:06:26 +01:00
Andrea Corallo
f28b1780c6 * Split type hint pass from dead code removal pass into dedicated one.
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.
2020-05-25 22:10:42 +01:00
Andrea Corallo
0bba0e367b Fix GNU style
* src/comp.h: Fix GNU style.

* src/comp.c (Fcomp__compile_ctxt_to_file): Likewise.

* lisp/emacs-lisp/comp.el (comp--replace-output-file): Likewise.

* src/pdumper.c (dump_do_dump_relocation): Likewise.
2020-05-24 21:59:25 +01:00
Nicolás Bértolo
1b809f378f Improve handling of native compilation units still in use in Windows
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.
2020-05-25 09:42:10 +01:00
Nicolás Bértolo
d59607b685 * Windows: Use NUMBER_OF_PROCESSORS environment variable.
* 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.
2020-05-23 09:36:52 +01:00
Nicolás Bértolo
60b326ef11 * Workaround the 32768 chars command line limit in Windows.
* 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.
2020-05-23 09:36:52 +01:00
Andrea Corallo
f5ba60defb * lisp/emacs-lisp/comp.el (comp-num-cpus): Fix definition.
Introduced by 2aec16ab75.
2020-05-19 08:43:38 +01:00
Andrea Corallo
2aec16ab75 * Pacify with the byte-compiler
* 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.
2020-05-18 21:04:36 +01:00
Andrea Corallo
2ac6194585 * Add new customize `comp-async-env-modifier-form' (Bug#40838)
* lisp/emacs-lisp/comp.el (comp-async-env-modifier-form): New
	customize.
	(comp-run-async-workers): Make use of `comp-async-env-modifier-form'.
2020-05-18 21:04:36 +01:00
Andrea Corallo
6d850b50c5 * Make the Evil happy (Bug#41374)
* 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.
2020-05-18 19:19:05 +01:00
Andrea Corallo
d6f6353cfd * Do not refuse to compile if a dynamic lambda is encountered
* 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.
2020-05-15 20:06:49 +01:00
Andrea Corallo
9a64585c12 * Allow for logging async compilation command line
* lisp/emacs-lisp/comp.el (comp-run-async-workers): When non zero
	verbose log async compilation command line invocation.
2020-05-15 20:06:49 +01:00
Andrea Corallo
e351a12216 Sanity check on lambdas fixups
* 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.
2020-05-15 20:06:49 +01:00
Andrea Corallo
2b064c780c * Fix speed 2 bootstrap
(comp-call-optim-func): Do nothing if the function name is
	unknown.
2020-05-15 20:06:49 +01:00
Andrea Corallo
44b0ce6e38 Add anonymous lambdas reload mechanism
* src/pdumper.c (dump_do_dump_relocation): Initialize
	'lambda_gc_guard' while resurrecting.
	(dump_do_dump_relocation): Revive lambdas and fixup them.

	* src/comp.h (struct Lisp_Native_Comp_Unit): Define new
	'lambda_gc_guard' 'lambda_c_name_idx_h' 'data_imp_relocs'
	'loaded_once' fields.

	* src/comp.c (load_comp_unit): Use compilaiton unit 'loaded_once'
	field.
	(make_subr, Fcomp__register_lambda): New functions.
	(Fcomp__register_subr): Make use of 'make_subr'.
	(Fnative_elisp_load): Indent.
	(Fnative_elisp_load): Initialize 'lambda_gc_guard'
	'lambda_c_name_idx_h' fields.
	(syms_of_comp): Add Scomp__register_lambda.

	* lisp/emacs-lisp/comp.el (comp-ctxt): Change
	'byte-func-to-func-h' hash key test.
	(comp-ctxt): Add 'lambda-fixups-h' slot.
	(comp-emit-lambda-for-top-level): New function.
	(comp-finalize-relocs): Never emit lambdas in pure space.
	(comp-finalize-relocs): Fixup relocation indexes.
2020-05-15 20:06:49 +01:00
Andrea Corallo
2ee2fb5a86 * Prune now unnecessary byte-code objects
* lisp/emacs-lisp/comp.el (comp-finalize-container): Prune
	byte-code that was lambdas.
	(comp-compile-ctxt-to-file): Remove fixme.
2020-05-14 21:50:32 +01:00
Andrea Corallo
c12831a6b6 * Rework comp-spill-lap-function
* 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.
2020-05-14 21:50:32 +01:00
Andrea Corallo
a335f7eeac Update spill LAP machinery and compile anonymous lambdas
* 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.
2020-05-14 21:50:31 +01:00
Andrea Corallo
9bc0a7c408 * Fix `comp-deferred-compilation-black-list' effectiveness
* lisp/emacs-lisp/comp.el (native-compile-async): Fix logic for
	'comp-deferred-compilation-black-list' effectiveness.
2020-05-10 09:34:21 +01:00
Andrea Corallo
40f655e050 * Add 'comp-deferred-compilation-black-list' customize
* lisp/emacs-lisp/comp.el (comp-deferred-compilation-black-list):
	New customize.
	(native-compile-async): Make use of
	'comp-deferred-compilation-black-list'.
2020-05-09 14:06:43 +01:00
Andrea Corallo
cf105f6044 * Fix bug#41112
* lisp/emacs-lisp/comp.el (comp-jump-table-optimizable): New
	function.
	(comp-emit-switch): Make use of 'comp-jump-table-optimizable'.
2020-05-07 10:23:10 +01:00
Andrea Corallo
f8df3320b1 * Add native compilation unit 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.
2020-05-06 20:11:47 +01:00
Andrea Corallo
1ec7499e59 * Add a warning for missing write privilege
* lisp/emacs-lisp/comp.el (native-compile-async): Check for write
	privilege and raise a warning in case.
2020-05-03 13:37:38 +01:00
Andrea Corallo
8d37220190 * Introduce `comp-output-directory'
* lisp/emacs-lisp/comp.el (comp-output-directory): New function.
	(comp-output-base-filename): Use `comp-output-directory'.
2020-05-03 14:35:50 +01:00
Andrea Corallo
02e3ffad6d * Fix async compilation non respecting `comp-always-compile' nil value.
* lisp/emacs-lisp/comp.el (comp-run-async-workers): Fix missing
	`comp-output-filename' usage.
2020-04-29 21:25:02 +01:00
Andrea Corallo
f8b254d195 Rework spill LAP mechanism in preparation of compiling lambdas.
* 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.
2020-04-26 22:17:37 +01:00
Andrea Corallo
bb4cf13c47 Convert before final function doc hash into a vector.
* lisp/emacs-lisp/comp.el (comp-finalize-relocs): Convert doc hash
	table into vector befor final.
	(comp-emit-for-top-level): Rename `comp-ctxt-doc-index-h' ->
	`comp-ctxt-function-docs'.
	(comp-ctxt): Likewise.

	* src/comp.c (native_function_doc): Update logic for documentation
	being a vector.
	(emit_ctxt_code): Update for 'comp-ctxt-doc-index-h' slot rename.

	* src/comp.h (struct Lisp_Native_Comp_Unit): Rename 'data_fdoc_h'
	into data_fdoc_v.

	* src/pdumper.c (dump_native_comp_unit): Likewise.
2020-04-26 10:10:17 +01:00
Andrea Corallo
d73e64076e Store function documentations in a hash table.
* 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.
2020-04-25 19:55:39 +01:00
Andrea Corallo
9c4c0af89d * lisp/emacs-lisp/comp.el (comp-run-async-workers): Use `clrhash'. 2020-04-25 19:55:40 +01:00
Andrea Corallo
bab36619fb Fix deferred-compilation for double compilation (bug#40838).
* lisp/emacs-lisp/comp.el (native-compile-async): Prevent double
	compilation (bug#40838).
2020-04-25 15:12:37 +01:00
Andrea Corallo
e208de9d25 Store ongoing compilations processes as hash table.
* 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.
2020-04-25 15:12:37 +01:00
Andrea Corallo
b380451c6a * lisp/emacs-lisp/comp.el (comp-run-async-workers): Fix non late load. 2020-04-24 19:02:55 +01:00
Andrea Corallo
65cc8efa33 * lisp/emacs-lisp/comp.el (comp-never-optimize-functions): Better doc fix 2020-04-16 19:06:08 +01:00
Andrea Corallo
886ded1b70 * lisp/emacs-lisp/comp.el (comp-never-optimize-functions): Add yes-or-no-p 2020-04-16 18:59:40 +01:00
Andrea Corallo
8decfbe4d7 * lisp/emacs-lisp/comp.el (native-compile-async): Better error message. 2020-04-14 08:48:24 +01:00
Andrea Corallo
b7678cf10e * lisp/emacs-lisp/comp.el (comp-finalize-relocs): Better commentary. 2020-04-13 20:44:09 +01:00
Andrea Corallo
9f42f35418 * Fix native-compile-async for bug#40602.
* lisp/emacs-lisp/comp.el (native-compile-async): Relax coherency condition.
2020-04-13 20:44:09 +01:00
Andrea Corallo
32a079aef2 * lisp/emacs-lisp/comp.el (comp-c-func-name): Fix for M-x disassemble 2020-04-06 20:03:34 +01:00
Andrea Corallo
37a9d1e42b * lisp/emacs-lisp/comp.el (native-compile): Better documentation. 2020-04-05 21:10:49 +01:00
Andrea Corallo
530faee275 Fix free function compilation 2020-03-29 12:30:33 +01:00
Andrea Corallo
53f9bc6908 * comp.el (comp-output-base-filename): Handle src being a symbol 2020-03-29 12:30:33 +01:00
Andrea Corallo
d5f6dc131b Prevent collisions in C namespace and function shadowing
This rework make functions being indexed by their unique C symbol name
preventing multiple lisp function with the same name colliding.
2020-03-29 12:30:33 +01:00
Andrea Corallo
4acc4ac667 * comp.el (native-compile-async): Fix excessive messaging 2020-03-24 19:10:20 +00:00
Andrea Corallo
73ced8c23e * comp.el : Fix typo introduced by f8b07ff4f3 2020-03-23 22:27:17 +00:00
Andrea Corallo
f8b07ff4f3 Guard against function redefinition during deferred load 2020-03-23 20:37:59 +00:00
Andrea Corallo
ef30feb554 * comp.el: Add missing require 2020-03-22 15:57:00 +00:00