all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Robin Tarsiger <rtt@dasyatidae.com>
To: Emacs-Devel List <emacs-devel@gnu.org>
Subject: Re: cl-block less lexical than expected
Date: Tue, 4 Jan 2022 13:29:23 -0600	[thread overview]
Message-ID: <070acea8-3299-83ca-f321-a08a93005225@dasyatidae.com> (raw)
In-Reply-To: <jwvee5u3p6n.fsf-monnier+emacs@gnu.org>

I wrote:
 > I have to think that since catch and throw both take evaluated
 > expressions for their tags, a more suitable implementation might
 > do a static transformation to choose an out-of-the-way lexical
 > _variable_ name which would then be let-bound to a gensym during
 > the body. cl-return-from could then try to evaluate the variable
 > to get the tag;

Stefan Monnier wrote:
> Sounds good.  As you noted, this was not an option when these macros
> were written because of the need for statically scoped variables.

So I've been experimenting a little with modifying cl-macs.el to make
this happen. I think I have it about right, but here's what I've found
that's tricky:

   - cl--block-wrapper currently assumes it's receiving exactly a form
     produced by cl--block and invasively unwraps it, so they have to
     be kept in sync. This isn't too bad when it's just a catch form,
     but the new form is much more highly nested.

     I imagine having cl--block-wrapper do most of the expansion itself
     and be implemented as macro+cmacro rather than passthrough+cmacro
     would be cleaner here?

   - The new form is more highly nested not just because of the let to
     keep the tag in a variable, but because of an unwind-protect used
     to clear out the variable when the body is exited. This is so that
     lambdas that cl-return-from the enclosing block function properly
     when called while the block is executing, but can _not_ erroneously
     return from a separate activation of the same block if called after
     the original activation of the block has exited. Instead, they will
     wind up throwing to a dummy tag and signaling a recognizable error
     thereby.

     Naturally, the existing code misbehaves in this scenario as well.

   - I currently have cl-block warn if lexical-binding is nil. I did a
     quick pass over the Lisp files included with Emacs to make sure
     all files with cl-block-alikes used lexical-binding, but I don't
     know what impact this would have on external packages.

   - It would be nice to have cl-return-from warn if it doesn't see the
     name in the list of extant blocks that the cl--block-wrapper cmacro
     already uses to optimize away the catch, but that's not reliable
     enough, right? It doesn't play nicely with macrostep, for instance.
     Is there a better way to do this?

   - Documenting the new behavior is a bit weird due to the potential
     interaction with lexical-binding. I have a few paragraphs in the
     docstrings Texinfo manual indicating that cl-return-from may
     behave erratically if there are any non-lexical-binding cl-blocks
     in effect.

     The existing documentation is not quite correct anyway.

More general questions for the list:

   - Is this a worthwhile thing to fix in Emacs? I would say yes, else
     I wouldn't be trying it, but I don't know if other people agree.

     The complexity increase in documentation from interactions with
     non-lexical-binding code is awkward, especially. How much do we
     need to worry about that? Is the general trend for lexical-binding
     to be strongly recommended enough that not giving details of
     what happens if it's off (other than that the correct use cases
     should still work) is okay?

   - If so, do I sound reasonably on the right track above? Would it be
     helpful to present a draft patch?

   - The reason I have not already presented a draft patch is because in
     futures where the code is integrated into Emacs, I would have to
     perform a copyright assignment. I do not object to this, but I also
     do not use my government-recognized name as my social name in this
     context. I am okay with the FSF keeping a record of my government
     name for legal purposes, but I would rather it not be included in
     publications anyplace too obvious. Is this a request that I can
     expect to be honored? What would be the impact of this on the
     assignment procedure? I am a US citizen.

-RTT



  reply	other threads:[~2022-01-04 19:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-30 18:12 cl-block less lexical than expected Robin Tarsiger
2021-12-30 18:15 ` Robin Tarsiger
2021-12-30 18:50 ` Stefan Monnier
2022-01-04 19:29   ` Robin Tarsiger [this message]
2022-01-04 20:11     ` Eli Zaretskii

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

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

  git send-email \
    --in-reply-to=070acea8-3299-83ca-f321-a08a93005225@dasyatidae.com \
    --to=rtt@dasyatidae.com \
    --cc=emacs-devel@gnu.org \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.