From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Andrea Corallo Newsgroups: gmane.emacs.devel Subject: Inferred function types in the *Help* buffer Date: Tue, 23 May 2023 16:44:08 +0000 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40165"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue May 23 18:45:21 2023 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 1q1V8T-000AK8-Lu for ged-emacs-devel@m.gmane-mx.org; Tue, 23 May 2023 18:45:21 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q1V7R-00077e-SF; Tue, 23 May 2023 12:44:18 -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 1q1V7Q-00077R-Hp for emacs-devel@gnu.org; Tue, 23 May 2023 12:44:16 -0400 Original-Received: from ma.sdf.org ([205.166.94.33]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1V7O-0003UO-Rl for emacs-devel@gnu.org; Tue, 23 May 2023 12:44:16 -0400 Original-Received: from akrl by ma.sdf.org with local (Exim 4.92) (envelope-from ) id 1q1V7I-0002TX-8r for emacs-devel@gnu.org; Tue, 23 May 2023 16:44:08 +0000 Received-SPF: pass client-ip=205.166.94.33; envelope-from=akrl@sdf.org; helo=ma.sdf.org X-Spam_score_int: 18 X-Spam_score: 1.8 X-Spam_bar: + X-Spam_report: (1.8 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_SBL_CSS=3.335, RCVD_IN_XBL=0.375, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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:306282 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello all, on my Emacs I'm toying with the attached patch. Applied on top of master it adds the inferred type for native compiled functions into the help buffer. So for instance for a function like: (defun foo (n) (unless (integerp n) (error "Panic")) (if (> n 100) 'too-big (if (< n 100) 'to-small n))) The content of the *Help* buffer becomes: =3D=3D=3D=3D foo is a native-compiled Lisp function in =E2=80=98~/.emacs.d/eln-cache/30.0.50-e29d76eb/test-a526a80f-5481bc95.eln= =E2=80=99. Signature: (foo N) Inferred type: (function (t) (or (member to-small too-big) (integer 100 100))) ... =3D=3D=3D=3D Indeed the native compiler is not capable of predicting precisly the return type for every compiled function, often can't predict anything more precise than 't'. But in a -Q Emacs on my system it manages to predict non trivial results for ~20% of loaded functions at startup. I feel this would be a nice addition to the self-documenting capabilities of Emacs, so I wanted to probe what's the general feeling about this. If it's considered too invasive we might indeed control it with a customize, WDYT? ATM I adds as well "Signature: " in front of the signature to differentiate it from the type. But looking at it in restrospective it might be not even necessary. Thanks Andrea --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=typef.patch diff --git a/lisp/help-fns.el b/lisp/help-fns.el index 1966193d1a7..69f5c623f5c 100644 --- a/lisp/help-fns.el +++ b/lisp/help-fns.el @@ -710,7 +710,11 @@ help-fns--signature (high-doc (cdr high))) (unless (and (symbolp function) (get function 'reader-construct)) - (insert high-usage "\n")) + (insert "Signature: " high-usage "\n\n") + (when (and (featurep 'native-compile) + (subr-native-elisp-p (symbol-function function)) + (subr-type (symbol-function function))) + (insert (format "Inferred type: %s\n" (subr-type (symbol-function function)))))) (fill-region fill-begin (point)) high-doc))))) --=-=-=--