unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: akater <nuclearspace@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: [PATCH] Improve detection of local function calls in methods
Date: Fri, 10 Sep 2021 06:25:57 +0000	[thread overview]
Message-ID: <87ee9xq74a.fsf@gmail.com> (raw)
In-Reply-To: <jwvv93ig7c5.fsf-monnier+emacs@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 2261 bytes --]

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> 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?

I agree.  I think the root of the problem is, ~cl-flet~ is generally not
implemented well.  Feels like it was implemented in a rush.

- (func exp) is non-standard and ad-hoc.  Do you happen to remember,
  maybe it was invented solely for ~cl--generic-lambda~?

- (func exp) definition form is described incorrectly in the docstring:
  it should be (FUNCTION-NAME SYMBOL) and so on; this also affects
  cl-macrolet docstring which claims it's “like cl-flet” but in fact
  it's not as it doesn't support this definition form

- ~cl-flet~ with invalid function names should error but it doesn't

I implemented ~cl--expand-flet~ but I felt simply returning a list of
used symbols would be just another ad-hoc addition so I decided to
instead add an interface to execute arbitrary code during
macroexpansion.  It took longer than I expected but I'm satisfied with
the result.  I'll open a standalone bug (my implementation happens to
fix some outstanding issues); when changes are (hopefully) merged, we'll
continue on with this one.

Quick reference: if all goes well, the definition of
~cl--generic-lambda~ is to become
#+begin_example emacs-lisp
..
(let* ((parsed-body (macroexp-parse-body body)) uses-cnm
       (cnm (make-symbol "cl--cnm"))
       (nmp (make-symbol "cl--nmp"))
       (nbody (cl--expand-flet macroenv (cdr parsed-body)
                (cl-call-next-method (push cnm uses-cnm) cnm)
                (cl-next-method-p (push nmp uses-cnm) nmp)))
       ;; FIXME: Optimize the case where call-next-method is
       ;; only called with explicit arguments.
       )
  ..)
#+end_example

This involves a “macro” version of expand-flet; we'll see whether it's
worth keeping alongside the corresponding function.

If you can, please confirm my suspicion that (FUNC EXP) definitions were
indeed invented solely for ~cl--generic-lambda~.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 865 bytes --]

  reply	other threads:[~2021-09-10  6:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-27 21:41 [PATCH] Improve detection of local function calls in methods akater
2021-08-27 22:59 ` Stefan Monnier
2021-08-29 11:25   ` akater
2021-09-02 18:34     ` Stefan Monnier
2021-09-10  6:25       ` akater [this message]
2021-09-10 15:49         ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ee9xq74a.fsf@gmail.com \
    --to=nuclearspace@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).