From 87c6aa13b30281398688ec8693a0205bb84bc648 Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Fri, 2 Oct 2020 22:36:05 +0200 Subject: [PATCH] Make primitive redefinition effective through trampoline synthesis * lisp/loadup.el (dump-mode): Set `comp-enable-subr-trampolines' when finished bootstrap. * src/data.c (Ffset): Call `comp-enable-subr-trampolines' when redefining a subr. * src/comp.c (syms_of_comp): Define `comp-subr-trampoline-install' symbol. (syms_of_comp): Define `comp-enable-subr-trampolines' variable. --- lisp/loadup.el | 5 +++++ src/comp.c | 6 ++++++ src/data.c | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/lisp/loadup.el b/lisp/loadup.el index f218ec1ff98..91126703d18 100644 --- a/lisp/loadup.el +++ b/lisp/loadup.el @@ -510,6 +510,11 @@ lost after dumping"))) ((equal dump-mode "bootstrap") "emacs") ((equal dump-mode "pbootstrap") "bootstrap-emacs.pdmp") (t (error "unrecognized dump mode %s" dump-mode))))) + (when (and (boundp 'comp-ctxt) + (equal dump-mode "pdump")) + ;; Don't enable this before bootstrap is completed the as the + ;; compiler infrastructure may not be usable. + (setq comp-enable-subr-trampolines t)) (message "Dumping under the name %s" output) (condition-case () (delete-file output) diff --git a/src/comp.c b/src/comp.c index 5663c9e5624..076236ef80c 100644 --- a/src/comp.c +++ b/src/comp.c @@ -5141,6 +5141,7 @@ native compiled one. */); DEFSYM (Qlate, "late"); DEFSYM (Qlambda_fixup, "lambda-fixup"); DEFSYM (Qgccjit, "gccjit"); + DEFSYM (Qcomp_subr_trampoline_install, "comp-subr-trampoline-install") /* To be signaled by the compiler. */ DEFSYM (Qnative_compiler_error, "native-compiler-error"); @@ -5246,6 +5247,11 @@ The last directory of this list is assumed to be the system one. */); dump reload. */ Vcomp_eln_load_path = Fcons (build_string ("../native-lisp/"), Qnil); + DEFVAR_BOOL ("comp-enable-subr-trampolines", comp_enable_subr_trampolines, + doc: /* When non-nil enable trampoline synthesis + triggerd by `fset' making primitives + redefinable effectivelly. */); + DEFVAR_LISP ("comp-installed-trampolines-h", Vcomp_installed_trampolines_h, doc: /* Hash table subr-name -> bool. */); Vcomp_installed_trampolines_h = CALLN (Fmake_hash_table); diff --git a/src/data.c b/src/data.c index 8c39c319110..c6629dd5f29 100644 --- a/src/data.c +++ b/src/data.c @@ -775,6 +775,13 @@ DEFUN ("fset", Ffset, Sfset, 2, 2, 0, eassert (valid_lisp_object_p (definition)); +#ifdef HAVE_NATIVE_COMP + if (comp_enable_subr_trampolines + && SUBRP (function) + && !SUBR_NATIVE_COMPILEDP (function)) + CALLN (Ffuncall, Qcomp_subr_trampoline_install, symbol); +#endif + set_symbol_function (symbol, definition); return definition; -- 2.39.5