unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#39709: 28.0.50; [PATCH] substring and the byte compiler
@ 2020-02-21  6:22 Mark Oteiza
  2020-02-21 11:48 ` bug#39709: #39709: " Mattias Engdegård
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Oteiza @ 2020-02-21  6:22 UTC (permalink / raw)
  To: 39709


Hi,

I don't really understand the byte compiler, but I noticed in
disassembly that substring, despite having an opcode, is getting
call'd:

10      constant  substring
11      stack-ref 3
12      constant  0
13      stack-ref 7
15      call      3

when really I'd expect to see something like

57      stack-ref 2
58      stack-ref 7
60      min       
61      stack-ref 7
63      substring 

The only relevant change I found is bug#33807.  Enlightenment welcome.
Naive patch below.

diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index fce5e4aed6..ec340cd451 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -3506,6 +3506,7 @@ byte-defop-compiler
 					(0-1 . byte-compile-zero-or-one-arg)
 					(1-2 . byte-compile-one-or-two-args)
 					(2-3 . byte-compile-two-or-three-args)
+					(1-3 . byte-compile-one-to-three-args)
 					)))
 			   compile-handler
 			   (intern (concat "byte-compile-"
@@ -3690,6 +3691,13 @@ byte-compile-two-or-three-args
 	  ((= len 4) (byte-compile-three-args form))
 	  (t (byte-compile-subr-wrong-args form "2-3")))))
 
+(defun byte-compile-one-to-three-args (form)
+  (let ((len (length form)))
+    (cond ((= len 2) (byte-compile-one-arg form))
+          ((= len 3) (byte-compile-two-args form))
+          ((= len 4) (byte-compile-three-args form))
+	  (t (byte-compile-subr-wrong-args form "1-3")))))
+
 (defun byte-compile-noop (_form)
   (byte-compile-constant nil))
 
diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
index fe0930c684..d3c84335ec 100644
--- a/lisp/emacs-lisp/byte-opt.el
+++ b/lisp/emacs-lisp/byte-opt.el
@@ -1511,11 +1511,11 @@ byte-compile-side-effect-and-error-free-ops
 (defconst byte-compile-side-effect-free-ops
   (nconc
    '(byte-varref byte-nth byte-memq byte-car byte-cdr byte-length byte-aref
-     byte-symbol-value byte-get byte-concat2 byte-concat3 byte-sub1 byte-add1
-     byte-eqlsign byte-gtr byte-lss byte-leq byte-geq byte-diff byte-negate
-     byte-plus byte-max byte-min byte-mult byte-char-after byte-char-syntax
-     byte-buffer-substring byte-string= byte-string< byte-nthcdr byte-elt
-     byte-member byte-assq byte-quo byte-rem)
+     byte-symbol-value byte-get byte-substring byte-concat2 byte-concat3
+     byte-sub1 byte-add1 byte-eqlsign byte-gtr byte-lss byte-leq byte-geq
+     byte-diff byte-negate byte-plus byte-max byte-min byte-mult byte-char-after
+     byte-char-syntax byte-buffer-substring byte-string= byte-string<
+     byte-nthcdr byte-elt byte-member byte-assq byte-quo byte-rem)
    byte-compile-side-effect-and-error-free-ops))
 
 ;; This crock is because of the way DEFVAR_BOOL variables work.





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

* bug#39709: #39709: 28.0.50; [PATCH] substring and the byte compiler
  2020-02-21  6:22 bug#39709: 28.0.50; [PATCH] substring and the byte compiler Mark Oteiza
@ 2020-02-21 11:48 ` Mattias Engdegård
  2020-02-25 15:42   ` Mattias Engdegård
  0 siblings, 1 reply; 3+ messages in thread
From: Mattias Engdegård @ 2020-02-21 11:48 UTC (permalink / raw)
  To: Mark Oteiza; +Cc: 39709, Stefan Monnier

[-- Attachment #1: Type: text/plain, Size: 615 bytes --]

The missing 1-3 case seems to be a simple omission -- thanks for spotting it.

+(defun byte-compile-one-to-three-args (form)
+  (let ((len (length form)))
+    (cond ((= len 2) (byte-compile-one-arg form))
+          ((= len 3) (byte-compile-two-args form))
+          ((= len 4) (byte-compile-three-args form))
+	  (t (byte-compile-subr-wrong-args form "1-3")))))

Not sure how this would work. Don't you need to add the missing arguments?

Cleaned-up patch attached.
(Unless, of course, there is evidence that the byte op has never been emitted --- then we have an opportunity to drop it instead.)


[-- Attachment #2: 0001-Generate-substring-byte-op-bug-39709.patch --]
[-- Type: application/octet-stream, Size: 3969 bytes --]

From c7163d7a23f124b7bca611615e42a23e2987bd4d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Fri, 21 Feb 2020 12:16:20 +0100
Subject: [PATCH] Generate 'substring' byte op (bug#39709)

The 'substring' byte op was not emitted, apparently by mistake.  Fix.
Suggested by Mark Oteiza <mvoteiza@udel.edu>.

* lisp/emacs-lisp/bytecomp.el (byte-defop-compiler): Add '1-3' clause.
(byte-compile-one-to-three-args): New.
* lisp/emacs-lisp/byte-opt.el (byte-compile-side-effect-free-ops):
Add 'byte-substring'.
* test/lisp/emacs-lisp/bytecomp-tests.el
(byte-opt-testsuite-arith-data): Test 'substring'.
---
 lisp/emacs-lisp/byte-opt.el            |  2 +-
 lisp/emacs-lisp/bytecomp.el            | 10 +++++++++-
 test/lisp/emacs-lisp/bytecomp-tests.el |  7 ++++++-
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
index fe0930c684..4f72251aed 100644
--- a/lisp/emacs-lisp/byte-opt.el
+++ b/lisp/emacs-lisp/byte-opt.el
@@ -1515,7 +1515,7 @@ byte-compile-side-effect-free-ops
      byte-eqlsign byte-gtr byte-lss byte-leq byte-geq byte-diff byte-negate
      byte-plus byte-max byte-min byte-mult byte-char-after byte-char-syntax
      byte-buffer-substring byte-string= byte-string< byte-nthcdr byte-elt
-     byte-member byte-assq byte-quo byte-rem)
+     byte-member byte-assq byte-quo byte-rem byte-substring)
    byte-compile-side-effect-and-error-free-ops))
 
 ;; This crock is because of the way DEFVAR_BOOL variables work.
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index fce5e4aed6..6a2ee978af 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -3487,7 +3487,7 @@ byte-defop-compiler
 is the function and the second element is the bytecode-symbol.
 The second element may be nil, meaning there is no opcode.
 COMPILE-HANDLER is the function to use to compile this byte-op, or
-may be the abbreviations 0, 1, 2, 3, 0-1, or 1-2.
+may be the abbreviations 0, 1, 2, 3, 0-1, 1-2, 1-3, 2-3, or 2-and.
 If it is nil, then the handler is \"byte-compile-SYMBOL.\""
   (let (opcode)
     (if (symbolp function)
@@ -3506,6 +3506,7 @@ byte-defop-compiler
 					(0-1 . byte-compile-zero-or-one-arg)
 					(1-2 . byte-compile-one-or-two-args)
 					(2-3 . byte-compile-two-or-three-args)
+					(1-3 . byte-compile-one-to-three-args)
 					)))
 			   compile-handler
 			   (intern (concat "byte-compile-"
@@ -3690,6 +3691,13 @@ byte-compile-two-or-three-args
 	  ((= len 4) (byte-compile-three-args form))
 	  (t (byte-compile-subr-wrong-args form "2-3")))))
 
+(defun byte-compile-one-to-three-args (form)
+  (let ((len (length form)))
+    (cond ((= len 2) (byte-compile-three-args (append form '(nil nil))))
+          ((= len 3) (byte-compile-three-args (append form '(nil))))
+          ((= len 4) (byte-compile-three-args form))
+          (t (byte-compile-subr-wrong-args form "1-3")))))
+
 (defun byte-compile-noop (_form)
   (byte-compile-constant nil))
 
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el
index de11ae22d5..d4ceb47c36 100644
--- a/test/lisp/emacs-lisp/bytecomp-tests.el
+++ b/test/lisp/emacs-lisp/bytecomp-tests.el
@@ -347,7 +347,12 @@ byte-opt-testsuite-arith-data
                                 ((eq x 't) 99)
                                 (t 999))))
             '((a c) (b c) (7 c) (-3 c) (nil nil) (t c) (q c) (r c) (s c)
-              (t c) (x "a") (x "c") (x c) (x d) (x e))))
+              (t c) (x "a") (x "c") (x c) (x d) (x e)))
+
+    ;; `substring' bytecode generation (bug#39709).
+    (substring "abcdef")
+    (substring "abcdef" 2)
+    (substring "abcdef" 3 2))
   "List of expression for test.
 Each element will be executed by interpreter and with
 bytecompiled code, and their results compared.")
-- 
2.21.1 (Apple Git-122.3)


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

* bug#39709: #39709: 28.0.50; [PATCH] substring and the byte compiler
  2020-02-21 11:48 ` bug#39709: #39709: " Mattias Engdegård
@ 2020-02-25 15:42   ` Mattias Engdegård
  0 siblings, 0 replies; 3+ messages in thread
From: Mattias Engdegård @ 2020-02-25 15:42 UTC (permalink / raw)
  To: Mark Oteiza; +Cc: 39709-done, Stefan Monnier

No objection arrived -- pushed to master.






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

end of thread, other threads:[~2020-02-25 15:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-21  6:22 bug#39709: 28.0.50; [PATCH] substring and the byte compiler Mark Oteiza
2020-02-21 11:48 ` bug#39709: #39709: " Mattias Engdegård
2020-02-25 15:42   ` Mattias Engdegård

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