mooz / js2-mode

Improved JavaScript editing mode for GNU Emacs
GNU General Public License v3.0
1.33k stars 186 forks source link

Fail start mode with "Error running timer" on Emacs 31.0.50 #603

Open kostafey opened 1 month ago

kostafey commented 1 month ago

GNU Emacs 31.0.50 (build from master, commit: d50c82f3e98e5418e5a42b48162bc26028309b89)

Steps to reproduce: M-x js2-mode

Message: Error running timer ‘js2-mode-idle-reparse’: (args-out-of-range #s(js2-keyword-node 44 253 5 nil nil) 6)

Full trace with M-x toggle-debug-on-error:

Debugger entered--Lisp error: (args-out-of-range #s(js2-keyword-node :type 44 :pos 253 :len 5 :props nil :parent nil) 6)
  js2-parse-highlight-member-expr-node(#s(js2-keyword-node :type 44 :pos 253 :len 5 :props nil :parent nil))
  js2-parse-member-expr-tail(t #s(js2-keyword-node :type 44 :pos 253 :len 5 :props nil :parent nil))
  js2-parse-member-expr(t)
  js2-parse-unary-expr()
  js2-parse-expon-expr()
  js2-parse-mul-expr()
  js2-parse-add-expr()
  js2-parse-shift-expr()
  js2-parse-rel-expr()
  js2-parse-eq-expr()
  js2-parse-bit-and-expr()
  js2-parse-bit-xor-expr()
  js2-parse-bit-or-expr()
  js2-parse-and-expr()
  js2-parse-or-expr()
  js2-parse-nullish-coalescing-expr()
  js2-parse-cond-expr()
  js2-parse-assign-expr()
  js2-parse-variables(124 227)
  js2-parse-const-var()
  js2-statement-helper()
  js2-parse-statement()
  js2-parse-function-body(#s(js2-function-node :type 111 :pos 47 :len 1 :props nil :parent nil :kids nil :symbol-table ((iFrameTaxLoadedSign . #s(js2-symbol :decl-type 124 :name "iFrameTaxLoadedSign" :ast-node #s(js2-name-node :type 39 :pos 231 :len 19 :props nil :parent nil :name "iFrameTaxLoadedSign" :scope nil))) (maintenance . #s(js2-symbol :decl-type 124 :name "maintenance" :ast-node #s(js2-name-node :type 39 :pos 0 :len 11 :props nil :parent #s(js2-var-init-node :type 124 :pos 4 :len 52 :props nil :parent #s(js2-var-decl-node :type 124 :pos 0 :len 56 :props nil :parent ... :kids ... :decl-type 124) :target #6 :initializer #s(js2-call-node :type 38 :pos 14 :len 38 :props nil :parent #7 :target ... :args ... :lp 23 :rp 37)) :name "maintenance" :scope nil))) (spinner . #s(js2-symbol :decl-type 124 :name "spinner" :ast-node #s(js2-name-node :type 39 :pos 0 :len 7 :props nil :parent #s(js2-var-init-node :type 124 :pos 4 :len 44 :props nil :parent #s(js2-var-decl-node :type 124 :pos 0 :len 48 :props nil :parent ... :kids ... :decl-type 124) :target #7 :initializer #s(js2-call-node :type 38 :pos 10 :len 34 :props nil :parent #8 :target ... :args ... :lp 23 :rp 33)) :name "spinner" :scope nil))) (iFrame . #s(js2-symbol :decl-type 124 :name "iFrame" :ast-node #s(js2-name-node :type 39 :pos 0 :len 6 :props nil :parent #s(js2-var-init-node :type 124 :pos 4 :len 45 :props nil :parent #s(js2-var-decl-node :type 124 :pos 0 :len 49 :props nil :parent ... :kids ... :decl-type 124) :target #8 :initializer #s(js2-call-node :type 38 :pos 9 :len 36 :props nil :parent #9 :target ... :args ... :lp 23 :rp 35)) :name "iFrame" :scope nil)))) :parent-scope nil :top nil :functions nil :regexps nil :symbols nil :param-count 0 :var-names nil :consts nil :temp-number 0 :ftype FUNCTION :form FUNCTION_EXPRESSION :name nil :params nil :rest-p nil :body nil :lp 8 :rp 9 :ignore-dynamic nil :needs-activation nil :generator-type nil :async nil :member-expr nil))
  js2-parse-function-internal(FUNCTION_EXPRESSION 47 nil nil nil)
  js2-parse-function(FUNCTION_EXPRESSION 47 nil nil nil)
  js2-parse-function-expr()
  js2-parse-primary-expr()
  js2-parse-member-expr(t)
  js2-parse-unary-expr()
  js2-parse-expon-expr()
  js2-parse-mul-expr()
  js2-parse-add-expr()
  js2-parse-shift-expr()
  js2-parse-rel-expr()
  js2-parse-eq-expr()
  js2-parse-bit-and-expr()
  js2-parse-bit-xor-expr()
  js2-parse-bit-or-expr()
  js2-parse-and-expr()
  js2-parse-or-expr()
  js2-parse-nullish-coalescing-expr()
  js2-parse-cond-expr()
  js2-parse-assign-expr()
  js2-parse-argument-list()
  js2-parse-function-call(#s(js2-prop-get-node :type 33 :pos 0 :len 25 :props nil :parent #s(js2-call-node :type 38 :pos 1 :len 1 :props nil :parent nil :target #1 :args nil :lp 25 :rp nil) :op-pos 9 :left #s(js2-name-node :type 39 :pos 0 :len 8 :props nil :parent #1 :name "document" :scope nil) :right #s(js2-name-node :type 39 :pos 9 :len 16 :props nil :parent #1 :name "addEventListener" :scope nil)))
  js2-parse-member-expr-tail(t #s(js2-name-node :type 39 :pos 0 :len 8 :props nil :parent #s(js2-prop-get-node :type 33 :pos 0 :len 25 :props nil :parent #s(js2-call-node :type 38 :pos 1 :len 1 :props nil :parent nil :target #3 :args nil :lp 25 :rp nil) :op-pos 9 :left #2 :right #s(js2-name-node :type 39 :pos 9 :len 16 :props nil :parent #3 :name "addEventListener" :scope nil)) :name "document" :scope nil))
  js2-parse-member-expr(t)
  js2-parse-unary-expr()
  js2-parse-expon-expr()
  js2-parse-mul-expr()
  js2-parse-add-expr()
  js2-parse-shift-expr()
  js2-parse-rel-expr()
  js2-parse-eq-expr()
  js2-parse-bit-and-expr()
  js2-parse-bit-xor-expr()
  js2-parse-bit-or-expr()
  js2-parse-and-expr()
  js2-parse-or-expr()
  js2-parse-nullish-coalescing-expr()
  js2-parse-cond-expr()
  js2-parse-assign-expr()
  js2-parse-expr()
  js2-parse-name-or-label()
  js2-statement-helper()
  js2-parse-statement()
  js2-do-parse()
  js2-parse()
  js2-reparse()
  js2-mode-idle-reparse(#<buffer someJsFile.js>)
  apply(js2-mode-idle-reparse #<buffer someJsFile.js>)
  timer-event-handler([t 0 0 0 nil js2-mode-idle-reparse (#<buffer someJsFile.js>) idle 0 nil])
dgutov commented 1 month ago

Hi!

Are you sure reproducing this bug doesn't require some specific code to be present in the buffer?

kostafey commented 1 month ago

Are you sure reproducing this bug doesn't require some specific code to be present in the buffer?

Yes, you're right. Now I see that it fails only for some code. Here is a minimal js that reproduces this case:

document.addEventListener('DOMContentLoaded', function() {
  var id = null;
});
dgutov commented 1 month ago

Thank you. Any chance you're using an older version of js2-mode, maybe?

I'm testing with Emacs 31.0.50 built from the current master and the latest js2-mode, and I'm not seeing any error with these buffer contents.

kostafey commented 1 month ago

Any chance you're using an older version of js2-mode, maybe?

No, it is an actual MELPA version: js2-mode-20240418.6. But I figured out that the issue can't be reproduced if js2-mode loaded from .el or .elc files. Only loading from native compiled version (.eln) leads to this issue.

So, the actual workaround for me is:

(setq native-comp-jit-compilation-deny-list '("js2-mode"))

UPD: Not fully relevant to js2-mode, but rjsx-mode has a similar problem and a similar solution in the current version of Emacs. Although rjsx-mode may be enabled in the buffer, it highlights all tags in red (as a syntax error). When loading from el/elc files, the problem goes away:

(setq native-comp-jit-compilation-deny-list
      '("js2-mode" "rjsx-mode"))
dgutov commented 1 month ago

All right, that makes sense. I also remember a couple of bugs in the similar vein that only happen with native compilation. Problem is, each has to be reported and fixed separately.

And like the last time, it doesn't reproduce on my machine if I just reconfigure --with-native-compilation and rebuild. Maybe it's dependent on some special configuration, or the system details, or etc.

So if you could do a M-x report-emacs-bug with the reproducer and the note that this happens with native-compilation only, that would help a lot. I can do it for you, but I won't be able to answer follow-up questions.

dgutov commented 1 month ago

You can try deleting the existing native-compilation cache, BTW.

IIRC this helped in some instance of this problem in the past.