From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Improve detection of local function calls in methods Date: Thu, 02 Sep 2021 14:34:28 -0400 Message-ID: References: <878s0mva4u.fsf@gmail.com> <87zgt0sdbg.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12911"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: akater Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Sep 02 20:35:50 2021 Return-path: Envelope-to: ged-emacs-devel@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 1mLrZ0-00038N-AV for ged-emacs-devel@m.gmane-mx.org; Thu, 02 Sep 2021 20:35:50 +0200 Original-Received: from localhost ([::1]:53934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLrYy-0003yC-9Y for ged-emacs-devel@m.gmane-mx.org; Thu, 02 Sep 2021 14:35:48 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44850) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLrXp-0003AW-0a for emacs-devel@gnu.org; Thu, 02 Sep 2021 14:34:37 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:15025) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLrXl-0005Ny-75 for emacs-devel@gnu.org; Thu, 02 Sep 2021 14:34:35 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 28F6A806A7; Thu, 2 Sep 2021 14:34:32 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 48E8F80667; Thu, 2 Sep 2021 14:34:30 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1630607670; bh=TU1jlzZ/h9kdWjJlh0eW8Yf3EPSpAEXTtuZx6tag988=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=d2DTnpIgqR1EDBDXN84CPxpvQ9xzrKJBcXHtnk7q7B4xkDzbJYreXd0OndInT0qb0 YLfjV135FKee6xXSxv/3HzlNPjCfhmHv15bgKEWgI+X2YQA6rCHtbekqgKKW/GgCPo 4pqjdUdQEFErVQqUvi7DxP/Ps/nBcNaMl9YTsS3HqFeXRCqawp1S2gaBcXtLeUAfzK lnzHKciUneYVgcCgmBkqiVovDQ3h/3vZSkiBw+6lwZ1+UcKKwFvMkU+/yF9bWhPqi5 57FQruY+6LnvPpx0jG54uiXh6kxWWN2FdMmLCcdkK2FhYjo4dGYhKrpl/A4hBCHiLn wReMVZw8ELZbA== Original-Received: from lechazo (lechon.iro.umontreal.ca [132.204.27.242]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id B9AFF1201DD; Thu, 2 Sep 2021 14:34:28 -0400 (EDT) In-Reply-To: <87zgt0sdbg.fsf@gmail.com> (akater's message of "Sun, 29 Aug 2021 11:25:07 +0000") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:273723 Archived-At: > I don't know if all this is appropriate style; I provide patches this > way in the hope it's acceptable. Yes, that's very nice, thank you. > @@ -377,24 +377,51 @@ defun cl--generic-lambda (args body) > ;; destructuring args, `declare' and whatnot). > (pcase (macroexpand fun macroenv) > (`#'(lambda ,args . ,body) > - (let* ((parsed-body (macroexp-parse-body body)) > + (let* ((parsed-body (macroexp-parse-body body)) uses-cnm > (cnm (make-symbol "cl--cnm")) > (nmp (make-symbol "cl--nmp")) > - (nbody (macroexpand-all > - `(cl-flet ((cl-call-next-method ,cnm) > - (cl-next-method-p ,nmp)) > - ,@(cdr parsed-body)) > - macroenv)) > - ;; FIXME: Rather than `grep' after the fact, the > - ;; macroexpansion should directly set some flag when cnm > - ;; is used. > + (nbody > + ;; We duplicate the code from `cl-flet' augmenting it > + ;; with `cl-pushnew' forms to record the presence of > + ;; `cl-call-next-method', `cl-next-method-p'. > + ;; It would be better to avoid code duplication > + ;; but it's not clear how to do that reasonably enough. > + (let ((newenv > + (cons `(cl-call-next-method > + . > + ,(lambda (&rest args) > + (cl-pushnew cnm uses-cnm :test #'eq) > + (if (eq (car args) cl--labels-magic) > + (list cl--labels-magic cnm) > + `(funcall ,cnm ,@args)))) > + (cons `(cl-next-method-p > + . > + ,(lambda (&rest args) > + (cl-pushnew nmp uses-cnm :test #'eq) > + (if (eq (car args) cl--labels-magic) > + (list cl--labels-magic nmp) > + `(funcall ,nmp ,@args)))) > + macroenv)))) > + (macroexpand-all > + `(progn ,@(cdr parsed-body)) > + ;; Don't override lexical-let's macro-expander > + (if (assq 'function newenv) newenv > + (cons (cons 'function > + (lambda (f) > + (cl-case f > + (cl-call-next-method > + (cl-pushnew cnm uses-cnm :test #'eq)) > + (cl-next-method-p > + (cl-pushnew nmp uses-cnm :test #'eq))) > + (cl--labels-convert f))) > + newenv))))) Hmm... the reason why I didn't do that (when I wrote the comment instead), is that I find this duplication ugly. I think "the right way" would be for the `cl-flet` implementation to use a `cl--expand-flet` function returning which functions are used and which aren't. Then we could use it here without such duplication, *and* we could use it in `cl-flet` to emit warnings about unused functions. WDYT? Stefan