From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Basil L. Contovounesios" via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#58563: 29.0.50; Generic functions and advertised-calling-convention Date: Sun, 23 Oct 2022 20:15:55 +0300 Message-ID: <87czaih35g.fsf@tcd.ie> References: <878rlgjcbl.fsf@tcd.ie> Reply-To: "Basil L. Contovounesios" 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="24826"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 58563@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Oct 24 07:34:05 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1omq69-0006Hr-9G for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 24 Oct 2022 07:34:05 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1omnEY-00039O-JN; Sun, 23 Oct 2022 22:30:34 -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 1omeas-0006U8-KU for bug-gnu-emacs@gnu.org; Sun, 23 Oct 2022 13:17:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1omeas-0007NI-AV for bug-gnu-emacs@gnu.org; Sun, 23 Oct 2022 13:17:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1omear-0007Jp-Rf for bug-gnu-emacs@gnu.org; Sun, 23 Oct 2022 13:17:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Basil L. Contovounesios" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 23 Oct 2022 17:17:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58563 X-GNU-PR-Package: emacs Original-Received: via spool by 58563-submit@debbugs.gnu.org id=B58563.166654536828056 (code B ref 58563); Sun, 23 Oct 2022 17:17:01 +0000 Original-Received: (at 58563) by debbugs.gnu.org; 23 Oct 2022 17:16:08 +0000 Original-Received: from localhost ([127.0.0.1]:46438 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1omeZz-0007IR-Sz for submit@debbugs.gnu.org; Sun, 23 Oct 2022 13:16:08 -0400 Original-Received: from mail-ed1-f45.google.com ([209.85.208.45]:42579) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1omeZv-0007HU-Dc for 58563@debbugs.gnu.org; Sun, 23 Oct 2022 13:16:06 -0400 Original-Received: by mail-ed1-f45.google.com with SMTP id y12so3131102edc.9 for <58563@debbugs.gnu.org>; Sun, 23 Oct 2022 10:16:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd.ie; s=google21; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=+rMwsufGVQ1RW5tWUfpbapYb0qRCNpfpPTBUEhKn+C0=; b=UYxaxyjAknenmAQyq5ni9TYjovXUFJD9Prlw8xwvvuvUnsLpX1Uzidm+7Dj85yNZym f8Eh/6kiu0wLzbzl39U4XwrqnvnNZeHgtW6VE5pl33GmbEcIwzO580R2qj7HIKUcd8rq ywqoq+9BHPNwAB2K8N2oV15fMj6OFfaOIihZFuqb7Ec8SNtDWVS1jtx/ZqX1+bE0Je0/ udExdac4gnrCPXz+TIdV4eQza1VxATFopRlGpzMlpsYJ5Jamc7ucAvd8WmSsaQe37wjd 17R2i4BVCWba85utcde4wO2vuajoge8ZgCn6gi8s6SKNmo8in61FFpljUSUgBs+m7089 SsVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=+rMwsufGVQ1RW5tWUfpbapYb0qRCNpfpPTBUEhKn+C0=; b=mVADpbnm8PD1Fz/xeD5hJfYYYkRQAZhUXDH8XNIqJeA8iv0UHUXqj5Y5PhAc8YP+xz gtqhGa4jsUSRWH0KeIBCzkLUNzE213T+McvktkUbjbuhGFuDXjbUkjfLTx+7tU47TMr2 m/oHJv5ih3XZGcyfbPjHFno6b/k7NuNNbttn/0Q3NNtLNUEag//gj1Yltqf4hQIj6vwY P4gZJNQ/guBKi/XLkPH2En9zAnDjJ2AEEHeGteDBnYspIt2Z1DLxQG5THOapiWcIXKE2 TW9hGR48eNkoksfdYuIFsboRabDYszRnHlMM1jqUa8Uod2kENVpXArr4EmYFtHIzewFs JdyQ== X-Gm-Message-State: ACrzQf1g4Rj4J50EeekhyD+wrRU8Q1lXzDxaf1C1fUFAldQMxf/PqIHW B5sdP8Ow0G4V5q2TLkQmlwkcEZsmVidWGA== X-Google-Smtp-Source: AMsMyM6BTnGqvjdxkqEaG+ND50qo+F6yK0h7BaKS5fBXtqALEWyR/oBMbOG+G0AsZiQygSderl2O9g== X-Received: by 2002:a17:907:6ea9:b0:794:8b93:2e44 with SMTP id sh41-20020a1709076ea900b007948b932e44mr19199732ejc.407.1666545357322; Sun, 23 Oct 2022 10:15:57 -0700 (PDT) Original-Received: from localhost ([2a02:587:321f:7e8a:d9:365a:ced1:b3d1]) by smtp.gmail.com with ESMTPSA id p10-20020a170906228a00b0078bfe57fc7bsm14208029eja.47.2022.10.23.10.15.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Oct 2022 10:15:56 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Sun, 16 Oct 2022 12:05:33 -0400") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: "bug-gnu-emacs" Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:246087 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable tags 58563 + patch quit Stefan Monnier [2022-10-16 12:05 -0400] wrote: >> Then my-foo's symbol-function is overwritten and its entry in >> advertised-signature-table is no longer found, so byte-compilation no >> longer warns about incorrect usage, and C-h f regresses to displaying: > > I believe this is now fixed in `master`. > >> C-h f also shows the expected arglist, but not for methods: >> >> my-foo is a Lisp closure. >> (my-foo X) >> Frobnicate X. >> This is a generic function. >> Implementations: >> (my-foo X &optional _Y) >> Undocumented > > Not this, OTOH. Do we want this fixed? Currently C-h f map-contains-key RET says: map-contains-key is a byte-compiled Lisp function in =E2=80=98map.el=E2= =80=99. (map-contains-key MAP KEY) Return non-nil if and only if MAP contains KEY. TESTFN is deprecated. Its default depends on MAP. The default implementation delegates to =E2=80=98map-some=E2=80=99. Probably introduced at or before Emacs version 27.1. This is a generic function. Implementations: (map-contains-key (MAP hash-table) KEY &optional TESTFN) in =E2=80=98map.= el=E2=80=99. Return non-nil if MAP contains KEY, ignoring TESTFN. (map-contains-key (MAP array) KEY &optional TESTFN) in =E2=80=98map.el=E2= =80=99. Return non-nil if KEY is an index of MAP, ignoring TESTFN. (map-contains-key (MAP list) KEY &optional TESTFN) in =E2=80=98map.el=E2= =80=99. Return non-nil if MAP contains KEY. If MAP is an alist, TESTFN defaults to =E2=80=98equal=E2=80=99. If MAP is a plist, TESTFN defaults to =E2=80=98eq=E2=80=99. (map-contains-key MAP KEY &optional TESTFN) in =E2=80=98map.el=E2=80=99. Undocumented So the generic docstring shows the advertised signature, and the method docstrings show the actual signature. Whereas with a patch like that following my signature, we'd have: map-contains-key is a byte-compiled Lisp function in =E2=80=98map.el=E2= =80=99. (map-contains-key MAP KEY) Return non-nil if and only if MAP contains KEY. TESTFN is deprecated. Its default depends on MAP. The default implementation delegates to =E2=80=98map-some=E2=80=99. Probably introduced at or before Emacs version 27.1. This is a generic function. Implementations: (map-contains-key (MAP hash-table) KEY) in =E2=80=98map.el=E2=80=99. Return non-nil if MAP contains KEY, ignoring TESTFN. (map-contains-key (MAP array) KEY) in =E2=80=98map.el=E2=80=99. Return non-nil if KEY is an index of MAP, ignoring TESTFN. (map-contains-key (MAP list) KEY) in =E2=80=98map.el=E2=80=99. Return non-nil if MAP contains KEY. If MAP is an alist, TESTFN defaults to =E2=80=98equal=E2=80=99. If MAP is a plist, TESTFN defaults to =E2=80=98eq=E2=80=99. (map-contains-key MAP KEY) in =E2=80=98map.el=E2=80=99. Undocumented I don't know whether that's better or worse, with all the references to the seemingly nonexistent TESTFN. Then again, we could just update the docstrings to mention it less. WDYT? P.S. There's a call to cl--generic-method-info also in elisp-mode.el. I wasn't sure whether the advertised signature is of use there, so I left it alone. --=20 Basil --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=signature.diff diff --git a/lisp/emacs-lisp/cl-generic.el b/lisp/emacs-lisp/cl-generic.el index 7b6d43e572..db1ad64874 100644 --- a/lisp/emacs-lisp/cl-generic.el +++ b/lisp/emacs-lisp/cl-generic.el @@ -484,18 +484,18 @@ cl-generic-define-context-rewriter (defun cl--generic-make-defmethod-docstring () ;; FIXME: Copy&paste from pcase--make-docstring. (let* ((main (documentation (symbol-function 'cl-defmethod) 'raw)) - (ud (help-split-fundoc main 'cl-defmethod))) + (ud (help-split-fundoc main 'cl-defmethod)) + (generic (cl--generic 'cl-generic-generalizers))) ;; So that eg emacs -Q -l cl-lib --eval "(documentation 'pcase)" works, ;; where cl-lib is anything using pcase-defmacro. (require 'help-fns) (with-temp-buffer (insert (or (cdr ud) main)) (insert "\n\n\tCurrently supported forms for TYPE:\n\n") - (dolist (method (reverse (cl--generic-method-table - (cl--generic 'cl-generic-generalizers)))) - (let* ((info (cl--generic-method-info method))) + (dolist (method (reverse (cl--generic-method-table generic))) + (let ((info (cl--generic-method-info method generic))) (when (nth 2 info) - (insert (nth 2 info) "\n\n")))) + (insert (nth 2 info) "\n\n")))) (let ((combined-doc (buffer-string))) (if ud (help-add-fundoc-usage combined-doc (car ud)) combined-doc))))) @@ -1096,15 +1096,19 @@ cl--generic-find-defgeneric-regexp (add-to-list 'find-function-regexp-alist '(cl-defgeneric . cl--generic-find-defgeneric-regexp))) -(defun cl--generic-method-info (method) +(defun cl--generic-method-info (method &optional generic) (let* ((specializers (cl--generic-method-specializers method)) (qualifiers (cl--generic-method-qualifiers method)) (call-con (cl--generic-method-call-con method)) (function (cl--generic-method-function method)) - (args (help-function-arglist (if (not (eq call-con 'curried)) - function - (funcall function #'ignore)) - 'names)) + (signature (and generic + (get-advertised-calling-convention + (symbol-function (cl--generic-name generic))))) + (args (if (and generic (listp signature)) signature + (help-function-arglist (if (not (eq call-con 'curried)) + function + (funcall function #'ignore)) + 'names))) (docstring (documentation function)) (qual-string (if (null qualifiers) "" @@ -1154,8 +1158,8 @@ cl--generic-describe (insert (propertize "Implementations:\n\n" 'face 'bold)) ;; Loop over fanciful generics (dolist (method (cl--generic-method-table generic)) - (pcase-let* - ((`(,qualifiers ,args ,doc) (cl--generic-method-info method))) + (pcase-let ((`(,qualifiers ,args ,doc) + (cl--generic-method-info method generic))) ;; FIXME: Add hyperlinks for the types as well. (let ((print-quoted nil) (quals (if (length> qualifiers 0) @@ -1227,7 +1231,7 @@ cl--generic-method-documentation (dolist (method (cl--generic-method-table generic)) (when (cl--generic-specializers-apply-to-type-p (cl--generic-method-specializers method) type) - (push (cl--generic-method-info method) docs)))) + (push (cl--generic-method-info method generic) docs)))) docs)) (defun cl--generic-method-files (method) --=-=-=--