From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms Date: Thu, 12 Dec 2024 08:43:39 +0200 Message-ID: <86ed2d1jvo.fsf@gnu.org> References: <2C0B7D3A-6131-4427-BF04-9211981B57DD@gmail.com> <867c8g3o6v.fsf@gnu.org> <0D278D91-4D67-4E0E-869F-6AF0A46678F7@gmail.com> <791c31a1-84ab-4cab-921b-cc8977e980d9@gutov.dev> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4098"; mail-complaints-to="usenet@ciao.gmane.io" Cc: dmitry@gutov.dev, acorallo@gnu.org, emacs-devel@gnu.org To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Dec 12 07:44:26 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 1tLcvy-0000vx-IK for ged-emacs-devel@m.gmane-mx.org; Thu, 12 Dec 2024 07:44:26 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLcvI-0007hk-H5; Thu, 12 Dec 2024 01:43:44 -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 1tLcvH-0007ha-9Y for emacs-devel@gnu.org; Thu, 12 Dec 2024 01:43:43 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLcvG-0005RG-U1; Thu, 12 Dec 2024 01:43:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=QkUT12NCC18dy/yoeBF5pUwDH6+g6sS6Zw2U9E7VovY=; b=KU8vBUBPGrFqRFIVWB8W DePSU4eIhbVafiZNnd9w07QiQMztSyxtN6H97cWBfnf4BCZapd8sd/iadRbAhEkl9qGSBvPzOa7Vm H/3ZwokyXbs7pG3X0GA339efzjYk2WMQ7K/YK8+9r89jzEHVMo4EbXhGLw7ujroBOu25lnApylpKq oogealhg72iRR1MI6UqjErPo8sNXK6/y+C3vJqaEHCbLdhqsFtt3Tl/EAcHxRGRj7I1cRh4cksnrq u2f8e/C9Z9HDrzuOyCSzF4o98jx7T0yqxJyolKZiwwWvs8TbXU6t+z6hRa83rV2Odm8pMhM2mjA4J fvbqiTu1zEe1hA==; In-Reply-To: (message from Yuan Fu on Wed, 11 Dec 2024 22:05:56 -0800) 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:326407 Archived-At: > From: Yuan Fu > Date: Wed, 11 Dec 2024 22:05:56 -0800 > Cc: Andrea Corallo , > Eli Zaretskii , > emacs-devel@gnu.org > > > > > On Dec 11, 2024, at 4:23 PM, Dmitry Gutov wrote: > > > > On 12/12/2024 01:38, Andrea Corallo wrote: > >> The suggestion of having the C functions defined to nops when > >> HAVE_TREE_SITTER is not defined is cleaner in principle, but I think > >> there are two downsides: > >> - We don't tipically do it this way, so it would be an exception > > > > We also don't typically require a caller to have a 'declare-function' for every function they use from a package that they (require ...) already. > > > >> - Also we should do it for all the functions in treesit.c, otherwise we > >> don't solve the original problem of introducing warnings by mistake on > >> non treesit builds. > > > > Sure. All non-static ones anyway. > > I tried to define all the C functions and it’s not easy to do: doing it in C seems pretty tedious, we’d need DEFUN form and defsubr for each function (is there a easier way?). If done in lisp, we need to do it in a separate file and _load_ it before compiling treesit.el and any other package that uses tree-sitter. I’m not familiar with Emacs’s build process so I don’t know how and where to add such a file and make Emacs load it on startup. > > Can someone enlighten me on how to define these functions in either C or lisp? > > I think defining them as no-op for Emacs w/o tree-sitter is a good move, because otherwise if some user compiles an Emacs w/o tree-sitter and compiles a bunch of packages, and one of the package happens to be based on tree-sitter, they’ll see a bunch of warnings unless the package author added declare-function forms or the proposed macro. It’s better to have tree-sitter functions always defined and save everybody some hassle. FWIW, I'd rather we didn't go this way, for the reasons Andrea explained (and I agreed). Inventing some new technique or tricks just for this one case, when we don't do anything like that in any other similar case, doesn't sound like a good idea, because it would mean one more subtle protocol to support in Emacs development. It gets in the way while reviewing patches, for example, because it is not easy to remember when special conventions must be observed. E.g., should someone come up with a new DEFUN in treesit.c, someone should remember that a no-op function by the same name should be defined at the same time. Or we'd need to #ifdef out the body of each DEFUN, which makes the code harder to read. Can we find some other way of making this easier, without defining no-op functions in treesit.c?