From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#59213: Emacs 29: Edebug fails to instrument a parameter whose name begins with _ Date: Tue, 14 Feb 2023 17:19:12 -0500 Message-ID: References: Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6276"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 59213@debbugs.gnu.org To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Feb 14 23:20:41 2023 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 1pS3fE-0001QL-Ui for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 14 Feb 2023 23:20:41 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pS3eg-0000gm-Uq; Tue, 14 Feb 2023 17:20:06 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pS3ec-0000Z4-8V for bug-gnu-emacs@gnu.org; Tue, 14 Feb 2023 17:20:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pS3eb-0005I8-VH for bug-gnu-emacs@gnu.org; Tue, 14 Feb 2023 17:20:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pS3eb-00029r-RZ for bug-gnu-emacs@gnu.org; Tue, 14 Feb 2023 17:20:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 14 Feb 2023 22:20:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59213 X-GNU-PR-Package: emacs Original-Received: via spool by 59213-submit@debbugs.gnu.org id=B59213.16764131648247 (code B ref 59213); Tue, 14 Feb 2023 22:20:01 +0000 Original-Received: (at 59213) by debbugs.gnu.org; 14 Feb 2023 22:19:24 +0000 Original-Received: from localhost ([127.0.0.1]:57274 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pS3dz-00028w-Vq for submit@debbugs.gnu.org; Tue, 14 Feb 2023 17:19:24 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:40407) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pS3dx-00028i-Q6 for 59213@debbugs.gnu.org; Tue, 14 Feb 2023 17:19:22 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id D4C1B800A8; Tue, 14 Feb 2023 17:19:15 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id D421C80148; Tue, 14 Feb 2023 17:19:13 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1676413153; bh=0XcZUzI9vMxbR/GnfkjSiNK8FuIEezVauh/sox4PcMw=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=Zfkpa78GsCR9yXlzyrmRcYrLhVKZSVgTOLeKnLCyvAuUQdgDRr608icTO0UsG6vML a3+1esATdH4hqVDmVvIN/m7o+2dJJ13l3S1TZddpRpPX2ciz8ErZDX2P4P7AsxA7Yc 06cm0He6JUNSzltLre0/LMIcw5ppzjnsc64HyAkvwcpWHKcxqF/gS3JYTzxbXJC39m 0n2SrlxeiPuOd+3EbXUWVgacIUsrdCpykGCakVBp7bgCsHQKUitLqQ5H21eynGweYx Y3l86UqQpMALNrT2t46P4ghi5M4aiM0O715yNI5wfYcn+7ec0UtxjbC3GQ3dkoHKlx +gT9Oy7cGMMyg== Original-Received: from lechazo (lechon.iro.umontreal.ca [132.204.27.242]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id B133D1231AD; Tue, 14 Feb 2023 17:19:13 -0500 (EST) In-Reply-To: (Alan Mackenzie's message of "Fri, 10 Feb 2023 18:51:37 +0000") 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:255641 Archived-At: Hi Alan, > (defun cconv-make-interpreted-closure (fun env) > + "Make a closure for the interpreter. > +This function is evaluated both at compile time and run time. > +FUN, the closure's function, must be a lambda form. > +ENV, the closure's environment, is a mixture of lexical bindings of the form > +(SYMBOL . VALUE) and symbols which indicate dynamic bindings of those > +symbols." BTW, what did you mean by "This function is evaluated both at compile time and run time"? Also, I append the current state of the patch I plan to install on `master`. Stefan diff --git a/lisp/emacs-lisp/cconv.el b/lisp/emacs-lisp/cconv.el index b8121aeba55..d055026cb1a 100644 --- a/lisp/emacs-lisp/cconv.el +++ b/lisp/emacs-lisp/cconv.el @@ -113,10 +113,6 @@ cconv--interactive-form-funs (defvar cconv--dynbound-variables nil "List of variables known to be dynamically bound.") -(defvar cconv-dont-trim-unused-variables nil - "When bound to non-nil, don't remove unused variables from the environment. -This is intended for use by edebug and similar.") - ;;;###autoload (defun cconv-closure-convert (form &optional dynbound-vars) "Main entry point for closure conversion. @@ -886,11 +882,16 @@ cconv-make-interpreted-closure This function is evaluated both at compile time and run time. FUN, the closure's function, must be a lambda form. ENV, the closure's environment, is a mixture of lexical bindings of the form -(SYMBOL . VALUE) and symbols which indicate dynamic bindings of those +\(SYMBOL . VALUE) and symbols which indicate dynamic bindings of those symbols." (cl-assert (eq (car-safe fun) 'lambda)) (let ((lexvars (delq nil (mapcar #'car-safe env)))) - (if (or cconv-dont-trim-unused-variables (null lexvars)) + (if (or (null lexvars) + ;; Functions of the form (lambda (..) :closure-dont-trim-context ..) + ;; should keep their whole context untrimmed (bug#59213). + (and (eq :closure-dont-trim-context (nth 2 fun)) + ;; Check the function doesn't just return the magic keyword. + (nthcdr 3 fun))) ;; The lexical environment is empty, or needs to be preserved, ;; so there's no need to look for free variables. ;; Attempting to replace ,(cdr fun) by a macroexpanded version diff --git a/lisp/emacs-lisp/edebug.el b/lisp/emacs-lisp/edebug.el index 735a358cdba..4b625dd076e 100644 --- a/lisp/emacs-lisp/edebug.el +++ b/lisp/emacs-lisp/edebug.el @@ -1217,16 +1217,17 @@ edebug-make-enter-wrapper (setq edebug-old-def-name nil)) (setq edebug-def-name (or edebug-def-name edebug-old-def-name (gensym "edebug-anon"))) - `(let ((cconv-dont-trim-unused-variables t)) - (edebug-enter - (quote ,edebug-def-name) - ,(if edebug-inside-func - `(list - ;; Doesn't work with more than one def-body!! - ;; But the list will just be reversed. - ,@(nreverse edebug-def-args)) - 'nil) - (function (lambda () ,@forms))))) + `(edebug-enter + (quote ,edebug-def-name) + ,(if edebug-inside-func + `(list + ;; Doesn't work with more than one def-body!! + ;; But the list will just be reversed. + ,@(nreverse edebug-def-args)) + 'nil) + ;; Make sure `forms' is not nil so we don't accidentally return + ;; the magic keyword. + #'(lambda () :closure-dont-trim-context ,@(or forms '(nil))))) (defvar edebug-form-begin-marker) ; the mark for def being instrumented diff --git a/lisp/emacs-lisp/testcover.el b/lisp/emacs-lisp/testcover.el index 1212905f08a..ed31b90ca32 100644 --- a/lisp/emacs-lisp/testcover.el +++ b/lisp/emacs-lisp/testcover.el @@ -442,11 +442,6 @@ testcover-analyze-coverage (let ((testcover-vector (get sym 'edebug-coverage))) (testcover-analyze-coverage-progn body))) - (`(let ((cconv-dont-trim-unused-variables t)) - (edebug-enter ',sym ,_ (function (lambda nil . ,body)))) - (let ((testcover-vector (get sym 'edebug-coverage))) - (testcover-analyze-coverage-progn body))) - (`(edebug-after ,(and before-form (or `(edebug-before ,before-id) before-id)) ,after-id ,wrapped-form) diff --git a/test/lisp/emacs-lisp/cconv-tests.el b/test/lisp/emacs-lisp/cconv-tests.el index 83013cf46a9..349ffeb7e47 100644 --- a/test/lisp/emacs-lisp/cconv-tests.el +++ b/test/lisp/emacs-lisp/cconv-tests.el @@ -364,5 +364,18 @@ cconv-tests--intern-all (call-interactively f)) '((t 51696) (nil 51695) (t 51697))))))) +(ert-deftest cconv-safe-for-space () + (let* ((magic-string "This-is-a-magic-string") + (safe-p (lambda (x) (not (string-match magic-string (format "%S" x)))))) + (should (funcall safe-p (lambda (x) (+ x 1)))) + (should (funcall safe-p (eval '(lambda (x) (+ x 1)) + `((y . ,magic-string))))) + (should (funcall safe-p (eval '(lambda (x) :closure-dont-trim-context) + `((y . ,magic-string))))) + (should-not (funcall safe-p + (eval '(lambda (x) :closure-dont-trim-context (+ x 1)) + `((y . ,magic-string))))))) + + (provide 'cconv-tests) ;;; cconv-tests.el ends here