From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Can the byte-compiler check whether functions passed by name are defined? Date: Sun, 04 Aug 2013 17:11:51 -0400 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1375650730 32436 80.91.229.3 (4 Aug 2013 21:12:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 4 Aug 2013 21:12:10 +0000 (UTC) Cc: Sebastian Wiesner , emacs-devel@gnu.org To: Klaus-Dieter Bauer Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Aug 04 23:12:11 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1V65b0-0004sY-7f for ged-emacs-devel@m.gmane.org; Sun, 04 Aug 2013 23:12:10 +0200 Original-Received: from localhost ([::1]:51746 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V65az-0001AF-EJ for ged-emacs-devel@m.gmane.org; Sun, 04 Aug 2013 17:12:09 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43940) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V65aq-00019j-2h for emacs-devel@gnu.org; Sun, 04 Aug 2013 17:12:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V65ai-0000sO-Ou for emacs-devel@gnu.org; Sun, 04 Aug 2013 17:12:00 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.182]:61294) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V65ai-0000sH-Kh for emacs-devel@gnu.org; Sun, 04 Aug 2013 17:11:52 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av4EABK/CFFFxKix/2dsb2JhbABEvw4Xc4IeAQEEAVYjBQsLNBIUGA0kiB4GwS2RCgOSWpIggV6DEw X-IPAS-Result: Av4EABK/CFFFxKix/2dsb2JhbABEvw4Xc4IeAQEEAVYjBQsLNBIUGA0kiB4GwS2RCgOSWpIggV6DEw X-IronPort-AV: E=Sophos;i="4.84,565,1355115600"; d="scan'208";a="20556291" Original-Received: from 69-196-168-177.dsl.teksavvy.com (HELO pastel.home) ([69.196.168.177]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 04 Aug 2013 17:11:45 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id 4D5636643A; Sun, 4 Aug 2013 17:11:51 -0400 (EDT) In-Reply-To: (Klaus-Dieter Bauer's message of "Sun, 4 Aug 2013 20:41:13 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.182 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:162419 Archived-At: > I have written an implementation of the compile-time check, see the > attached patch to "lisp/bytecomp.el". Since I also introduced as new > declare form for `defun', I have also attached a patch to > "doc/functions.texi". That looks a lot more complex than what I expected. As mentioned, the best option is to start by adding warnings for the #'symbol form (should be easy: handle it in the same way we handle warnings for function calls). Then make the higher-order functions turn 'symbol into #'symbol. That's important for things like (if foo #'a #'b) > (defun my-combine (func1 func2) > (declare (higher-order-arguments 0 1) Sadly, I defined the `compiler-macro' declaration to take a function rather than an exp that returns a function, so you can't just write a function macroexp--rewrite-function-arguments and then use: (defun my-combine (func1 func2) (declare (compiler-macro (macroexp--rewrite-function-arguments 0 1))) But you can do something like (defun my-combine (func1 func2) (declare (compiler-macro (lambda (body) (macroexp--rewrite-function-arguments body (rewrite func1) (rewrite func2))))) (defun my-mapcar (func list) (declare (compiler-macro (lambda (body) (macroexp--rewrite-function-arguments body (rewrite func) list)))) Still, this annotation is only needed to turn a ' into a #', so it's not the most important. > I couldn't define the handler in "byte-run.el" however, as when I added it > to the declaration of `defun-declaration-alist', it would suddenly be > missing again during compilation. Probably because you didn't re-dump Emacs (byte-run.el is preloaded into the `emacs' executable so if you change it, you need to rebuild `emacs'). Stefan