From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lynn Winebarger Newsgroups: gmane.emacs.help Subject: Re: inline function expansion Date: Thu, 11 May 2023 03:11:14 -0400 Message-ID: References: <87bkivhqip.fsf@posteo.net> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25756"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs@gnu.org To: Philip Kaludercic , Stefan Monnier Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu May 11 09:12:10 2023 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1px0TB-0006Se-4x for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 11 May 2023 09:12:09 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1px0Sb-0003R9-SN; Thu, 11 May 2023 03:11:33 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1px0SY-0003NQ-D1 for help-gnu-emacs@gnu.org; Thu, 11 May 2023 03:11:31 -0400 Original-Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1px0SW-0000AI-NP for help-gnu-emacs@gnu.org; Thu, 11 May 2023 03:11:30 -0400 Original-Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-250175762b8so7104136a91.1 for ; Thu, 11 May 2023 00:11:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683789086; x=1686381086; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=uuVjgtSdV0afjcgv9E5Qkj+1znBCoIWVHZjQzrfYVLQ=; b=ACmgJOpi2wqqDpAk1hD+mOCzeBlU2yyEFhmDGCTxYgvjp2yWivDchsM63xZt1wozdo dRd8FKmu3rgQQasuzEua7xBB9ifVo2nnNwhkzgVQVgqDQhFUhqoPyR7Sqa3BweqnbDXa NT8RxtGEnA4CsEUnmxHt+hpkZtAFj2jNTcVOr9xA5rlSBMj5vZR8kgzQNEnBzYZWAsl6 24V0cCygDKLuucwtqYv60Lcx5dX6PIg89WskItAlZqmL+/EP/7vvtyO3Y1v3umopG2LT yPC+XcQR1Z8NC9HhZP7UEeSWJP2zrYd+ZRMeCIgZfEGX92kOklkWkmgVrQmrOAvUMrug QoUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683789086; x=1686381086; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uuVjgtSdV0afjcgv9E5Qkj+1znBCoIWVHZjQzrfYVLQ=; b=Oji3JwtsJeBVM5lu+0+L9V/dV0C/BFcm5zQXee+mDn20TIK3JkeqQna7373LkXrPb9 vURDPUh1FmT0xIqQJmPaG6yTd7irayxzzHVJ8PrH4MheoojOQ9WOnYM9/u8bvhMR+ln3 QEJFUcVvu0RnOH81WgBPo1DnZW8a30jDPfy6QNijyzbTRc4JoUoRVX5/TvXbnJQONOUf naXhqZioAjt4cozSl8em29ZloZ0vzrw5xLlzJtIfTW5YLb6mZmZzYmJiE4K1df1jOG5r c6pymGnCsuobLC7IypLV8SkSsqqIHDdu+5s1QWn5PHuUgoy9aXrE4vrzf1PWoxqVtwsf 8N7A== X-Gm-Message-State: AC+VfDy69lqb0HqAOlh6zADmd2SLHDNJZINtfBDCNJfO5HycnT/7qTA1 fN7wYUFJXm3INDeFvmeWpEP4E6ZH9M7EQ4XcuIo= X-Google-Smtp-Source: ACHHUZ42ApqIsGcUO1MH9vndFPGfjuBgGz/oG4XY1SiB2/H97Z8pMnLBZbbKrtksrsTPGCR0vahxx/usmarM/MpwWn0= X-Received: by 2002:a17:90a:318c:b0:247:53b4:ec52 with SMTP id j12-20020a17090a318c00b0024753b4ec52mr20333423pjb.8.1683789085614; Thu, 11 May 2023 00:11:25 -0700 (PDT) In-Reply-To: <87bkivhqip.fsf@posteo.net> Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=owinebar@gmail.com; helo=mail-pj1-x102c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:143560 Archived-At: On Sun, May 7, 2023 at 3:48=E2=80=AFPM Philip Kaludercic wrote: > Lynn Winebarger 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