unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#8631: since lexical merge, byte compiler does not know defmethod defines a function
@ 2011-05-06 17:48 Glenn Morris
  2011-05-07  4:07 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Glenn Morris @ 2011-05-06 17:48 UTC (permalink / raw)
  To: 8631

Package: emacs
Version: 24.0.50

Since the lexical branch was merged (ie r103798), the byte compiler does
not understand that eieio's defmethod defines a function.

Eg:

emacs -Q -batch -f batch-byte-compile cedet/srecode/dictionary.el

In end of data:
dictionary.el:712:1:Warning: the following functions are not known to be
    defined: srecode-dictionary-add-template-table,[...]





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

* bug#8631: since lexical merge, byte compiler does not know defmethod defines a function
  2011-05-06 17:48 bug#8631: since lexical merge, byte compiler does not know defmethod defines a function Glenn Morris
@ 2011-05-07  4:07 ` Stefan Monnier
  2011-05-07 13:00   ` Andy Moreton
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2011-05-07  4:07 UTC (permalink / raw)
  To: Glenn Morris; +Cc: Eric M. Ludlam, 8631-done

> Since the lexical branch was merged (ie r103798), the byte compiler does
> not understand that eieio's defmethod defines a function.

> Eg:

> emacs -Q -batch -f batch-byte-compile cedet/srecode/dictionary.el

> In end of data:
> dictionary.el:712:1:Warning: the following functions are not known to be
>     defined: srecode-dictionary-add-template-table,[...]

Should be fixed now, thanks to the patch below,


        Stefan


=== modified file 'lisp/emacs-lisp/bytecomp.el'
--- lisp/emacs-lisp/bytecomp.el	2011-04-15 12:30:15 +0000
+++ lisp/emacs-lisp/bytecomp.el	2011-05-07 03:24:05 +0000
@@ -4173,6 +4173,7 @@
 
 ;; Compile normally, but deal with warnings for the function being defined.
 (put 'defalias 'byte-hunk-handler 'byte-compile-file-form-defalias)
+;; Used for eieio--defalias as well.
 (defun byte-compile-file-form-defalias (form)
   (if (and (consp (cdr form)) (consp (nth 1 form))
 	   (eq (car (nth 1 form)) 'quote)

=== modified file 'lisp/emacs-lisp/eieio.el'
--- lisp/emacs-lisp/eieio.el	2011-05-05 03:42:09 +0000
+++ lisp/emacs-lisp/eieio.el	2011-05-07 03:56:24 +0000
@@ -420,6 +420,7 @@
     (load-library (car (cdr (symbol-function cname))))))
 
 (defun eieio-defclass (cname superclasses slots options-and-doc)
+  ;; FIXME: Most of this should be moved to the `defclass' macro.
   "Define CNAME as a new subclass of SUPERCLASSES.
 SLOTS are the slots residing in that class definition, and options or
 documentation OPTIONS-AND-DOC is the toplevel documentation for this class.
@@ -1139,6 +1140,17 @@
 \f
 ;;; CLOS methods and generics
 ;;
+
+(put 'eieio--defalias 'byte-hunk-handler
+     #'byte-compile-file-form-defalias) ;;(get 'defalias 'byte-hunk-handler)
+(defun eieio--defalias (name body)
+  "Like `defalias', but with less side-effects.
+More specifically, it has no side-effects at all when the new function
+definition is the same (`eq') as the old one."
+  (unless (and (fboundp name)
+               (eq (symbol-function name) body))
+    (defalias name body)))
+
 (defmacro defgeneric (method args &optional doc-string)
   "Create a generic function METHOD.
 DOC-STRING is the base documentation for this class.  A generic
@@ -1147,7 +1160,21 @@
 `defgeneric' for you.  With this implementation the ARGS are
 currently ignored.  You can use `defgeneric' to apply specialized
 top level documentation to a method."
-  `(eieio-defgeneric (quote ,method) ,doc-string))
+  `(eieio--defalias ',method
+                    (eieio--defgeneric-init-form ',method ,doc-string)))
+
+(defun eieio--defgeneric-init-form (method doc-string)
+  "Form to use for the initial definition of a generic."
+  (cond
+   ((or (not (fboundp method))
+        (eq 'autoload (car-safe (symbol-function method))))
+    ;; Make sure the method tables are installed.
+    (eieiomt-install method)
+    ;; Construct the actual body of this function.
+    (eieio-defgeneric-form method doc-string))
+   ((generic-p method) (symbol-function method))           ;Leave it as-is.
+   (t (error "You cannot create a generic/method over an existing symbol: %s"
+             method))))
 
 (defun eieio-defgeneric-form (method doc-string)
   "The lambda form that would be used as the function defined on METHOD.
@@ -1237,26 +1264,6 @@
 		  (cdr entry)
 		  ))))
 
-(defun eieio-defgeneric (method doc-string)
-  "Engine part to `defgeneric' macro defining METHOD with DOC-STRING."
-  (if (and (fboundp method) (not (generic-p method))
-	   (or (byte-code-function-p (symbol-function method))
-	       (not (eq 'autoload (car (symbol-function method)))))
-	   )
-      (error "You cannot create a generic/method over an existing symbol: %s"
-	     method))
-  ;; Don't do this over and over.
-  (unless (fboundp 'method)
-    ;; This defun tells emacs where the first definition of this
-    ;; method is defined.
-    `(defun ,method nil)
-    ;; Make sure the method tables are installed.
-    (eieiomt-install method)
-    ;; Apply the actual body of this function.
-    (fset method (eieio-defgeneric-form method doc-string))
-    ;; Return the method
-    'method))
-
 (defun eieio-unbind-method-implementations (method)
   "Make the generic method METHOD have no implementations.
 It will leave the original generic function in place,
@@ -1292,12 +1299,17 @@
   (let* ((key (if (keywordp (car args)) (pop args)))
 	 (params (car args))
 	 (arg1 (car params))
-	 (class (if (consp arg1) (nth 1 arg1))))
-    `(eieio--defmethod ',method ',key ',class
-                       (lambda ,(if (consp arg1)
+         (args (if (consp arg1)
                                (cons (car arg1) (cdr params))
-                             params)
-                         ,@(cdr args)))))
+                 params))
+	 (class (if (consp arg1) (nth 1 arg1)))
+         (code `(lambda ,args ,@(cdr args))))
+    `(progn
+       ;; Make sure there is a generic and the byte-compiler sees it.
+       (defgeneric ,method ,args
+         ,(or (documentation code)
+              (format "Generically created method `%s'." method)))
+       (eieio--defmethod ',method ',key ',class ',code))))
 
 (defun eieio--defmethod (method kind argclass code)
   "Work part of the `defmethod' macro defining METHOD with ARGS."
@@ -1317,11 +1329,11 @@
 		 method-static)
 		;; Primary key
                (t method-primary))))
-    ;; make sure there is a generic
-    (eieio-defgeneric
-     method
-     (or (documentation code)
-         (format "Generically created method `%s'." method)))
+    ;; Make sure there is a generic (when called from defclass).
+    (eieio--defalias
+     method (eieio--defgeneric-init-form
+             method (or (documentation code)
+                        (format "Generically created method `%s'." method))))
     ;; create symbol for property to bind to.  If the first arg is of
     ;; the form (varname vartype) and `vartype' is a class, then
     ;; that class will be the type symbol.  If not, then it will fall






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

* bug#8631: since lexical merge, byte compiler does not know defmethod defines a function
  2011-05-07  4:07 ` Stefan Monnier
@ 2011-05-07 13:00   ` Andy Moreton
  0 siblings, 0 replies; 3+ messages in thread
From: Andy Moreton @ 2011-05-07 13:00 UTC (permalink / raw)
  To: bug-gnu-emacs

On Sat 07 May 2011, Stefan Monnier wrote:

>> Since the lexical branch was merged (ie r103798), the byte compiler does
>> not understand that eieio's defmethod defines a function.
>
>> Eg:
>
>> emacs -Q -batch -f batch-byte-compile cedet/srecode/dictionary.el
>
>> In end of data:
>> dictionary.el:712:1:Warning: the following functions are not known to be
>>     defined: srecode-dictionary-add-template-table,[...]
>
> Should be fixed now, thanks to the patch below,

Hi Stefan,

Since you change in revno 104151, I've bootstrapped on winXP at revno
104154. The build output shows some new errors:

--8<---------------cut here---------------start------------->8---
Compiling emacs-lisp/eieio-speedbar.el
In toplevel form:
emacs-lisp/eieio-speedbar.el:96:1:Error: Symbol's value as variable is void: &rest
Compiling emacs-lisp/eieio.el

Compiling gnus/nnregistry.el
In toplevel form:
gnus/nnregistry.el:34:1:Error: Symbol's value as variable is void: &rest
--8<---------------cut here---------------end--------------->8---

Running gnus in this emacs fails with the same error message at runtime,
so I cannot connect to any news servers with it. Could this be related to your
changes ?

    AndyM






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

end of thread, other threads:[~2011-05-07 13:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-06 17:48 bug#8631: since lexical merge, byte compiler does not know defmethod defines a function Glenn Morris
2011-05-07  4:07 ` Stefan Monnier
2011-05-07 13:00   ` Andy Moreton

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