help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: inline function expansion


From: Lynn Winebarger
Subject: Re: inline function expansion
Date: Sun, 21 May 2023 08:47:23 -0400

On Sat, May 20, 2023 at 11:32 AM Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
> >> You're right, tho in practice number is either nil or non-constant, so
> >> it doesn't make much difference.
> > I'm just pointing out it is difficult to tell how to use the
> > facilities for compile-time evaluation provided by define-inline.
>
> Oh, that, yes the `define-inline` facility is hard to use, no doubt.
> I'm not happy with it.  This is also reflected in the lack of doc
> because it's difficult to document it much better than "look at the
> code, try it out, and fiddle until it works" :-(

Couldn't most (all but 2) of the current instances be captured by a
simplified interface defsubst* defined along the lines of:
(defmacro defsubst* (name args &rest body)
  (let ((parameters (inline--get-parameters args)))
    `(define-inline ,name ,args
       (inline-letevals
        ,(inline--susbt*-bindings args)
        (inline-quote
         (cl-symbol-macrolet
             ,(mapcar (lambda (v) `(,v (,'\, ,v))) parameters)
           ,@body))))))

Where I've left the ugly details of handling lambda lists to
inline--get-parameters and inline--subst*-bindings.  I'm unclear on
why defsubst* is an improvement on defsubst.

> >>     (define-inline cconv--var-classification (binder form)
> >>       (inline-quote
> >>        (cdr (assoc ,(cons (inline-const-val binder)
> >>                           (inline-const-val form))
> >>                    cconv-var-classification))))
> >
> > Don't you need something to add a quote to the cons cell when "binder"
> > or "form" are not constant?
>
> Oh, you're right.
>
> >> but here as well, this optimization would never apply because those args
> >> are never literal constants.  Worse: the failure of `inline-const-val`
> >> would cause the whole inlining to fail :-(
> > Could inline--do-quote catch the throw?
>
> It could, but it doesn't (and it would be an incompatible change).

As far as I can tell, the only code that makes use of inline-const-val
is cl-typep, so the impact of any incompatibility should be (famous
last words) controllable.  Is the issue figuring out how to define
inline-letevals so that inline-const-val would be able to "see
through" it when the parameter is constant but be bound by it when it
is not constant?

> > The byte-opt.el code from v28.2.50 says it's because the third
> > argument may be an impure function:
> >          ;; `assoc' and `assoc-default' are excluded since they are
> >          ;; impure if the test function is (consider `string-match').
> > I'm not sure why the possibility of signaling an error alone would be
> > disqualifying.  For example, (+ 5 's) signals an error.
>
> Oh, you're right, sorry.  So the problem is if the test function is
> constant but not pure.
>
> > Also, I don't get why logand isn't considered a pure function
>
> What makes you think it's not?
>
Faulty memory - I was thinking of lsh as mentioned in this comment
from byte-opt.el:
;; Pure functions are side-effect free functions whose values depend
;; only on their arguments, not on the platform.  For these functions,
;; calls with constant arguments can be evaluated at compile time.
;; For example, ash is pure since its results are machine-independent,
;; whereas lsh is not pure because (lsh -1 -1)'s value depends on the
;; fixnum range.

> > How important is it to be able to run byte-code generated by
> > a 32-bit emacs in a 64-bit emacs (or vice-versa)?
>
> The Emacs tarball comes with all the `.elc` files, so it's important
> that `.elc` files be portable across architectures.

Interesting restriction.

Lynn



reply via email to

[Prev in Thread] Current Thread [Next in Thread]