From: npostavs@users.sourceforge.net
To: Stefan Monnier <monnier@IRO.UMontreal.CA>
Cc: 27718@debbugs.gnu.org, Alex <agrambot@gmail.com>
Subject: bug#27718: 26.0.50; (cl-typep instance-ab 'class-a) gives wrong answer when compiled
Date: Fri, 04 Aug 2017 21:06:42 -0400 [thread overview]
Message-ID: <87fud67rh9.fsf@users.sourceforge.net> (raw)
In-Reply-To: <jwv1sp4nzin.fsf-monnier+emacsbugs@gnu.org> (Stefan Monnier's message of "Tue, 25 Jul 2017 17:21:04 -0400")
[-- Attachment #1: Type: text/plain, Size: 438 bytes --]
Stefan Monnier <monnier@IRO.UMontreal.CA> writes:
> Right, so we have 3 options, indeed:
> - `get` looks up to byte-compile-plist-environment
> - byte-compile manipulates `get`s overriding-plist-environment
> - provide a new get-like function.
>
> Either one is fine by me,
I'm thinking the 2nd looks best. Is it correct to `put'
`byte-compile-define-symbol-prop' as the hunk handler for both
`define-symbol-prop' and `function-put'?
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 5388 bytes --]
From 3e8759320ecba4156cd3315ef02ea902ff408ae3 Mon Sep 17 00:00:00 2001
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
Date: Fri, 14 Jul 2017 00:32:34 -0400
Subject: [PATCH v2 1/2] Let `define-symbol-prop' take effect during
compilation
* src/fns.c (syms_of_fns): New variable `overriding-plist-environment'.
(Fget): Consult it.
* lisp/emacs-lisp/bytecomp.el (byte-compile-close-variables): Let-bind
it to nil.
(byte-compile-define-symbol-prop): New function, handles compilation
of top-level `define-symbol-prop' and `function-put' calls by putting
the symbol setting into `overriding-plist-environment'.
Co-authored-by: Noam Postavsky <npostavs@gmail.com>
---
lisp/emacs-lisp/bytecomp.el | 29 +++++++++++++++++++++++++++++
src/fns.c | 11 +++++++++++
test/lisp/emacs-lisp/bytecomp-tests.el | 17 +++++++++++++++++
3 files changed, 57 insertions(+)
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index fdd4276e4e..a1626c0b9d 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -1572,6 +1572,7 @@ (defmacro byte-compile-close-variables (&rest body)
;; macroenvironment.
(copy-alist byte-compile-initial-macro-environment))
(byte-compile--outbuffer nil)
+ (overriding-plist-environment nil)
(byte-compile-function-environment nil)
(byte-compile-bound-variables nil)
(byte-compile-lexical-variables nil)
@@ -4712,6 +4713,34 @@ (put 'make-variable-buffer-local
'byte-hunk-handler 'byte-compile-form-make-variable-buffer-local)
(defun byte-compile-form-make-variable-buffer-local (form)
(byte-compile-keep-pending form 'byte-compile-normal-call))
+
+(put 'function-put 'byte-hunk-handler 'byte-compile-define-symbol-prop)
+(put 'define-symbol-prop 'byte-hunk-handler 'byte-compile-define-symbol-prop)
+(defun byte-compile-define-symbol-prop (form)
+ (pcase form
+ ((and `(,op ,fun ,prop ,val)
+ (guard (and (macroexp-const-p fun)
+ (macroexp-const-p prop)
+ (or (macroexp-const-p val)
+ ;; Also accept anonymous functions, since
+ ;; we're at top-level which implies they're
+ ;; also constants.
+ (pcase val (`(function (lambda . ,_)) t))))))
+ (byte-compile-push-constant op)
+ (byte-compile-form fun)
+ (byte-compile-form prop)
+ (let* ((fun (eval fun))
+ (prop (eval prop))
+ (val (if (macroexp-const-p val)
+ (eval val)
+ (byte-compile-lambda (cadr val)))))
+ (push `(,fun
+ . (,prop ,val ,@(alist-get fun overriding-plist-environment)))
+ overriding-plist-environment)
+ (byte-compile-push-constant val)
+ (byte-compile-out 'byte-call 3)))
+
+ (_ (byte-compile-keep-pending form))))
\f
;;; tags
diff --git a/src/fns.c b/src/fns.c
index d849618f2b..00b6ed6a28 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -1987,6 +1987,10 @@ DEFUN ("get", Fget, Sget, 2, 2, 0,
(Lisp_Object symbol, Lisp_Object propname)
{
CHECK_SYMBOL (symbol);
+ Lisp_Object propval = Fplist_get (CDR (Fassq (symbol, Voverriding_plist_environment)),
+ propname);
+ if (!NILP (propval))
+ return propval;
return Fplist_get (XSYMBOL (symbol)->plist, propname);
}
@@ -5163,6 +5167,13 @@ syms_of_fns (void)
DEFSYM (Qcursor_in_echo_area, "cursor-in-echo-area");
DEFSYM (Qwidget_type, "widget-type");
+ DEFVAR_LISP ("overriding-plist-environment", Voverriding_plist_environment,
+ doc: /* An alist overrides the plists of the symbols which it lists.
+Used by the byte-compiler to apply `define-symbol-prop' during
+compilation. */);
+ Voverriding_plist_environment = Qnil;
+ DEFSYM (Qoverriding_plist_environment, "overriding-plist-environment");
+
staticpro (&string_char_byte_cache_string);
string_char_byte_cache_string = Qnil;
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el
index d15bd8b6e6..8ef2ce7025 100644
--- a/test/lisp/emacs-lisp/bytecomp-tests.el
+++ b/test/lisp/emacs-lisp/bytecomp-tests.el
@@ -545,6 +545,23 @@ (ert-deftest bytecomp-tests--old-style-backquotes ()
This functionality has been obsolete for more than 10 years already
and will be removed soon. See (elisp)Backquote in the manual.")))))))
+
+(ert-deftest bytecomp-tests-function-put ()
+ "Check `function-put' operates during compilation."
+ (should (boundp 'lread--old-style-backquotes))
+ (bytecomp-tests--with-temp-file source
+ (dolist (form '((function-put 'bytecomp-tests--foo 'foo 1)
+ (function-put 'bytecomp-tests--foo 'bar 2)
+ (defmacro bytecomp-tests--foobar ()
+ `(cons ,(function-get 'bytecomp-tests--foo 'foo)
+ ,(function-get 'bytecomp-tests--foo 'bar)))
+ (defvar bytecomp-tests--foobar 1)
+ (setq bytecomp-tests--foobar (bytecomp-tests--foobar))))
+ (print form (current-buffer)))
+ (write-region (point-min) (point-max) source nil 'silent)
+ (byte-compile-file source t)
+ (should (equal bytecomp-tests--foobar (cons 1 2)))))
+
;; Local Variables:
;; no-byte-compile: t
;; End:
--
2.11.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: patch --]
[-- Type: text/x-diff, Size: 1014 bytes --]
From 848a5eb1ed15bb975fe308464b2891b160c5a420 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Fri, 4 Aug 2017 19:50:21 -0400
Subject: [PATCH v2 2/2] Let the cl-typep effects of defclass work during
compilation (Bug#27718)
* lisp/emacs-lisp/eieio.el (defclass): Use `define-symbol-prop'
instead of `put'.
---
lisp/emacs-lisp/eieio.el | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el
index 1a7de55fce..8b92d5b7ac 100644
--- a/lisp/emacs-lisp/eieio.el
+++ b/lisp/emacs-lisp/eieio.el
@@ -246,7 +246,7 @@ (defmacro defclass (name superclasses slots &rest options-and-doc)
;; test, so we can let typep have the CLOS documented behavior
;; while keeping our above predicate clean.
- (put ',name 'cl-deftype-satisfies #',testsym2)
+ (define-symbol-prop ',name 'cl-deftype-satisfies #',testsym2)
(eieio-defclass-internal ',name ',superclasses ',slots ',options-and-doc)
--
2.11.1
next prev parent reply other threads:[~2017-08-05 1:06 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-15 21:50 bug#27718: 26.0.50; (cl-typep instance-ab 'class-a) gives wrong answer when compiled npostavs
2017-07-21 12:23 ` npostavs
2017-07-21 13:19 ` Stefan Monnier
2017-07-22 17:51 ` npostavs
2017-07-24 15:30 ` Stefan Monnier
2017-07-24 19:44 ` Stefan Monnier
2017-07-25 16:34 ` Noam Postavsky
2017-07-25 21:21 ` Stefan Monnier
2017-08-05 1:06 ` npostavs [this message]
2017-08-05 12:49 ` Stefan Monnier
2017-08-08 1:16 ` npostavs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fud67rh9.fsf@users.sourceforge.net \
--to=npostavs@users.sourceforge.net \
--cc=27718@debbugs.gnu.org \
--cc=agrambot@gmail.com \
--cc=monnier@IRO.UMontreal.CA \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.