unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#25941: 26.0.50; Different code behavior between using the auto-compiled and evaled versions
@ 2017-03-02 23:43 Kaushal Modi
  2017-03-03 12:12 ` Kaushal Modi
  0 siblings, 1 reply; 6+ messages in thread
From: Kaushal Modi @ 2017-03-02 23:43 UTC (permalink / raw)
  To: 25941, ohwoeowho

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

I discovered a difference in between when running a command from the avy
package (available on GNU Elpa).

I verified that this issue did not exist on emacs 25.1 or emacs 25.2.1.

But it does exist on emacs 26.0.50.

How to recreate the problem:

1. emacs -Q
2. Install the avy package from GNU Elpa
3. M-x toggle-debug-on-error
4. M-x avy-goto-line
5. Enter the number 10

You will get a backtrace like this:

=====
Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
  avy-action-goto(nil)
  avy-goto-line(1)
  funcall-interactively(avy-goto-line 1)
  call-interactively(avy-goto-line record nil)
  command-execute(avy-goto-line record)
  execute-extended-command(nil "avy-goto-line" nil)
  funcall-interactively(execute-extended-command nil "avy-goto-line" nil)
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)
=====

By edebugging the avy.el code, I figured out that the problem was that this
function was returning nil when it should in fact be returning t.

The difficulty in debugging this further is that if I evaluate that
function (avy--process), then the problem goes away.
With point in that function, after I do C-M-x, M-x avy-goto-line starts
working fine.

This problem repeats after each emacs restart; and goes away after C-M-x on
avy--process.

This means that when the compiled version of avy--process is loaded, that
function returns nil incorrectly. But after manually evaluating it, it
starts returning t when expected.

=====
(defun avy--process (candidates overlay-fn)
  "Select one of CANDIDATES using `avy-read'.
Use OVERLAY-FN to visualize the decision overlay."
  (unless (and (consp (car candidates))
               (windowp (cdar candidates)))
    (setq candidates
          (mapcar (lambda (x) (cons x (selected-window)))
                  candidates)))
  (let ((len (length candidates))
        (cands (copy-sequence candidates))
        res)
    (if (= len 0)
        (message "zero candidates")
      (if (= len 1)
          (setq res (car candidates))
        (unwind-protect
             (progn
               (avy--make-backgrounds
                (avy-window-list))
               (setq res (if (eq avy-style 'de-bruijn)
                             (avy-read-de-bruijn
                              candidates avy-keys)
                           (avy-read (avy-tree candidates avy-keys)
                                     overlay-fn
                                     #'avy--remove-leading-chars))))
          (avy--done)))
      (cond ((eq res 'restart)
             (avy--process cands overlay-fn))
            ;; ignore exit from `avy-handler-function'
            ((eq res 'exit))
            (t
             (avy-push-mark)
             (when (and (consp res)
                        (windowp (cdr res)))
               (let* ((window (cdr res))
                      (frame (window-frame window)))
                 (unless (equal frame (selected-frame))
                   (select-frame-set-input-focus frame))
                 (select-window window))
               (setq res (car res)))

             (funcall (or avy-action 'avy-action-goto)
                      (if (consp res)
                          (car res)
                        res)))))))
=====

More info..

The avy--process is called via avy--line when doing M-x avy-goto-line.
Below is the relevant snippet from the avy-goto-line fn. Notice the r
variable.
When numbers are entered as input after M-x avy-goto-line, that (avy--line
(eq arg 4) form should return t. But it is returning nil instead. So
avy-action-goto gets called when it shouldn't be.

After manually evaluating avy--process, r is set to t instead of nil as
expected and the problem goes away.

===== snippet from avy-goto-line fn definition =====
             (r (avy--line (eq arg 4))))
        (unless (eq r t)
          (avy-action-goto r))))))
=====

I started off this bug report on the package github page:
https://github.com/abo-abo/avy/issues/182
But realizing that the same package version works fine on emacs 25.x but
not on the master build, I am filing this report.

In GNU Emacs 26.0.50 (build 52, x86_64-unknown-linux-gnu, GTK+ Version
2.24.23)
 of 2017-03-02
Repository revision: d0d26c1379598983d2163deb13ba8ab13b14ba2c
Windowing system distributor 'The X.Org Foundation', version 11.0.60900000
System Description: Red Hat Enterprise Linux Workstation release 6.6
(Santiago)


Configured using:
 'configure --with-modules
 --prefix=/home/kmodi/usr_local/apps/6/emacs/master
 '--program-transform-name=s/^ctags$/ctags_emacs/'
 'CPPFLAGS=-fgnu89-inline -I/home/kmodi/usr_local/6/include
 -I/usr/include/freetype2 -I/usr/include' 'CFLAGS=-ggdb3 -O0'
 'CXXFLAGS=-ggdb3 -O0' 'LDFLAGS=-L/home/kmodi/usr_local/6/lib
 -L/home/kmodi/usr_local/6/lib64 -ggdb3''

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GCONF GSETTINGS
NOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS GTK2 X11 MODULES

Important settings:
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=none
  locale-coding-system: utf-8-unix


-- 

Kaushal Modi

[-- Attachment #2: Type: text/html, Size: 7287 bytes --]

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

* bug#25941: 26.0.50; Different code behavior between using the auto-compiled and evaled versions
  2017-03-02 23:43 bug#25941: 26.0.50; Different code behavior between using the auto-compiled and evaled versions Kaushal Modi
@ 2017-03-03 12:12 ` Kaushal Modi
  2017-03-09 16:31   ` Kaushal Modi
  0 siblings, 1 reply; 6+ messages in thread
From: Kaushal Modi @ 2017-03-03 12:12 UTC (permalink / raw)
  To: 25941

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

Here's a set of updates that could probably help trace the problem:

- I rebuilt emacs from master using make bootstrap, but the problem
persists.
- I see the problem when I do "M-x avy-goto-line 10" but not when I do "M-:
(avy-goto-line 10)". So the bug triggers only during interactive execution?

A workaround for now is to delete the avy.elc file.

Does the avy--process code not work well with the recently byte compiler
incompatibility in the master branch?
-- 

Kaushal Modi

[-- Attachment #2: Type: text/html, Size: 695 bytes --]

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

* bug#25941: 26.0.50; Different code behavior between using the auto-compiled and evaled versions
  2017-03-03 12:12 ` Kaushal Modi
@ 2017-03-09 16:31   ` Kaushal Modi
  2017-03-09 18:23     ` Vibhav Pant
  0 siblings, 1 reply; 6+ messages in thread
From: Kaushal Modi @ 2017-03-09 16:31 UTC (permalink / raw)
  To: 25941, Vibhav Pant, Oleh Krehel

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

Hi Vibhav,

This issue seems to be related to the switch bytecode change.

Can you please review it.

The code snippet in
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=25941#5 returns
t on emacs 25.2 but nil on emacs master. That is messing up the
avy-goto-line function (avy package).

avy--process does contain the cond form which is affected by the switch
bytecode change.

If I delete the .elc, the issue goes away.

On Fri, Mar 3, 2017 at 7:12 AM Kaushal Modi <kaushal.modi@gmail.com> wrote:

> Here's a set of updates that could probably help trace the problem:
>
> - I rebuilt emacs from master using make bootstrap, but the problem
> persists.
> - I see the problem when I do "M-x avy-goto-line 10" but not when I do
> "M-: (avy-goto-line 10)". So the bug triggers only during interactive
> execution?
>
> A workaround for now is to delete the avy.elc file.
>
> Does the avy--process code not work well with the recently byte compiler
> incompatibility in the master branch?
> --
>
> Kaushal Modi
>
-- 

Kaushal Modi

[-- Attachment #2: Type: text/html, Size: 2004 bytes --]

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

* bug#25941: 26.0.50; Different code behavior between using the auto-compiled and evaled versions
  2017-03-09 16:31   ` Kaushal Modi
@ 2017-03-09 18:23     ` Vibhav Pant
  2017-03-09 18:28       ` Kaushal Modi
  0 siblings, 1 reply; 6+ messages in thread
From: Vibhav Pant @ 2017-03-09 18:23 UTC (permalink / raw)
  To: Kaushal Modi; +Cc: 25941, Oleh Krehel

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

On Thu, Mar 9, 2017 at 10:01 PM, Kaushal Modi <kaushal.modi@gmail.com> wrote:
> This issue seems to be related to the switch bytecode change.

`cond' returns the value of the met condition when the clause doesn't
have a body. That's what seems to be happening when (eq res 'exit).
The result should be t instead of nil. A similar example like:
(defun test (v)
  (cond ((eq v 1) 'one)
((eq v 2))
(t 'none)))
Also displays different results with (test 2) when byte compiled. I've
added a patch to bytecomp.el which tries to fix this, could you apply
it and see whether the issue still exists?

Thanks,
Vibhav

-- 
Vibhav Pant
vibhavp@gmail.com

[-- Attachment #2: condition-only-clause.diff --]
[-- Type: text/plain, Size: 800 bytes --]

diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 25513bd024..068988813a 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -4128,7 +4128,9 @@ byte-compile-cond-jump-table
           ;; depth/tag conflicts or violating asserts down the road.
           ;; To make sure `byte-compile-body' itself doesn't violate this,
           ;; we use `cl-assert'.
-          (byte-compile-body body byte-compile--for-effect)
+          (if (null body)
+              (byte-compile-body '(t) byte-compile--for-effect)
+            (byte-compile-body body byte-compile--for-effect))
           (cl-assert (or (= byte-compile-depth init-depth)
                          (= byte-compile-depth (1+ init-depth))))
           (byte-compile-goto 'byte-goto donetag)

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

* bug#25941: 26.0.50; Different code behavior between using the auto-compiled and evaled versions
  2017-03-09 18:23     ` Vibhav Pant
@ 2017-03-09 18:28       ` Kaushal Modi
  2017-03-09 19:15         ` Kaushal Modi
  0 siblings, 1 reply; 6+ messages in thread
From: Kaushal Modi @ 2017-03-09 18:28 UTC (permalink / raw)
  To: Vibhav Pant; +Cc: 25941, Oleh Krehel

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

On Thu, Mar 9, 2017 at 1:23 PM Vibhav Pant <vibhavp@gmail.com> wrote:

> I've
> added a patch to bytecomp.el which tries to fix this, could you apply
> it and see whether the issue still exists?
>

That fixes it! Thanks.
-- 

Kaushal Modi

[-- Attachment #2: Type: text/html, Size: 650 bytes --]

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

* bug#25941: 26.0.50; Different code behavior between using the auto-compiled and evaled versions
  2017-03-09 18:28       ` Kaushal Modi
@ 2017-03-09 19:15         ` Kaushal Modi
  0 siblings, 0 replies; 6+ messages in thread
From: Kaushal Modi @ 2017-03-09 19:15 UTC (permalink / raw)
  To: Vibhav Pant, 25941-done; +Cc: Oleh Krehel

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

Thanks for the prompt action and fix.

(1) I re-built my emacs to the latest master containing the fix
(2) Re-built the elpa dir by running
     (byte-recompile-directory package-user-dir nil :force)
(3) .. and confirm the bug as fixed!



On Thu, Mar 9, 2017 at 1:28 PM Kaushal Modi <kaushal.modi@gmail.com> wrote:

> On Thu, Mar 9, 2017 at 1:23 PM Vibhav Pant <vibhavp@gmail.com> wrote:
>
> I've
> added a patch to bytecomp.el which tries to fix this, could you apply
> it and see whether the issue still exists?
>
>
> That fixes it! Thanks.
> --
>
> Kaushal Modi
>
-- 

Kaushal Modi

[-- Attachment #2: Type: text/html, Size: 1713 bytes --]

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

end of thread, other threads:[~2017-03-09 19:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-02 23:43 bug#25941: 26.0.50; Different code behavior between using the auto-compiled and evaled versions Kaushal Modi
2017-03-03 12:12 ` Kaushal Modi
2017-03-09 16:31   ` Kaushal Modi
2017-03-09 18:23     ` Vibhav Pant
2017-03-09 18:28       ` Kaushal Modi
2017-03-09 19:15         ` Kaushal Modi

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