From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Using funcall on inline functions Date: Sat, 12 Dec 2020 18:28:59 -0500 Message-ID: References: <87bleyd4hz.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38218"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Eric Abrahamsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Dec 13 00:29:47 2020 Return-path: Envelope-to: ged-emacs-devel@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 1koEKh-0009pj-AR for ged-emacs-devel@m.gmane-mx.org; Sun, 13 Dec 2020 00:29:47 +0100 Original-Received: from localhost ([::1]:39274 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1koEKg-00042L-9m for ged-emacs-devel@m.gmane-mx.org; Sat, 12 Dec 2020 18:29:46 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55022) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1koEK1-0003b5-MR for emacs-devel@gnu.org; Sat, 12 Dec 2020 18:29:05 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:15642) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1koEJy-0005sS-VF for emacs-devel@gnu.org; Sat, 12 Dec 2020 18:29:04 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 300928033C; Sat, 12 Dec 2020 18:29:01 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id C367580675; Sat, 12 Dec 2020 18:28:59 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1607815739; bh=Qq9XAWZjGufxFO5V6es27FADyfK6JbYYaqUpxh4bY2I=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=mOzQ/gsVF/RUDAk+FkulaX5+os5pP692GRKC6+HO2epXYCeBxNUMgWSJ9R7z7T1OI YfXsxuYx4c3L5IdZ/t+nChTWg+aJwo+3zuhYbn0NN1kFBTINY+8PIK/yN5TUEYMzbW Pq/DyeG24R16b52dkg3P1xmeo2+pAVjVltnqw13dIppvKj7J5sY7slddIZ5Jx/hNlM XUG0QwPiYNwqrC275b8/PmD1EMCFuay/muaciOvBI1QDaDKwmVbJ/uwdQyFKAtdKJA 8p2nSW7svR3a2qC4tux9O85HL6fMv3qiKUdSHSi1ZrSjnOLy3Yj4q584FTUcUbmOsW yfvdnbueWP0YA== Original-Received: from alfajor (69-165-136-52.dsl.teksavvy.com [69.165.136.52]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 98228120257; Sat, 12 Dec 2020 18:28:59 -0500 (EST) In-Reply-To: <87bleyd4hz.fsf@ericabrahamsen.net> (Eric Abrahamsen's message of "Sat, 12 Dec 2020 14:49:28 -0800") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:260736 Archived-At: > (define-inline ebdb-add-to-list (list-var element) > (inline-quote (when, element > (cl-pushnew, element, list-var :test #'equal)))) This can't work: your argument is named "list-var" but the way you use it in the body indicates that it's supposed to be a *list* not a *list variable*. It may happen to work in some cases when the function gets inlined, but if so, it's actually showing a misfeature of the `define-inline` implementation (result of some optimizations). You can't have it both way: if `ebdb-add-to-list` is a function, then `list-var` is a local variable and this argument uses the usual pass-by-value semantics (and hence `cl-pushnew` will only affect that local variable). If you want `list-var` to be the name of the *place* passed by the caller then it has to be a macro. There is a workaround, then, which is to use a reference: (cl-defstruct ebdb-record-cache (alt-names nil :type list)) (defclass ebdb-record () ((cache :type ebdb-record-cache))) (define-inline ebdb-record-alt-names (record) (inline-quote (ebdb-record-cache-alt-names (slot-value,record 'cache)))) (define-inline ebdb-add-to-list (list-ref element) (inline-quote (when ,element (cl-pushnew ,element (gv-deref ,list-ref) :test #'equal)))) (let ((listfunc #'ebdb-add-to-list) (name-string "Bob's new name")) (funcall listfunc (gv-ref (ebdb-record-alt-names )) name-string)) [ BTW, your `ebdb-add-to-list` has a bug in that it will evaluate its second argument before its first. ] Stefan