unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Inferred function types in the *Help* buffer
@ 2023-05-23 16:44 Andrea Corallo
  2023-05-24 10:46 ` Eli Zaretskii
  0 siblings, 1 reply; 26+ messages in thread
From: Andrea Corallo @ 2023-05-23 16:44 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1354 bytes --]

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:

====
foo is a native-compiled Lisp function in
‘~/.emacs.d/eln-cache/30.0.50-e29d76eb/test-a526a80f-5481bc95.eln’.

Signature: (foo N)

Inferred type: (function (t) (or (member to-small too-big) (integer
100 100)))

...
====

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: typef.patch --]
[-- Type: text/x-diff, Size: 761 bytes --]

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)))))
 

^ permalink raw reply related	[flat|nested] 26+ messages in thread
* Re: Inferred function types in the *Help* buffer
@ 2023-05-23 16:47 Payas Relekar
  2023-05-23 18:51 ` Philip Kaludercic
  2023-05-24 12:20 ` Andrea Corallo
  0 siblings, 2 replies; 26+ messages in thread
From: Payas Relekar @ 2023-05-23 16:47 UTC (permalink / raw)
  To: Andrea Corallo; +Cc: emacs-devel

Andrea Corallo <akrl@sdf.org> writes:

> ====
> foo is a native-compiled Lisp function in
> ‘~/.emacs.d/eln-cache/30.0.50-e29d76eb/test-a526a80f-5481bc95.eln’.
>
> Signature: (foo N)
>
> Inferred type: (function (t) (or (member to-small too-big) (integer
> 100 100)))
>
> ...
> ====

Pretty cool.

Tangentially, there's also Elsa: https://github.com/emacs-elsa/Elsa

How feasible would you say it would be to integrate it within
Emacs/native-compiler?

Regards,
Payas

--



^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2023-06-01 19:13 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-23 16:44 Inferred function types in the *Help* buffer Andrea Corallo
2023-05-24 10:46 ` Eli Zaretskii
2023-05-24 12:19   ` Andrea Corallo
2023-05-30 16:46     ` Andrea Corallo
2023-05-30 18:14       ` Mattias Engdegård
2023-05-30 18:48         ` Andrea Corallo
2023-05-31 12:19           ` Andrea Corallo
2023-05-31 14:08             ` Eli Zaretskii
2023-06-01 11:28             ` Mattias Engdegård
2023-06-01 11:35               ` Eli Zaretskii
2023-06-01 11:36                 ` Mattias Engdegård
2023-06-01 11:54                   ` Andrea Corallo
2023-06-01 11:50               ` Andrea Corallo
2023-06-01 13:06                 ` Mattias Engdegård
2023-06-01 13:34                   ` Andrea Corallo
2023-06-01 14:50                     ` Mattias Engdegård
2023-06-01 15:10                       ` Andrea Corallo
2023-06-01 17:53                         ` Mattias Engdegård
2023-06-01 19:13                           ` Andrea Corallo
2023-06-01 14:09                   ` Andrea Corallo
2023-05-31 13:46       ` Eli Zaretskii
2023-06-01  8:42         ` Andrea Corallo
2023-06-01  8:53           ` Eli Zaretskii
  -- strict thread matches above, loose matches on Subject: below --
2023-05-23 16:47 Payas Relekar
2023-05-23 18:51 ` Philip Kaludercic
2023-05-24 12:20 ` Andrea Corallo

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).