From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Andrea Corallo via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#47049: [feature/native] macro-expansion cycle when compiling comp.el Date: Fri, 12 Mar 2021 20:02:25 +0000 Message-ID: References: <83zgzbnm7i.fsf@gnu.org> <83pn07nfuc.fsf@gnu.org> Reply-To: Andrea Corallo Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19799"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Eli Zaretskii , 47049@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Mar 12 21:03:28 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lKo0N-00050M-UM for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 12 Mar 2021 21:03:28 +0100 Original-Received: from localhost ([::1]:41140 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lKo0N-00077Q-0b for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 12 Mar 2021 15:03:27 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45454) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lKnzz-00076U-Ob for bug-gnu-emacs@gnu.org; Fri, 12 Mar 2021 15:03:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:46934) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lKnzy-0002YE-Ap for bug-gnu-emacs@gnu.org; Fri, 12 Mar 2021 15:03:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lKnzy-0000vN-7U for bug-gnu-emacs@gnu.org; Fri, 12 Mar 2021 15:03:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Andrea Corallo Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 12 Mar 2021 20:03:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47049 X-GNU-PR-Package: emacs Original-Received: via spool by 47049-submit@debbugs.gnu.org id=B47049.16155793513515 (code B ref 47049); Fri, 12 Mar 2021 20:03:02 +0000 Original-Received: (at 47049) by debbugs.gnu.org; 12 Mar 2021 20:02:31 +0000 Original-Received: from localhost ([127.0.0.1]:58480 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lKnzS-0000uc-NW for submit@debbugs.gnu.org; Fri, 12 Mar 2021 15:02:31 -0500 Original-Received: from mx.sdf.org ([205.166.94.24]:50932) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lKnzP-0000uR-7j for 47049@debbugs.gnu.org; Fri, 12 Mar 2021 15:02:29 -0500 Original-Received: from mab (ma.sdf.org [205.166.94.33]) by mx.sdf.org (8.15.2/8.14.5) with ESMTPS id 12CK2Qro027558 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO); Fri, 12 Mar 2021 20:02:26 GMT In-Reply-To: (Stefan Monnier's message of "Thu, 11 Mar 2021 10:26:03 -0500") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:202203 Archived-At: Stefan Monnier writes: >>> > I made some local modifications in comp.el, and used that modified >>> > comp.el for a while (by loading it manually at run time) to debug some >>> > problem. Then I undid those local modifications of comp.el (by saying >>> > "git checkout") and said "make" to rebuild Emacs. And I see this: >>> > >>> > ELC emacs-lisp/comp.elc >>> > Warning: Eager macro-expansion skipped due to cycle: >>> > => (load "comp.el") => (macroexpand-all (defalias 'comp-add-call-cstr )) => (macroexpand (comp-loop-insn-in-block )) => (load "comp.el") >>> > >>> > Why does this happen? >>> >>> I'm not sure, but I can reproduce it. >>> >>> I guess (just a guess) it might be because `comp-add-call-cstr' is using >>> a macro `comp-loop-insn-in-block' that is expanding with a >>> `cl-symbol-macrolet' inside? (no idea why this should be a problem). >>> >>> > could it be that while comp.el was modified it >>> > got native-compiled, and now that inconsistent comp.eln gets in the >>> > way? >>> >>> I think this has not to do specifically with native compilation. >>> >>> I see it goes away removing '(setq load-prefer-newer t)' from the >>> invocation tho. >>> >>> Perhaps somebody already more into the macro expansion business might >>> have some suggestion. >> >> Stefan, can you help, please? > > Nothing jumps at me by looking at the code. I'll have to look at the > actual complete stacktrace I think. Cool didn't know was so easy to generate backtraces to debug this kind of issues. At the bottom I attached the backtrace I produced and had a look into. IIUC while *loading* "comp.el" we try to advice `macroexpand' and consequentially we try to install a trampoline (was already compiled) for `macroexpand', this is supposed to be done by `comp-subr-trampoline-install' requiring "comp.el" to be loaded again! Assuming my analysis is correct I'm not sure what's the best work around for this condition. WDYT? Andrea ============== $ touch lisp/emacs-lisp/comp.el $ ./src/emacs -batch --no-site-file --no-site-lisp --eval '(setq load-prefer-newer t macroexp--debug-eager t)' -l comp -f batch-byte-native-compile-for-bootstrap lisp/emacs-lisp/comp.el Debugger entered: (eager-macroexp-cycle) internal-macroexpand-for-load((require 'bytecomp) nil) load-with-code-conversion("/home/andcor03/emacs2/lisp/emacs-lisp/comp.el" "/home/andcor03/emacs2/lisp/emacs-lisp/comp.el" nil t) comp-subr-trampoline-install(macroexpand) #f(compiled-function (v1102) #)(#f(advice-wrapper :around # cl--sm-macroexpand)) #f(compiled-function (gv--val) #)(#f(advice-wrapper :around # cl--sm-macroexpand)) advice--add-function(:around (#f(compiled-function () #) . #f(compiled-function (gv--val) #)) cl--sm-macroexpand nil) advice-add(macroexpand :around cl--sm-macroexpand) #f(compiled-function (arg1 &rest rest) "Make symbol macro definitions.\nWithin the body FORMs, references to the variable NAME will be replaced\nby EXPANSION, and (setq NAME ...) will act like (setf EXPANSION ...)." #)(((insn (car insn-cell))) (let ((insn-cell (comp-block-insns bb))) (while insn-cell (when-let ((match (pcase insn (... ...) (... ...)))) (cl-multiple-value-bind (f cstr-f lhs args) match (cl-loop with gen = (comp-lambda-list-gen (comp-cstr-f-args cstr-f)) for arg in args for cstr = (funcall gen) for target = (comp-cond-cstrs-target-mvar arg insn bb) unless (comp-cstr-p cstr) do (sign\ al 'native-ice (list "Incoherent type specifier for function" f)) when (and target (not ...) (or ... ...)) do (comp-emit-call-cstr target insn-cell cstr)))) (setf insn-cell (cdr insn-cell))))) macroexpand((comp-loop-insn-in-block bb (when-let ((match (pcase insn (`... (when-let ... ...)) (`... (when-let ... ...))))) (cl-multiple-value-bind (f cstr-f lhs args) match (cl-loop with gen = (comp-lambda-list-gen (comp-cstr-f-args cstr-f)) for arg in args for cstr = (funcall gen) for target = (comp-cond-cstrs-target-mvar arg insn bb) unless (comp-cstr-p cstr) do (signal 'native-ice (list "Incoherent type specifier for function" f)) when (and target (not (equal comp-cstr-t cstr)) (or (null lhs) (not ...))) do (comp-emit-call-cstr target insn-cell cstr))))) nil) macroexp-macroexpand((comp-loop-insn-in-block bb (when-let ((match (pcase insn (`... (when-let ... ...)) (`... (when-let ... ...))))) (cl-multiple-value-bind (f cstr-f lhs args) match (cl-loop with gen = (comp-lambda-list-gen (comp-cstr-f-args cstr-f)) for arg in args for cstr = (funcall gen) for target = (comp-cond-cstrs-target-mvar arg insn bb) unless (comp-cstr-p cstr) do (signal 'native-ice (list "Incoherent type specifier for function" f)) when (and target (not (equal comp-cstr-t cstr)) (or (null lhs) (not ...))) do (comp-emit-call-cstr target insn-cell cstr))))) nil) macroexp--expand-all((comp-loop-insn-in-block bb (when-let ((match (pcase insn (`... (when-let ... ...)) (`... (when-let ... ...))))) (cl-multiple-value-bind (f cstr-f lhs args) match (cl-loop with gen = (comp-lambda-list-gen (comp-cstr-f-args cstr-f)) for arg in args for cstr = (funcall gen) for target = (comp-cond-cstrs-target-mvar arg insn bb) unless (comp-cstr-p cstr) do (signal 'native-ice (list "Incoherent type specifier for function" f)) when (and target (not (equal comp-cstr-t cstr)) (or (null lhs) (not ...))) do (comp-emit-call-cstr target insn-cell cstr)))))) macroexp--all-forms((lambda (--cl-var-- bb) (comp-loop-insn-in-block bb (when-let ((match (pcase insn (... ...) (... ...)))) (cl-multiple-value-bind (f cstr-f lhs args) match (cl-loop with gen = (comp-lambda-list-gen (comp-cstr-f-args cstr-f)) for arg in args for cstr = (funcall gen) for target = (comp-cond-cstrs-target-mvar arg insn bb) unless (comp-cstr-p cstr) do (signal 'native-ice (list "Incoherent type specifier for function" f)) when (and target (not ...) (or ... ...)) do (comp-emit-call-cstr target insn-cell cstr)))))) 2) macroexp--expand-all((lambda (--cl-var-- bb) (comp-loop-insn-in-block bb (when-let ((match (pcase insn (... ...) (... ...)))) (cl-multiple-value-bind (f cstr-f lhs args) match (cl-loop with gen = (comp-lambda-list-gen (comp-cstr-f-args cstr-f)) for arg in args for cstr = (funcall gen) for target = (comp-cond-cstrs-target-mvar arg insn bb) unless (comp-cstr-p cstr) do (signal 'native-ice (list "Incoherent type specifier for function" f)) when (and target (not ...) (or ... ...)) do (comp-emit-call-cstr target insn-cell cstr))))))) macroexp--all-forms((maphash (lambda (--cl-var-- bb) (comp-loop-insn-in-block bb (when-let ((match (pcase insn ... ...))) (cl-multiple-value-bind (f cstr-f lhs args) match (cl-loop with gen = (comp-lambda-list-gen ...) for arg in args for cstr = (funcall gen) for target = (comp-cond-cstrs-target-mvar arg insn bb) unless (comp-cstr-p cstr) do (signal ... ...) when (and target ... ...) do (comp-emit-call-cstr target insn-cell cstr)))))) (comp-func-blocks comp-func)) 1) macroexp--expand-all((maphash (lambda (--cl-var-- bb) (comp-loop-insn-in-block bb (when-let ((match (pcase insn ... ...))) (cl-multiple-value-bind (f cstr-f lhs args) match (cl-loop with gen = (comp-lambda-list-gen ...) for arg in args for cstr = (funcall gen) for target = (comp-cond-cstrs-target-mvar arg insn bb) unless (comp-cstr-p cstr) do (signal ... ...) when (and target ... ...) do (comp-emit-call-cstr target insn-cell cstr)))))) (comp-func-blocks comp-func))) macroexpand-all((maphash (lambda (--cl-var-- bb) (comp-loop-insn-in-block bb (when-let ((match (pcase insn ... ...))) (cl-multiple-value-bind (f cstr-f lhs args) match (cl-loop with gen = (comp-lambda-list-gen ...) for arg in args for cstr = (funcall gen) for target = (comp-cond-cstrs-target-mvar arg insn bb) unless (comp-cstr-p cstr) do (signal ... ...) when (and target ... ...) do (comp-emit-call-cstr target insn-cell cstr)))))) (comp-func-blocks comp-func)) nil) cl--block-wrapper--cmacro((cl--block-wrapper (catch '--cl-block---cl-finish---- (maphash (lambda (--cl-var-- bb) (comp-loop-insn-in-block bb (when-let (...) (cl-multiple-value-bind ... match ...)))) (comp-func-blocks comp-func)))) (catch '--cl-block---cl-finish---- (maphash (lambda (--cl-var-- bb) (comp-loop-insn-in-block bb (when-let ((match ...)) (cl-multiple-value-bind (f cstr-f lhs args) match (cl-loop with gen = ... for arg in args for cstr = ... for target = ... unless ... do ... when ... do ...))))) (comp-func-blocks comp-func)))) apply(cl--block-wrapper--cmacro (cl--block-wrapper (catch '--cl-block---cl-finish---- (maphash (lambda (--cl-var-- bb) (comp-loop-insn-in-block bb (when-let (...) (cl-multiple-value-bind ... match ...)))) (comp-func-blocks comp-func)))) (catch '--cl-block---cl-finish---- (maphash (lambda (--cl-var-- bb) (comp-loop-insn-in-block bb (when-let ((match ...)) (cl-multiple-value-bind (f cstr-f lhs args) match (cl-loop with gen = ... for arg in args for cstr = ... for target = ... unless ... do ... when ... do ...))))) (comp-func-blocks comp-func)))) macroexp--compiler-macro(cl--block-wrapper--cmacro (cl--block-wrapper (catch '--cl-block---cl-finish---- (maphash (lambda (--cl-var-- bb) (comp-loop-insn-in-block bb (when-let (...) (cl-multiple-value-bind ... match ...)))) (comp-func-blocks comp-func))))) macroexp--expand-all((cl-block --cl-finish-- (maphash (lambda (--cl-var-- bb) (comp-loop-insn-in-block bb (when-let ((match ...)) (cl-multiple-value-bind (f cstr-f lhs args) match (cl-loop with gen = ... for arg in args for cstr = ... for target = ... unless ... do ... when ... do ...))))) (comp-func-blocks comp-func)))) macroexp--all-forms((progn (cl-block --cl-finish-- (maphash (lambda (--cl-var-- bb) (comp-loop-insn-in-block bb (when-let (...) (cl-multiple-value-bind ... match ...)))) (comp-func-blocks comp-func))) nil) 1) macroexp--expand-all((progn (cl-block --cl-finish-- (maphash (lambda (--cl-var-- bb) (comp-loop-insn-in-block bb (when-let (...) (cl-multiple-value-bind ... match ...)))) (comp-func-blocks comp-func))) nil)) macroexpand-all((progn (cl-block --cl-finish-- (maphash (lambda (--cl-var-- bb) (comp-loop-insn-in-block bb (when-let (...) (cl-multiple-value-bind ... match ...)))) (comp-func-blocks comp-func))) nil) nil) cl--block-wrapper--cmacro((cl--block-wrapper (catch '--cl-block-nil-- (cl-block --cl-finish-- (maphash (lambda (--cl-var-- bb) (comp-loop-insn-in-block bb (when-let ... ...))) (comp-func-blocks comp-func))) nil)) (catch '--cl-block-nil-- (cl-block --cl-finish-- (maphash (lambda (--cl-var-- bb) (comp-loop-insn-in-block bb (when-let (...) (cl-multiple-value-bind ... match ...)))) (comp-func-blocks comp-func))) nil)) apply(cl--block-wrapper--cmacro (cl--block-wrapper (catch '--cl-block-nil-- (cl-block --cl-finish-- (maphash (lambda (--cl-var-- bb) (comp-loop-insn-in-block bb (when-let ... ...))) (comp-func-blocks comp-func))) nil)) (catch '--cl-block-nil-- (cl-block --cl-finish-- (maphash (lambda (--cl-var-- bb) (comp-loop-insn-in-block bb (when-let (...) (cl-multiple-value-bind ... match ...)))) (comp-func-blocks comp-func))) nil)) macroexp--compiler-macro(cl--block-wrapper--cmacro (cl--block-wrapper (catch '--cl-block-nil-- (cl-block --cl-finish-- (maphash (lambda (--cl-var-- bb) (comp-loop-insn-in-block bb (when-let ... ...))) (comp-func-blocks comp-func))) nil))) macroexp--expand-all((cl-loop for bb being each hash-value of (comp-func-blocks comp-func) do (comp-loop-insn-in-block bb (when-let ((match (pcase insn (... ...) (... ...)))) (cl-multiple-value-bind (f cstr-f lhs args) match (cl-loop with gen = (comp-lambda-list-gen (comp-cstr-f-args cstr-f)) for arg in args for cstr = (funcall gen) for target = (comp-cond-cstrs-target-mvar arg insn bb) unless (comp-cstr-p cstr) do (signal 'native-ice (list "Incoherent type specifier for function" f)) when (and target (not ...) (or ... ...)) do (comp-emit-call-cstr target insn-cell cstr))))))) macroexp--all-forms((lambda nil "Add args assumptions for each function of which th..." (cl-loop for bb being each hash-value of (comp-func-blocks comp-func) do (comp-loop-insn-in-block bb (when-let ((match (pcase insn ... ...))) (cl-multiple-value-bind (f cstr-f lhs args) match (cl-loop with gen = (comp-lambda-list-gen ...) for arg in args for cstr = (funcall gen) for target = (comp-cond-cstrs-target-mvar arg insn bb) unless (comp-cstr-p cstr) do (signal ... ...) when (and target ... ...) do (comp-emit-call-cstr target insn-cell cstr))))))) 2) macroexp--expand-all(#'(lambda nil "Add args assumptions for each function of which th..." (cl-loop for bb being each hash-value of (comp-func-blocks comp-func) do (comp-loop-insn-in-block bb (when-let ((match ...)) (cl-multiple-value-bind (f cstr-f lhs args) match (cl-loop with gen = ... for arg in args for cstr = ... for target = ... unless ... do ... when ... do ...))))))) macroexp--all-forms((defalias 'comp-add-call-cstr #'(lambda nil "Add args assumptions for each function of which th..." (cl-loop for bb being each hash-value of (comp-func-blocks comp-func) do (comp-loop-insn-in-block bb (when-let (...) (cl-multiple-value-bind ... match ...)))))) 1) macroexp--expand-all((defalias 'comp-add-call-cstr #'(lambda nil "Add args assumptions for each function of which th..." (cl-loop for bb being each hash-value of (comp-func-blocks comp-func) do (comp-loop-insn-in-block bb (when-let (...) (cl-multiple-value-bind ... match ...))))))) macroexpand-all((defalias 'comp-add-call-cstr #'(lambda nil "Add args assumptions for each function of which th..." (cl-loop for bb being each hash-value of (comp-func-blocks comp-func) do (comp-loop-insn-in-block bb (when-let (...) (cl-multiple-value-bind ... match ...))))))) internal-macroexpand-for-load((defalias 'comp-add-call-cstr #'(lambda nil "Add args assumptions for each function of which th..." (cl-loop for bb being each hash-value of (comp-func-blocks comp-func) do (comp-loop-insn-in-block bb (when-let (...) (cl-multiple-value-bind ... match ...)))))) t) load-with-code-conversion("/home/andcor03/emacs2/lisp/emacs-lisp/comp.el" "/home/andcor03/emacs2/lisp/emacs-lisp/comp.el" nil t) command-line-1(("--eval" "(setq load-prefer-newer t macroexp--debug-eager t)" "-l" "comp" "-f" "batch-byte-native-compile-for-bootstrap" "lisp/emacs-lisp/comp.el")) command-line() normal-top-level() ==============