From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.devel Subject: Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms Date: Sat, 7 Dec 2024 22:39:21 -0800 Message-ID: <292D0D0F-AB88-49AB-86DD-A9B736DB00F7@gmail.com> References: <2C0B7D3A-6131-4427-BF04-9211981B57DD@gmail.com> <867c8g3o6v.fsf@gnu.org> <0D278D91-4D67-4E0E-869F-6AF0A46678F7@gmail.com> <86h67jz36z.fsf@gnu.org> <502D58B8-9432-4A8F-B50D-ECA392B7E7C5@gmail.com> <86ser2y5e1.fsf@gnu.org> <86ser0j5hw.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_EBBCDC2C-CE7D-4FA4-BCBF-DBD97C39F887" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38747"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Dec 08 07:40:25 2024 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 1tKAxt-0009wF-Di for ged-emacs-devel@m.gmane-mx.org; Sun, 08 Dec 2024 07:40:25 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tKAxB-0004fN-57; Sun, 08 Dec 2024 01:39:41 -0500 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 1tKAx8-0004fE-MK for emacs-devel@gnu.org; Sun, 08 Dec 2024 01:39:38 -0500 Original-Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tKAx7-00048N-8g; Sun, 08 Dec 2024 01:39:38 -0500 Original-Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-723f37dd76cso3028564b3a.0; Sat, 07 Dec 2024 22:39:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733639974; x=1734244774; darn=gnu.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=uDYJKKh570AHwqKlPpcch0obw6Jic/Udk7WJI5kFGtg=; b=cmKxAKa454/IS/ajtWUhrbidE9Bx4A9gFriUhOWlm6MeptrUB5VC6a2biXFlWxvowO dmmmrgJ2G8FG3H2Ri+N10+LOMMpwW/qkHuqIkGX3sglv8W8mXF9XRVXdhsuiI02veu8x xp/ppuhDb2aSmry6pdWdJd0msbkbnVgxgalZMY3TEzmNxB2KudukMERlpw7CBpGyw8Nq gCXQ2LDhrvklgQcdSVB0Ll8lKOcG7vXX3kt3rLPdBdSok0NIqBP3ggGmtY3qJfT0RzDR ZLTArybvQwJf6Oz9wwjxxzJ1YLrXvJVKrnZmM+ajWrdvYdtNbhXYJA+dLR9TbN23SWRm pGfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733639974; x=1734244774; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uDYJKKh570AHwqKlPpcch0obw6Jic/Udk7WJI5kFGtg=; b=Vu2ggLmHI45hcf0tw1dWlfvsvt8BfEtAHbdWyt7eR+kiMcz4vnh8IFJfAfUI/Nl0wd uc2Z3xmJ9Tj1nZvdvVS4hZrxsARzWxRVmiUVEJwZuLIu+xHQ3bsMENnItvYdDuiJ8Tiy sP/RZM6wiyMcQnmZv+IQbu2UqXYNCzQ/JR5KOyBTYaMFMSepoBjdkROEn4rskFbrM6Rj 9U4Dircn0ohZUrRUK93Lahg01bmOwfjclEm1a7Nr3ewz8JneiGP2pcepKjLt1VmTsA3U jIr5Klt6dpRFeFd1nPsVlZS6EYA9gp6+GmW7SMapAJtADSJGvygbgEk3KEuQBs+QueA2 Fzfw== X-Forwarded-Encrypted: i=1; AJvYcCV9cDH+J5XAGUr4n3O12mjYzwa/Zr1q/A+711h1PMIWlXIB3pUv5eIPrHV5CCHhGhLQFnj4cfjdXgq3Jg==@gnu.org X-Gm-Message-State: AOJu0Yxu3Llg37122OAeBvyThwFTBCD7vLbJgSkEE82aRW6HKUigxhLR S+1Q0+Gmoh2hh85cQQtvdBaZl9TnCDt3bqRczeuTp+lL1tyzT8BaFo/TTw== X-Gm-Gg: ASbGncu8DxwnFfBcALBwspcsL0EydrXCoAycdecFH2NTRIja197C7QrJljJjnbWx1pR IjADafQr6GaOGCR/xKEZCgDh6pzZU1jcX0KglyXWp4D/hWZMM8f1m6pD5i6OeohXM2AzoxAWFDq Vv+nv7lwldZ50SHkbSLwPF332zBXjTkvNB3FWqBxQHJWWqlkCFFmBCVbWBs7etYc3L/BWTFt683 2NT6TqJlZrhcGI/C9kYSD213wnTIW2RpMdSE89IgpLUbGe+RfW8pNeWLEVk3n9xcLTT9to53Q== X-Google-Smtp-Source: AGHT+IHa2WoDmF9K1UjfwbO+lLhG2tDaOPWBhA6MHWOMZA4XS6vidAcLizuh7YqapQVpxNoj5eywPQ== X-Received: by 2002:a05:6a00:92a6:b0:71e:6c3f:2fb6 with SMTP id d2e1a72fcca58-725b80ff2f7mr14359974b3a.8.1733639973968; Sat, 07 Dec 2024 22:39:33 -0800 (PST) Original-Received: from smtpclient.apple ([2601:646:8f81:6120:d59e:a328:96f3:f483]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-725e34bbb17sm739152b3a.56.2024.12.07.22.39.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Dec 2024 22:39:33 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.3776.700.51) Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=casouri@gmail.com; helo=mail-pf1-x429.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:326179 Archived-At: --Apple-Mail=_EBBCDC2C-CE7D-4FA4-BCBF-DBD97C39F887 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Dec 7, 2024, at 5:47=E2=80=AFAM, Stefan Monnier = wrote: >=20 >>> Does that mean declare-function forms only affect the file it=E2=80=99= s in? >>> Because if treesit.el has declare-function forms for all the = treesit.c >>> functions, and c-ts-mode.el requires treesit.el, why do we need to = have >>> declare-function forms in c-ts-mode.el? >> Seems like that. Stefan, am I missing something here? >=20 > Yes, `declare-function` *should* follow the same principles as = `(defvar > FOO)`, meaning that they are compiler directives not functions to > execute. They affect warnings only in the current lexical scope, and > requiring a file full of `(defvar FOO)` and `declare-function` will = have > no effect at all. >=20 > [ Side note regarding this *should*: it currently doesn't work quite = as > well as `defvar` because its effect is always file-wide, whereas it > should be limited to the current scope. ] Defining a macro that contains the declare-function forms, and calling = it in eval-when-compile forms seem to work (see patch), WDYT? The name = (treesit-declare-c-functions) could be better, any ideas? Yuan --Apple-Mail=_EBBCDC2C-CE7D-4FA4-BCBF-DBD97C39F887 Content-Disposition: attachment; filename=declare-function.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="declare-function.patch" Content-Transfer-Encoding: quoted-printable =46rom=20ba77886d5e250770251d8c1abec93d4fcf0e0268=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Yuan=20Fu=20=0ADate:=20Sat,=20= 7=20Dec=202024=2022:13:07=20-0800=0ASubject:=20[PATCH]=20= declare-function=20POC=0A=0A---=0A=20lisp/progmodes/c-ts-mode.el=20|=20=20= 17=20+-----=0A=20lisp/treesit.el=20=20=20=20=20=20=20=20=20=20=20=20=20|=20= 103=20++++++++++++++++++++----------------=0A=202=20files=20changed,=20= 60=20insertions(+),=2060=20deletions(-)=0A=0Adiff=20--git=20= a/lisp/progmodes/c-ts-mode.el=20b/lisp/progmodes/c-ts-mode.el=0Aindex=20= dec9411b87c..4a1f616b048=20100644=0A---=20a/lisp/progmodes/c-ts-mode.el=0A= +++=20b/lisp/progmodes/c-ts-mode.el=0A@@=20-73,21=20+73,8=20@@=0A=20= (require=20'c-ts-common)=0A=20(eval-when-compile=20(require=20'rx))=0A=20= =0A-(declare-function=20treesit-parser-create=20"treesit.c")=0A= -(declare-function=20treesit-parser-root-node=20"treesit.c")=0A= -(declare-function=20treesit-parser-set-included-ranges=20"treesit.c")=0A= -(declare-function=20treesit-node-parent=20"treesit.c")=0A= -(declare-function=20treesit-node-start=20"treesit.c")=0A= -(declare-function=20treesit-node-end=20"treesit.c")=0A= -(declare-function=20treesit-node-child=20"treesit.c")=0A= -(declare-function=20treesit-node-child-by-field-name=20"treesit.c")=0A= -(declare-function=20treesit-node-type=20"treesit.c")=0A= -(declare-function=20treesit-node-prev-sibling=20"treesit.c")=0A= -(declare-function=20treesit-node-first-child-for-pos=20"treesit.c")=0A= -(declare-function=20treesit-node-next-sibling=20"treesit.c")=0A= -(declare-function=20treesit-node-eq=20"treesit.c")=0A-(declare-function=20= treesit-node-match-p=20"treesit.c")=0A-(declare-function=20= treesit-query-compile=20"treesit.c")=0A+(eval-when-compile=0A+=20=20= (treesit-declare-c-functions))=0A=20=0A=20;;;=20Custom=20variables=0A=20=0A= diff=20--git=20a/lisp/treesit.el=20b/lisp/treesit.el=0Aindex=20= db3a706f016..2e189394983=20100644=0A---=20a/lisp/treesit.el=0A+++=20= b/lisp/treesit.el=0A@@=20-39,61=20+39,74=20@@=0A=20=0A=20;;;=20Function=20= declarations=0A=20=0A-(declare-function=20treesit-language-available-p=20= "treesit.c")=0A-(declare-function=20treesit-language-version=20= "treesit.c")=0A+(defmacro=20treesit-declare-c-functions=20()=0A+=20=20= "Declare=20C=20functions=20and=20variables=20defined=20in=20treesit.c.=0A= =20=0A-(declare-function=20treesit-parser-p=20"treesit.c")=0A= -(declare-function=20treesit-node-p=20"treesit.c")=0A-(declare-function=20= treesit-compiled-query-p=20"treesit.c")=0A-(declare-function=20= treesit-query-p=20"treesit.c")=0A-(declare-function=20= treesit-query-language=20"treesit.c")=0A+This=20macro=20is=20only=20= needed=20for=20byte-compiling=20in=20Emacs=20not=20built=20with=0A= +tree-sitter=20library.=20=20It=20should=20be=20used=20with=20= `eval-when-compile'=20like=0A+this:=0A=20=0A-(declare-function=20= treesit-node-parser=20"treesit.c")=0A+=20=20=20=20(eval-when-compile=0A+=20= =20=20=20=20=20(treesit-declare-c-functions))"=0A+=20=20'(progn=0A+=20=20= =20=20=20(declare-function=20treesit-language-available-p=20"treesit.c")=0A= +=20=20=20=20=20(declare-function=20treesit-language-version=20= "treesit.c")=0A=20=0A-(declare-function=20treesit-parser-create=20= "treesit.c")=0A-(declare-function=20treesit-parser-delete=20"treesit.c")=0A= -(declare-function=20treesit-parser-list=20"treesit.c")=0A= -(declare-function=20treesit-parser-buffer=20"treesit.c")=0A= -(declare-function=20treesit-parser-language=20"treesit.c")=0A= -(declare-function=20treesit-parser-tag=20"treesit.c")=0A+=20=20=20=20=20= (declare-function=20treesit-parser-p=20"treesit.c")=0A+=20=20=20=20=20= (declare-function=20treesit-node-p=20"treesit.c")=0A+=20=20=20=20=20= (declare-function=20treesit-compiled-query-p=20"treesit.c")=0A+=20=20=20=20= =20(declare-function=20treesit-query-p=20"treesit.c")=0A+=20=20=20=20=20= (declare-function=20treesit-query-language=20"treesit.c")=0A=20=0A= -(declare-function=20treesit-parser-root-node=20"treesit.c")=0A+=20=20=20= =20=20(declare-function=20treesit-node-parser=20"treesit.c")=0A=20=0A= -(declare-function=20treesit-parser-set-included-ranges=20"treesit.c")=0A= -(declare-function=20treesit-parser-included-ranges=20"treesit.c")=0A= -(declare-function=20treesit-parser-changed-ranges=20"treesit.c")=0A= -(declare-function=20treesit-parser-add-notifier=20"treesit.c")=0A+=20=20= =20=20=20(declare-function=20treesit-parser-create=20"treesit.c")=0A+=20=20= =20=20=20(declare-function=20treesit-parser-delete=20"treesit.c")=0A+=20=20= =20=20=20(declare-function=20treesit-parser-list=20"treesit.c")=0A+=20=20= =20=20=20(declare-function=20treesit-parser-buffer=20"treesit.c")=0A+=20=20= =20=20=20(declare-function=20treesit-parser-language=20"treesit.c")=0A+=20= =20=20=20=20(declare-function=20treesit-parser-tag=20"treesit.c")=0A=20=0A= -(declare-function=20treesit-node-type=20"treesit.c")=0A= -(declare-function=20treesit-node-start=20"treesit.c")=0A= -(declare-function=20treesit-node-end=20"treesit.c")=0A= -(declare-function=20treesit-node-string=20"treesit.c")=0A= -(declare-function=20treesit-node-parent=20"treesit.c")=0A= -(declare-function=20treesit-node-child=20"treesit.c")=0A= -(declare-function=20treesit-node-check=20"treesit.c")=0A= -(declare-function=20treesit-node-field-name-for-child=20"treesit.c")=0A= -(declare-function=20treesit-node-child-count=20"treesit.c")=0A= -(declare-function=20treesit-node-child-by-field-name=20"treesit.c")=0A= -(declare-function=20treesit-node-next-sibling=20"treesit.c")=0A= -(declare-function=20treesit-node-prev-sibling=20"treesit.c")=0A= -(declare-function=20treesit-node-first-child-for-pos=20"treesit.c")=0A= -(declare-function=20treesit-node-descendant-for-range=20"treesit.c")=0A= -(declare-function=20treesit-node-eq=20"treesit.c")=0A+=20=20=20=20=20= (declare-function=20treesit-parser-root-node=20"treesit.c")=0A=20=0A= -(declare-function=20treesit-pattern-expand=20"treesit.c")=0A= -(declare-function=20treesit-query-expand=20"treesit.c")=0A= -(declare-function=20treesit-query-compile=20"treesit.c")=0A= -(declare-function=20treesit-query-capture=20"treesit.c")=0A+=20=20=20=20= =20(declare-function=20treesit-parser-set-included-ranges=20"treesit.c")=0A= +=20=20=20=20=20(declare-function=20treesit-parser-included-ranges=20= "treesit.c")=0A+=20=20=20=20=20(declare-function=20= treesit-parser-changed-ranges=20"treesit.c")=0A+=20=20=20=20=20= (declare-function=20treesit-parser-add-notifier=20"treesit.c")=0A=20=0A= -(declare-function=20treesit-search-subtree=20"treesit.c")=0A= -(declare-function=20treesit-search-forward=20"treesit.c")=0A= -(declare-function=20treesit-induce-sparse-tree=20"treesit.c")=0A= -(declare-function=20treesit-subtree-stat=20"treesit.c")=0A= -(declare-function=20treesit-node-match-p=20"treesit.c")=0A+=20=20=20=20=20= (declare-function=20treesit-node-type=20"treesit.c")=0A+=20=20=20=20=20= (declare-function=20treesit-node-start=20"treesit.c")=0A+=20=20=20=20=20= (declare-function=20treesit-node-end=20"treesit.c")=0A+=20=20=20=20=20= (declare-function=20treesit-node-string=20"treesit.c")=0A+=20=20=20=20=20= (declare-function=20treesit-node-parent=20"treesit.c")=0A+=20=20=20=20=20= (declare-function=20treesit-node-child=20"treesit.c")=0A+=20=20=20=20=20= (declare-function=20treesit-node-check=20"treesit.c")=0A+=20=20=20=20=20= (declare-function=20treesit-node-field-name-for-child=20"treesit.c")=0A+=20= =20=20=20=20(declare-function=20treesit-node-child-count=20"treesit.c")=0A= +=20=20=20=20=20(declare-function=20treesit-node-child-by-field-name=20= "treesit.c")=0A+=20=20=20=20=20(declare-function=20= treesit-node-next-sibling=20"treesit.c")=0A+=20=20=20=20=20= (declare-function=20treesit-node-prev-sibling=20"treesit.c")=0A+=20=20=20= =20=20(declare-function=20treesit-node-first-child-for-pos=20= "treesit.c")=0A+=20=20=20=20=20(declare-function=20= treesit-node-descendant-for-range=20"treesit.c")=0A+=20=20=20=20=20= (declare-function=20treesit-node-eq=20"treesit.c")=0A=20=0A= -(declare-function=20treesit-available-p=20"treesit.c")=0A+=20=20=20=20=20= (declare-function=20treesit-pattern-expand=20"treesit.c")=0A+=20=20=20=20= =20(declare-function=20treesit-query-expand=20"treesit.c")=0A+=20=20=20=20= =20(declare-function=20treesit-query-compile=20"treesit.c")=0A+=20=20=20=20= =20(declare-function=20treesit-query-capture=20"treesit.c")=0A=20=0A= -(defvar=20treesit-thing-settings)=0A+=20=20=20=20=20(declare-function=20= treesit-search-subtree=20"treesit.c")=0A+=20=20=20=20=20= (declare-function=20treesit-search-forward=20"treesit.c")=0A+=20=20=20=20= =20(declare-function=20treesit-induce-sparse-tree=20"treesit.c")=0A+=20=20= =20=20=20(declare-function=20treesit-subtree-stat=20"treesit.c")=0A+=20=20= =20=20=20(declare-function=20treesit-node-match-p=20"treesit.c")=0A+=0A+=20= =20=20=20=20(declare-function=20treesit-available-p=20"treesit.c")=0A+=0A= +=20=20=20=20=20(defvar=20treesit-thing-settings)))=0A+=0A= +(eval-when-compile=0A+=20=20(treesit-declare-c-functions))=0A=20=0A=20= ;;;=20Custom=20options=0A=20=0A--=20=0A2.39.5=20(Apple=20Git-151)=0A=0A= --Apple-Mail=_EBBCDC2C-CE7D-4FA4-BCBF-DBD97C39F887 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii --Apple-Mail=_EBBCDC2C-CE7D-4FA4-BCBF-DBD97C39F887--