all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Lynn Winebarger <owinebar@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Philip Kaludercic <philipk@posteo.net>, help-gnu-emacs@gnu.org
Subject: Re: inline function expansion
Date: Thu, 18 May 2023 20:22:53 -0400	[thread overview]
Message-ID: <CAM=F=bAfSPUbY_7UB9NYR-qCtxif1fLxhan4S7j=mUmqmdYmRQ@mail.gmail.com> (raw)
In-Reply-To: <jwvlehla6yq.fsf-monnier+emacs@gnu.org>

On Thu, May 18, 2023 at 2:29 PM Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> > I think it will be easier to ensure compile-time generic methods
> > (e.g. a macro that simply calls a generic method) will (or at least
> > can) dispatch during macro-expansion, without involving the
> > byte-compiler's optimization phase.
>
> I don't understand this, sorry.

I'm trying to provide myself a tool for generic programming that
dispatches at compile time.  I've been writing too much repetitive
code, but I'm not a fan of ad hoc macros either.  Basically, I'm
trying to provide a C#-ish system for writing generic code
parameterized by interface requirements.  Then the generic method can
be moved to compile-time, with specialization on constant parameters
to dispatch to specialized code. Like cl-typep, except instead of an
explicit pcase form, calling a generic method.

> > (define-inline inline-+ (&rest args)
> >    (if (seq-every-p #'inline-const-p args)
> >        (apply (eval-when-compile (symbol-function '+)) args)
> >     (inline-quote (,(eval-when-compile (symbol-function '+)) . ,args))))
>
> IIRC you definitely need an `inline-letvals` somewhere here.

That's the issue - if you use inline-letvals, then the code can't make
use of constant values provided as operands.

> But also this will define the non-inlined version as something along the
> lines of:
>
>     (defun inline-+ (&rest args)
>        (if (seq-every-p ... args)
>            (apply '+ args)
>         (apply (symbol-function '+) args)))
>
> which is much too slow IMO.

I agree.

I posted a patch to emacs-devel for define-inline-pure-subr that
adapts the technique of define-inline.  I wanted to literally inline
the subr's into the code, but aside from the issue of not having
read-syntax for subrs (for some reason), some parts of core emacs
appear to rely on the car of a form being a symbol.

So I ended up defining a second symbol to hold the true definition,
with the compiler macro inserting a call to that symbol, while the
original symbol made into either a defun or defsubst.  The code copies
the plist of the original symbol to the second symbol so any
properties used by the byte-compiler/optimizer will be applied to the
new symbol as well.



  reply	other threads:[~2023-05-19  0:22 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-07 14:32 inline function expansion Lynn Winebarger
2023-05-07 17:51 ` Basile Starynkevitch
2023-05-07 19:48 ` Philip Kaludercic
2023-05-07 20:16   ` Lynn Winebarger
2023-05-08  0:21     ` Emanuel Berg
2023-05-08 11:12       ` Lynn Winebarger
2023-05-08  2:03   ` Lynn Winebarger
2023-05-11  7:11   ` Lynn Winebarger
2023-05-12  6:25     ` Emanuel Berg
2023-05-18 14:56     ` Lynn Winebarger
2023-05-19 13:31       ` Stefan Monnier
2023-05-20 14:18         ` Lynn Winebarger
2023-05-20 15:32           ` Stefan Monnier
2023-05-21 12:47             ` Lynn Winebarger
2023-05-18 18:29     ` Stefan Monnier
2023-05-19  0:22       ` Lynn Winebarger [this message]
2023-05-19 13:07         ` Stefan Monnier
2023-05-20 15:01           ` Lynn Winebarger
2023-05-20 15:48             ` Stefan Monnier
2023-05-27 14:34               ` Lynn Winebarger
2023-05-28 14:12                 ` Lynn Winebarger
2023-05-28 14:57                 ` Stefan Monnier
2023-05-28 22:42                   ` Lynn Winebarger
2023-05-29  2:59                     ` Stefan Monnier
2023-06-06 22:38                       ` Lynn Winebarger

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='CAM=F=bAfSPUbY_7UB9NYR-qCtxif1fLxhan4S7j=mUmqmdYmRQ@mail.gmail.com' \
    --to=owinebar@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=philipk@posteo.net \
    /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.