unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: "João Paulo Labegalini de Carvalho" <jaopaulolc@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Contributing to Emacs
Date: Fri, 09 Sep 2022 11:09:00 -0400	[thread overview]
Message-ID: <jwvfsh0wqfx.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <CAGjvy28hb4Kbn3sxUC_F5zfmxw+n7G5htsRaV_7r037Op=X7zw@mail.gmail.com> ("João Paulo Labegalini de Carvalho"'s message of "Wed, 7 Sep 2022 14:01:06 -0600")

>  I was looking at the file etc/TODO in the repo, and some items there
> caught my attention. For example, under 'Important Features'  I found 'Add
> an "indirect goto" byte-code'. Is this still a desired feature or is it not
> required due to recent efforts towards native compilation? (In the negative
> case, please feel free to suggest another item for me to work on)

I think I was the one to add this point to etc/TODO and AFAIK the need
is pretty much still the same, yes.  Part of the idea is to handle more
efficiently code which uses local lambda expressions (like `cl-flet`).

There's a lot of scope here.  Some steps are easy but won't bring any
(or very little) benefit, which others depend on those first steps and
require much more extensive work.

> If it is still desired I would like to work on it and would appreciate
> guidance. After taking a look at lisp/emacs-lisp/bytecomp.el,it seems that
> forms such as
>
>  (let ((foo (lambda (x) bar)))
>      (dosomething
>        (funcall foo toto)
>        (blabla (funcall foo titi))))
>
> are compiled by calling byte-compile-let. Before generating the binding for
> foo, #'(lambda (x) bar) is compiled by calling
> byte-compile-push-binding-init, which in turn compiles the lambda to
> bytecode and pushes it to the stack.
>
> So to make it more concrete for my sake, I wrote the following form
>
> (let ((foo (lambda (x) (- x 1))))
>   (* (funcall foo 2)
>      (- (funcall foo 3) 2)))

Indeed, I think it might be fairly easy to handle this code more
efficiently.  Things become more ... interesting when we have code like:

    (let* ((count 0)
           (foo (lambda (x) (setq count (1+ count)) (+ x count))))
      (* (funcall foo 2)
         (- (funcall foo 3) 2)))

Where `cconv.el` turns the `count` into a one-element list and
replaces the `setq` with a `setcar`, which wouldn't be needed if we
could directly refer to the `count` var from the inner lambda using
those new byte codes.

Even more interesting would be

    (let* ((count 0)
           (foo (lambda (x) (setq count (1+ count)) (+ x count))))
      (let ((bar (funcall foo 2)))
         (- (funcall foo 3) bar)))

where the relative position of `count` on the stack is different in the
two calls to `foo`.

> and with disassemble inspected the generated bytecode by Emacs 28.1
>
> byte code:
>   args: nil
> 0       constant  <compiled-function>
>       args: (x)
>     0       varref    x
>     1       sub1
>     2       return
>
> 1       dup
> 2       varbind   foo
> 3       constant  2
> 4       call      1
> 5       varref    foo
> 6       constant  3
> 7       call      1
> 8       constant  2
> 9       diff
> 10      mult
> 11      unbind    1
> 12      return
>
> As far as I understood,  the idea of the "indirect goto" here is to
> eliminate the calls on lines 4 and 7 and replace them with an indirect
> goto.

The ones at 4 and 7 can stay as "normal" gotos but they need to pass to
the function an additional argument which is the return address, and
then the inner function would be the one which uses an indirect goto
instead of "return".

> stack* in line 0 (constant <compiled-function>). Thus, for the indirect
> goto idea to work, the bytecode of the lambda would need to be part of the
> bytecode of the let's body**. That way, a computed branch can branch into
> the lambdas code and it is possible to branch out of it when returning.

I guess in theory there could be cases where we could use a computed
goto to jump into a function, but that needs probably too many stars to
be aligned to be worth considering.  The indirect goto is needed for
"return", OTOH.

> Aside from guidance on implementing this, I would appreciate any
> pointers on how to adequately test it.

I don't think there's currently many ways to test bytecode level
operation, other than writing normal ELisp code which we expect will use
those bytecodes and make sure they behave as expected.


        Stefan




  parent reply	other threads:[~2022-09-09 15:09 UTC|newest]

Thread overview: 187+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-07 20:01 Contributing to Emacs João Paulo Labegalini de Carvalho
2022-09-07 20:32 ` Mattias Engdegård
2022-09-08 16:26   ` João Paulo Labegalini de Carvalho
2022-09-08 16:39   ` Eli Zaretskii
2022-09-07 21:33 ` Christopher Dimech
2022-09-08  5:40   ` Eli Zaretskii
2022-09-08 10:22     ` Christopher Dimech
2022-09-08 11:57     ` Christopher Dimech
2022-09-08 12:27       ` Robert Pluim
2022-09-08 13:11         ` Christopher Dimech
2022-09-08 13:25           ` Robert Pluim
2022-09-08 13:38             ` Óscar Fuentes
2022-09-08 14:13               ` Robert Pluim
2022-09-08 14:48                 ` Óscar Fuentes
2022-09-08 15:21             ` Christopher Dimech
2022-09-08 12:12     ` Christopher Dimech
2022-09-08 13:47       ` Eli Zaretskii
2022-09-08 14:49         ` Christopher Dimech
2022-09-08 14:55           ` Visuwesh
2022-09-08 15:16             ` Christopher Dimech
2022-09-08 15:24               ` Robert Pluim
2022-09-08 15:34                 ` Christopher Dimech
2022-09-08 15:37                   ` Visuwesh
2022-09-08 15:39                   ` Robert Pluim
2022-09-08 16:43                     ` Christopher Dimech
2022-09-08 16:11               ` Eli Zaretskii
2022-09-08 16:38                 ` Christopher Dimech
2022-09-08 16:08           ` Eli Zaretskii
2022-09-09 15:09 ` Stefan Monnier [this message]
  -- strict thread matches above, loose matches on Subject: below --
2023-06-16 11:20 Android port of Emacs Eli Zaretskii
2023-06-16 15:16 ` Dr. Arne Babenhauserheide
2023-06-16 15:32   ` Eli Zaretskii
2023-06-17  0:49     ` Konstantin Kharlamov
2023-06-17  6:20       ` Eli Zaretskii
2023-06-17 13:34         ` Konstantin Kharlamov
2023-06-17 16:47           ` Alfred M. Szmidt
2023-06-17 18:11             ` contributing to Emacs Konstantin Kharlamov
2023-06-17 18:36               ` Alfred M. Szmidt
2023-06-17 19:39                 ` Konstantin Kharlamov
2023-06-17 21:00                   ` Alfred M. Szmidt
2023-06-17 21:10                     ` Konstantin Kharlamov
2023-06-17 21:19                       ` Alfred M. Szmidt
2023-06-17 21:26                         ` Konstantin Kharlamov
2023-06-17 22:25                           ` Alfred M. Szmidt
2023-06-17 22:39                             ` Konstantin Kharlamov
2023-06-18  5:20                               ` Eli Zaretskii
2023-06-18  8:53                                 ` Konstantin Kharlamov
2023-06-18  9:01                                   ` Po Lu
2023-06-18  9:23                                     ` Konstantin Kharlamov
2023-06-18  9:25                                       ` Po Lu
2023-06-18 10:04                                         ` Konstantin Kharlamov
2023-06-18 10:07                                           ` Po Lu
2023-06-18  9:57                                       ` Alfred M. Szmidt
2023-06-18  9:01                                   ` Eli Zaretskii
2023-06-18  9:06                                     ` Eli Zaretskii
2023-06-18  9:21                                       ` Konstantin Kharlamov
2023-06-18 12:00                                         ` Michael Albinus
2023-06-18  9:18                                     ` Konstantin Kharlamov
2023-06-18  9:35                                       ` Eli Zaretskii
2023-06-18 21:16                                         ` Dmitry Gutov
2023-06-18 10:00                                   ` Philip Kaludercic
2023-06-18 10:15                                     ` Konstantin Kharlamov
2023-06-18 10:22                                       ` Philip Kaludercic
2023-06-23  6:49                                         ` Sean Whitton
2023-06-24 15:37                                           ` Philip Kaludercic
2023-06-25  7:40                                             ` Sean Whitton
2023-06-18 12:13                                       ` Po Lu
2023-06-18 12:26                                         ` Konstantin Kharlamov
2023-06-18 13:43                                           ` Alfred M. Szmidt
2023-06-18 14:57                                             ` Dr. Arne Babenhauserheide
2023-06-18 16:29                                               ` Eli Zaretskii
2023-06-18 18:52                                                 ` Dr. Arne Babenhauserheide
2023-06-18 19:10                                                   ` Alfred M. Szmidt
2023-06-18 19:11                                                   ` Eli Zaretskii
2023-06-18 20:10                                                     ` Konstantin Kharlamov
2023-06-19  2:24                                                       ` Eli Zaretskii
2023-06-19  6:05                                                         ` Dr. Arne Babenhauserheide
2023-06-19 18:07                                                         ` David Masterson
2023-06-19 18:50                                                           ` Eli Zaretskii
2023-06-19 21:29                                                             ` Konstantin Kharlamov
2023-06-19 22:49                                                               ` David Masterson
2023-06-20 11:14                                                               ` Eli Zaretskii
2023-06-20 15:45                                                                 ` Konstantin Kharlamov
2023-06-20 16:14                                                                   ` Eli Zaretskii
2023-06-20 16:32                                                                     ` Lynn Winebarger
2023-06-20 16:42                                                                       ` Eli Zaretskii
2023-06-20 19:49                                                                     ` Konstantin Kharlamov
2023-06-24  1:44                                                                     ` Björn Bidar
2023-06-24  3:10                                                                       ` Po Lu
2023-06-24  7:00                                                                       ` Eli Zaretskii
2023-06-24  7:54                                                                         ` Michael Albinus
2023-06-25  2:25                                                                       ` Richard Stallman
2023-06-25 16:41                                                                         ` Corwin Brust
2023-06-25 23:31                                                                           ` Björn Bidar
2023-06-26 16:47                                                                             ` Ian Kelling
2023-06-27 11:08                                                                             ` Yuchen Pei
2023-06-27 13:52                                                                               ` Corwin Brust
2023-06-28  4:33                                                                               ` Björn Bidar
2023-06-29  3:03                                                                               ` Richard Stallman
2023-07-03  2:32                                                                                 ` Björn Bidar
2023-07-03  4:25                                                                                   ` Dr. Arne Babenhauserheide
2023-07-05  2:07                                                                                     ` Richard Stallman
2023-07-04  1:58                                                                                   ` Richard Stallman
2023-07-05 13:19                                                                                 ` Yuchen Pei
2023-07-09  2:53                                                                                   ` Richard Stallman
2023-06-27  1:05                                                                           ` Richard Stallman
2023-06-28  2:18                                                                           ` Richard Stallman
2023-06-20 16:24                                                                   ` Alfred M. Szmidt
2023-06-20 16:33                                                                   ` Dr. Arne Babenhauserheide
2023-06-19 22:47                                                             ` David Masterson
2023-06-20  1:17                                                               ` Po Lu
2023-06-20  2:24                                                                 ` David Masterson
2023-06-20  7:01                                                                 ` Alfred M. Szmidt
2023-06-21  0:51                                                                 ` Richard Stallman
2023-06-21  4:13                                                                   ` Po Lu
2023-06-21  4:23                                                                   ` David Masterson
2023-06-23  1:47                                                                     ` Richard Stallman
2023-06-23  2:28                                                                       ` Po Lu
2023-06-25  2:25                                                                         ` Richard Stallman
2023-06-20 11:20                                                               ` Eli Zaretskii
2023-06-18  8:34                               ` Alfred M. Szmidt
2023-06-18  8:58                                 ` Konstantin Kharlamov
2023-06-18  0:50                             ` Po Lu
2023-06-20  2:55                               ` Richard Stallman
2023-06-20  3:39                                 ` Po Lu
2023-06-21  9:20                                   ` Gregory Heytings
2023-06-22  1:56                                   ` Richard Stallman
2023-06-22  2:23                                     ` Po Lu
2023-06-22  7:47                                       ` Philip Kaludercic
2023-06-22  7:59                                         ` Po Lu
2023-06-22  8:38                                         ` Dr. Arne Babenhauserheide
2023-06-20 11:30                                 ` Eli Zaretskii
2023-06-17 21:44                         ` chad
2023-06-18  9:26                     ` Dr. Arne Babenhauserheide
2023-06-18 10:05                       ` Eli Zaretskii
2023-06-18 10:30                         ` Dr. Arne Babenhauserheide
2023-06-18 10:52                           ` Eli Zaretskii
2023-06-18 11:00                             ` Dr. Arne Babenhauserheide
2023-06-18 10:57                       ` Konstantin Kharlamov
2023-06-18  8:59                   ` Dr. Arne Babenhauserheide
2023-06-18  9:30                     ` Konstantin Kharlamov
2023-06-18  9:34                       ` Konstantin Kharlamov
2023-06-18  9:56                       ` Konstantin Kharlamov
2023-06-18 10:02                         ` Eli Zaretskii
2023-06-18 10:13                           ` Konstantin Kharlamov
2023-06-18 10:22                             ` Eli Zaretskii
2023-06-18 10:27                               ` Konstantin Kharlamov
2023-06-18 10:36                                 ` Eli Zaretskii
2023-06-18 10:44                                   ` Konstantin Kharlamov
2023-06-18 10:59                                     ` Eli Zaretskii
2023-06-18 11:14                                       ` Konstantin Kharlamov
2023-06-18 11:32                                         ` Eli Zaretskii
2023-06-18 11:54                                           ` Konstantin Kharlamov
2023-06-18 12:18                                             ` Eli Zaretskii
2023-06-18 12:24                                               ` Konstantin Kharlamov
2023-06-18 15:20                                                 ` Dr. Arne Babenhauserheide
2023-06-18 10:54                                 ` Dr. Arne Babenhauserheide
2023-06-18 11:11                                   ` Konstantin Kharlamov
2023-06-18 12:10                                 ` Po Lu
2023-06-18 12:28                                   ` Konstantin Kharlamov
2023-06-18 12:51                                     ` Eli Zaretskii
2023-06-18 13:02                                       ` Konstantin Kharlamov
2023-06-18 13:13                                         ` Eli Zaretskii
2023-06-18 13:32                                     ` Po Lu
2023-06-18 13:50                                       ` Konstantin Kharlamov
2023-06-18 10:12                         ` Po Lu
2023-06-18 10:22                           ` Konstantin Kharlamov
2023-06-18 12:09                             ` Po Lu
2023-06-18 12:30                               ` Konstantin Kharlamov
2023-06-18 13:29                                 ` Po Lu
2023-06-18 13:55                                   ` Konstantin Kharlamov
2023-06-18 12:33                               ` Konstantin Kharlamov
2023-06-18 13:30                                 ` Po Lu
2023-06-18 13:57                                   ` Konstantin Kharlamov
2023-06-23  6:51                           ` Sean Whitton
2023-06-23  7:06                             ` Po Lu
2023-06-23  7:14                               ` Sean Whitton
2023-06-23  7:17                             ` Eli Zaretskii
2023-06-24  7:21                               ` Sean Whitton
2023-06-24  7:43                                 ` Eli Zaretskii
2023-06-24 12:36                                   ` Konstantin Kharlamov
2023-06-24 14:44                                     ` Eli Zaretskii
2023-06-24 16:17                                       ` Konstantin Kharlamov
2023-06-24 17:13                                         ` Eli Zaretskii
2023-06-25  7:39                                   ` Sean Whitton
2023-06-18  9:43                     ` Eli Zaretskii
2023-06-18 10:19                       ` Dr. Arne Babenhauserheide
2023-06-18 10:31                         ` Eli Zaretskii
2023-06-18 10:50                           ` Dr. Arne Babenhauserheide
2023-06-18 11:29                             ` Eli Zaretskii
2013-03-20  5:44 Contributing " Jacob Criner
2013-03-21  7:49 ` Xue Fuqiao
2013-03-26 16:58 ` Stefan Monnier
2013-03-26 17:33   ` Drew Adams

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=jwvfsh0wqfx.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=jaopaulolc@gmail.com \
    /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).