From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.emacs.bugs Subject: bug#6376: 23.2; byte compile add-to-list report free variable Date: Sat, 07 Aug 2010 09:45:43 +1000 Message-ID: <87zkwzs3tk.fsf@blah.blah> References: <87y6eqia4d.fsf@blah.blah> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1281139739 26366 80.91.229.12 (7 Aug 2010 00:08:59 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 7 Aug 2010 00:08:59 +0000 (UTC) To: 6376@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Aug 07 02:08:58 2010 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OhWy3-00011T-Ks for geb-bug-gnu-emacs@m.gmane.org; Sat, 07 Aug 2010 02:08:56 +0200 Original-Received: from localhost ([127.0.0.1]:58301 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OhWy0-0003wm-Uu for geb-bug-gnu-emacs@m.gmane.org; Fri, 06 Aug 2010 20:08:49 -0400 Original-Received: from [140.186.70.92] (port=50860 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OhWxX-0003hY-TW for bug-gnu-emacs@gnu.org; Fri, 06 Aug 2010 20:08:26 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OhWxT-0000Hn-Nl for bug-gnu-emacs@gnu.org; Fri, 06 Aug 2010 20:08:17 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:54123) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OhWxT-0000Hi-MP for bug-gnu-emacs@gnu.org; Fri, 06 Aug 2010 20:08:15 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1OhWbx-0001MV-Qg; Fri, 06 Aug 2010 19:46:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Kevin Ryde Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 06 Aug 2010 23:46:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6376 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 6376-submit@debbugs.gnu.org id=B6376.12811383205224 (code B ref 6376); Fri, 06 Aug 2010 23:46:01 +0000 Original-Received: (at 6376) by debbugs.gnu.org; 6 Aug 2010 23:45:20 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OhWbI-0001MD-8h for submit@debbugs.gnu.org; Fri, 06 Aug 2010 19:45:20 -0400 Original-Received: from mailout1-7.pacific.net.au ([61.8.2.214] helo=mailout1.pacific.net.au) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OhWbE-0001M7-Te for 6376@debbugs.gnu.org; Fri, 06 Aug 2010 19:45:18 -0400 Original-Received: from mailproxy2.pacific.net.au (mailproxy2.pacific.net.au [61.8.2.163]) by mailout1.pacific.net.au (Postfix) with ESMTP id CDC915D077D; Sat, 7 Aug 2010 09:45:49 +1000 (EST) Original-Received: from blah.blah (ppp2335.dyn.pacific.net.au [61.8.35.53]) by mailproxy2.pacific.net.au (Postfix) with ESMTP id C08FC27406; Sat, 7 Aug 2010 09:45:48 +1000 (EST) Original-Received: from gg by blah.blah with local (Exim 4.72) (envelope-from ) id 1OhWbf-000204-Ld; Sat, 07 Aug 2010 09:45:43 +1000 In-Reply-To: (Stefan Monnier's message of "Tue, 08 Jun 2010 21:29:20 -0400") User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.2 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Fri, 06 Aug 2010 19:46:01 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) 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-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:39300 Archived-At: --=-=-= I got a bit further to these few lines. Not quite ready yet, but getting closer. The byte-compile-check-var is more or less a break-out of the checks in byte-compile-variable-ref. add-hook and remove-hook end up with checks against non-variables, but they don't demand a bound variable. I suppose they could helpfully also notice undefined functions in their second arg too. You'd be tempted to have some sort of general arg-type description for the builtin funcs rather than doing checks plus "normal-call" for each. --=-=-= Content-Type: application/emacs-lisp Content-Disposition: inline; filename=bytecomp-add-to-list.el Content-Transfer-Encoding: quoted-printable (require 'bytecomp) (defun byte-compile-check-var (symbol base-op) ;; SYMBOL is the name of a variable. BASE-OP is one of the following ;; according to what's being done to the variable. ;; 'byte-varref ;; 'byte-varset ;; 'byte-varbind ;; 'varset-def -- set, defining if not already (eg. add-hook) ;; Emit a warning if SYMBOL is unbound, or if it's a constant being set or ;; bound. ;; (cond ((and (not (symbolp symbol)) ;; `constants' warning includes all non-variables (byte-compile-warning-enabled-p 'constants)) (byte-compile-warn "%s non-variable `%S'" (assoc-default base-op '((byte-varref . "reference to") (byte-varset . "assignment to") (varset-def . "assignment to") (byte-varbind . "let-bind of")) nil base-op) symbol)) ((and (not (eq base-op 'byte-varref)) (byte-compile-warning-enabled-p 'constants) (byte-compile-const-symbol-p symbol t)) (byte-compile-warn "%s constant `%S'" (assoc-default base-op '((byte-varset . "variable assignment to") (varset-def . "variable assignment to") (byte-varbind . "let-bind of")) nil base-op) symbol)) ((and (not (memq base-op '(varset-def byte-varbind))) (byte-compile-warning-enabled-p 'free-vars) (not (memq symbol byte-compile-bound-variables)) (not (memq symbol byte-compile-free-assignments))) (byte-compile-warn "%s to free variable `%S'" (assoc-default base-op '((byte-varref . "reference to") (byte-varset . "assignment to"= )) nil base-op) symbol) (push symbol byte-compile-free-assignments)))) (defun byte-compile-check-argvar (arg base-op) ;; ARG is a function argument form which is supposed to evaluate to a ;; symbol naming a variable. If ARG is (quote FOO) or :foo then check ;; that it's a bound variable per bytecomp-check-var. If ARG is ;; self-evaluating like nil, t, strings, etc then pass to the check too, ;; to possibly report assignment to a constant. Code like (quote nil) or ;; (quote "foo") reaches this point as plain nil or t. ;; (cond ((eq 'quote (car-safe arg)) (byte-compile-check-var (car-safe (cdr arg)) base-op)) ((or (memq arg '(nil t)) ;; anything except a symbol or list is self-evaluating (not (or (symbolp arg) (consp arg)))) (byte-compile-check-var arg base-op)))) (defun byte-compile-addtolist (form) ;; first arg is the name of a variable being changed, eg. (foo 'var ...) (if (>=3D (safe-length form) 2) (byte-compile-check-argvar (cadr form) 'byte-varset)) (byte-compile-normal-call form)) (byte-defop-compiler-1 add-to-list byte-compile-addtolist) (byte-defop-compiler-1 add-to-ordered-list byte-compile-addtolist) (defun byte-compile-addremhook (form) ;; first arg is the name of a variable being changed, eg. (foo 'var ...) ;; only=20 (if (>=3D (safe-length form) 2) (byte-compile-check-argvar (cadr form) 'varset-def)) (byte-compile-normal-call form)) (byte-defop-compiler-1 add-hook byte-compile-addremhook) (byte-defop-compiler-1 remove-hook byte-compile-addremhook) --=-=-=--