[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: |
Thu, 11 May 2023 03:11:14 -0400 |
On Sun, May 7, 2023 at 3:48 PM Philip Kaludercic <philipk@posteo.net> wrote:
> Lynn Winebarger <owinebar@gmail.com> writes:
> > If I use define-inline, I would like to be able to verify that the
> > result is what I expect, or vice versa, that I understand what the
> > result will be well enough to have the correct expectation.
>
> Isn't the idea of inlining that the behaviour/effect of invoking a
> function shouldn't change, just that the resulting code might be more
> efficient?
I was working off of the description in "Evolution of Emacs Lisp",
page 45, which gives the example of cl-type-p for evaluation of
constant expressions at compile-time via inline functions (figure 2):
(define-inline cl-typep (val type)
(inline-letevals (val)
(pcase (inline-const-val type)
(`(not ,ty)
(inline-quote (not (cl-typep ,val ',ty))))
(`(eql ,v)
(inline-quote (eql ,val ',v)))
(`(satisfies ,pred) (inline-quote (funcall #',pred ,val)))
((and (pred symbolp) ty (guard (get ty 'cl-deftype-satisfies)))
(inline-quote (funcall #',(get ty 'cl-deftype-satisfies) ,val)))
...
(ty (error "Bad type spec: %s" ty)))))
The info documentation does not include any examples involving
inline-const-p, and in fact, I cannot find any code in the emacs lisp
directory, or in the source of a couple of thousand packages, that
makes use of inline-const-p or inline-const-val *other* than this
exact function.
I'd like to define inline- variants of pure subrs, e.g. arithmetic
operators, type-predicates, that evaluate during macroexpansion rather
than involving the compiler's optimization phase. 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. Unfortunately, I don't see how I can write something like
(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))))
Admittedly, I haven't actually tried the code above, but if I
understand the define-inline macro, the defun would include the "if"
statement, and that is not the intension.
I can still define the kind of inlined primitives described above
using a macro based on define-inline's approach of defining a compiler
macro and a defun, but I'm not seeing how to use the existing inline-*
machinery to do it. Am I missing something?
Lynn
- inline function expansion, Lynn Winebarger, 2023/05/07
- Re: inline function expansion, Basile Starynkevitch, 2023/05/07
- Re: inline function expansion, Philip Kaludercic, 2023/05/07
- Re: inline function expansion, Lynn Winebarger, 2023/05/07
- Re: inline function expansion,
Lynn Winebarger <=
- Re: inline function expansion, Emanuel Berg, 2023/05/13
- Re: inline function expansion, Lynn Winebarger, 2023/05/18
- Re: inline function expansion, Stefan Monnier, 2023/05/19
- Re: inline function expansion, Lynn Winebarger, 2023/05/20
- Re: inline function expansion, Stefan Monnier, 2023/05/20
- Re: inline function expansion, Lynn Winebarger, 2023/05/21
- Re: inline function expansion, Stefan Monnier, 2023/05/18
- Re: inline function expansion, Lynn Winebarger, 2023/05/18
- Re: inline function expansion, Stefan Monnier, 2023/05/19
- Re: inline function expansion, Lynn Winebarger, 2023/05/20