From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: John Wiegley Newsgroups: gmane.emacs.bugs Subject: bug#4845: 23.1.50; Uninterned symbols in .elc files Date: Tue, 19 Jan 2016 09:26:14 -0800 Message-ID: References: <20160119123956.32358.qmail@mail.muc.de> Reply-To: John Wiegley NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-Trace: ger.gmane.org 1453224449 20645 80.91.229.3 (19 Jan 2016 17:27:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 19 Jan 2016 17:27:29 +0000 (UTC) Cc: Marcin Borkowski , 4845@debbugs.gnu.org, Helmut Eller To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jan 19 18:27:18 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1aLa3n-0007vR-MC for geb-bug-gnu-emacs@m.gmane.org; Tue, 19 Jan 2016 18:27:15 +0100 Original-Received: from localhost ([::1]:38451 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLa3h-0005kD-TB for geb-bug-gnu-emacs@m.gmane.org; Tue, 19 Jan 2016 12:27:09 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38992) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLa3d-0005gp-4K for bug-gnu-emacs@gnu.org; Tue, 19 Jan 2016 12:27:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aLa3a-0006QA-CK for bug-gnu-emacs@gnu.org; Tue, 19 Jan 2016 12:27:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:37503) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLa3a-0006Q5-8p for bug-gnu-emacs@gnu.org; Tue, 19 Jan 2016 12:27:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1aLa3Z-0005F2-TX for bug-gnu-emacs@gnu.org; Tue, 19 Jan 2016 12:27:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: John Wiegley Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 19 Jan 2016 17:27:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 4845 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 4845-submit@debbugs.gnu.org id=B4845.145322439620111 (code B ref 4845); Tue, 19 Jan 2016 17:27:01 +0000 Original-Received: (at 4845) by debbugs.gnu.org; 19 Jan 2016 17:26:36 +0000 Original-Received: from localhost ([127.0.0.1]:53956 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aLa39-0005EI-Mx for submit@debbugs.gnu.org; Tue, 19 Jan 2016 12:26:35 -0500 Original-Received: from mail-pa0-f43.google.com ([209.85.220.43]:36057) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aLa37-0005E5-9g for 4845@debbugs.gnu.org; Tue, 19 Jan 2016 12:26:33 -0500 Original-Received: by mail-pa0-f43.google.com with SMTP id yy13so361898531pab.3 for <4845@debbugs.gnu.org>; Tue, 19 Jan 2016 09:26:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:in-reply-to:date:message-id:references :user-agent:reply-to:mime-version:content-type; bh=Emx2oPKKPDQZ/3CgmIm3DH5IEcxSx2VpoYguXqKgEn8=; b=YtDGDlJbRXWguHkm/+EG9YTwVqNoP/HgisLtDVid9ti+KCfkHD+I5nsThhDT1lC0Fm UKNVqhj2FPPzuQmgikLSKOAONLp7i9Z/4NwHvUsfIdKvhvbU7lxp8XygkHZvwzyXu3o7 q/k+rHsTjMBuh3wcdAcgUIvzLLGGsPfnqNrZbQUkqVgDBIBCoVvLnNTG/w3ehepa6egL AQhamzoUBXhFdbdP4uuJqI7UHeUufqI9dVQl9rge/MeieX3uf0zLJcLu0uDC8DatglAn HFlHaKVqoElN5HBmqugXO8qorUK3v821RsSOLl9UtNuJn8qBsQMy00o+v0cg40R+CDNb 5LnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:in-reply-to:date:message-id :references:user-agent:reply-to:mime-version:content-type; bh=Emx2oPKKPDQZ/3CgmIm3DH5IEcxSx2VpoYguXqKgEn8=; b=fUshfuiPh8BiIXqhI/VYb+e+HgQBaor4Uvc4Q+LABBFLWXeCWJE7OP3sRYZXe/MjIe KW1OdTm83RaWMsZaw0+WNHBOuw57BP381waWUbVVicJSPHlVLuVi7LpKKhc6aGVpqeze nisSZAVXdw4NVU67aEX6FbdzvP0DLGgmMtOATw3qzssZNXBiqzYRE5Ox3whcDbJ0VL1j qX5vWq4YQofbJc7yyCYWifD4tgVVhaVkENjCqQVblBt0ivPg9RAQSTgE18N5VjwAPFVv m9gjk5wpardisppcvMTBmDffV54Mv3I8ZkEF5/SfE+S4FitYtDL0YSUcnm3mMgw1igaE sa4Q== X-Gm-Message-State: ALoCoQnHCPXKCAgiQYiiE4QynAdZ2Vqd7hy7TRgB+SXgrBtr3p5bH+9Qcnb+77pAlFMXfNRyspJdM8lXHUO9ISW99Oi4dBDR7g== X-Received: by 10.66.162.9 with SMTP id xw9mr45958155pab.46.1453224387662; Tue, 19 Jan 2016 09:26:27 -0800 (PST) Original-Received: from Vulcan.local (76-234-68-79.lightspeed.frokca.sbcglobal.net. [76.234.68.79]) by smtp.gmail.com with ESMTPSA id 16sm42831823pfh.48.2016.01.19.09.26.25 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 19 Jan 2016 09:26:26 -0800 (PST) X-Google-Original-From: "John Wiegley" Original-Received: by Vulcan.local (Postfix, from userid 501) id 45F45124F7D88; Tue, 19 Jan 2016 09:26:25 -0800 (PST) In-Reply-To: <20160119123956.32358.qmail@mail.muc.de> (Alan Mackenzie's message of "19 Jan 2016 12:39:56 -0000") User-Agent: Gnus/5.130014 (Ma Gnus v0.14) Emacs/24.5 (darwin) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:111752 Archived-At: --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable >>>>> Alan Mackenzie writes: >>> (defmacro foo () >>> (let ((sym (make-symbol "bar"))) >>> `(progn >>> (defun ,sym () (message "function %s called" ',sym)) >>> (,sym)))) >>>=20 >>> (foo) >>> However loading the corresponding compiled file signals an error: shell> emacs -Q -batch -eval '(byte-compile-file "x.el")' -load x.elc >>> Wrote /tmp/x.elc >>> Symbol's function definition is void: bar This example becomes clearer if we use `gensym' instead of `make-symbol "bar"`. Here is a macro expansion: Byte-compiled: (progn (defun bar68503 nil (message "function %s called" '#:bar68503)) (#:bar68503)) Interpreted: (progn (defun bar68503 nil (message "function %s called" 'bar68503)) (bar68503)) What's happening here is this: 1. At compile-time, we're creating a new, uninterned symbol, and we are both passing that symbol to defun, and calling it. 2. `defun', at compilation time, is using the _name_ of that symbol to define a function definition for an interned symbol of the same name. 3. We then try to print and call the uninterned symbol directly. So what = we are calling, and what defun defined, are not the same symbol. This works when non-byte-compiled because we don't inline the symbol reference, making it a reference by name instead of by value. You can trigg= er the same error behavior at interpretation time with: (defmacro foo () (let ((sym (gensym))) `(progn (defun ,sym () (message "function %s called" ',sym)) (funcall (symbol-function (quote ,sym)))))) =20=20 (foo) I don't think this is a bug, rather macro expansion doing exactly what it w= as told to do. If anything, it's odd that when interpreting, we expand to a reference by name; but I suppose that makes sense too, given the more dynam= ic nature of interpreted code. The general rule to follow is: Don't leak internal symbols. If you use `gensym' or `make-symbol', ensure that all dependencies on that symbol occur entirely within the macro body. `defun' is used to establish global definitions, so it effectively "exports" the internal symbol, breaking the abstraction. That it has inconsistent behavior here is due to differences in the way that byte-compilation inlines references. I recommend closure of this bug as expected behavior, unless there are furt= her concerns. =2D-=20 John Wiegley GPG fingerprint =3D 4710 CF98 AF9B 327B B80F http://newartisans.com 60E1 46C4 BD1A 7AC1 4BA2 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQGcBAEBCgAGBQJWnnG2AAoJEMFE2PTxn+YwsqwL/RaITtEQOGbyJorAqlBUw9vs W+lFP00gsqk4B6oaMF1+sYNqiUIadTN4Owo8sKWUbRS09g7c2hwci0XSKjNNgQHi WPCfLT2nvTUJcfX60aojUcIv6iPDb6UE4qiqtG6HB1/K/BZEDGbbWk2/t/YWq1Bq dSsdPg+QwJbxVHryOLqS8Pt9oO6di0d375dXXSVjfRKPH5DOgwIyI4friVx7nrUB PMYo6rpKuKy7HgcuimKljkCwSQXgFD92rT9mi3awN0LhLCE2qDb5eq33Q2GPvRmH nufWjtwQ+uia/k1ZO+kTfXCl+NSIz1NwXYKYdJh7eN6lpdjPwWNfS6+XIrcvocwt FXVa/CJtbSq9594jvpZu/RY+uuedczz96LxVKzmPjbTiUoXWT0pZjEIDlfJtHQjO GJaXn+8eUIyq5TmhsuMwoJNN6zqXGH2GvzoGjUBZ3yZED0nrXpDL2Z21gAkKu3vE rd7b0Aln4FZTWrxQt3YyYHliE5QuEC9yMTNIna5kDg== =G0xy -----END PGP SIGNATURE----- --=-=-=--