Skip to content

Increase rule stack protection limit - Syntax highlighting broken in JS files with multiple nested functions #9937

Closed

Description

  • VSCode Version: 1.4.0-insider (anything after the 1.3.x builds, still broken as of the 2016-07-29 build)
  • OS Version: Windows 7 x64

Steps to Reproduce:
Write some code and continue nesting functions until the syntax highlighting stops working. Once it stops working then it will be broken for the remainder of the file. Two examples are pasted below (obviously the examples are simplified and contrived, but they illustrate the problem):

broken_highlight1

broken_highlight2

Activity

  1. dlong500 commented on Jul 29, 2016

    @dlong500
    Author

    And just to be clear, this problem was not occurring until the 1.4.x codebase as far as I can remember. In fact the problem does not exist under the current 1.3.1 release.

  2. added
    javascript
    on Aug 2, 2016
  3. aeschli commented on Aug 2, 2016

    @aeschli
    Contributor

    alexandrudima Alex, is that maybe related to the max number of nested scoped?

  4. dlong500 commented on Aug 4, 2016

    @dlong500
    Author

    Unfortunately the problem persists with the public 1.4 release. Have you figured out what is going on yet?

    In the meantime, are there links to installers for the previous versions? I don't see v1.3.1 (or anything past 0.10.10) on the Previous Releases wiki page.

  5. alexdima commented on Aug 5, 2016

    @alexdima
    Member

    Martin Aeschlimann (@aeschli) This is my change (if the stack goes above 30 tokenization is aborted, think of it like a stack overflow) - f7d23a3

  6. aeschli commented on Aug 5, 2016

    @aeschli
    Contributor

    Ok, I think 30 is reasonable and the example is rather a corner case.
    Closing as 'works as expected'.

  7. dlong500 commented on Aug 5, 2016

    @dlong500
    Author

    Can the limit be increased a small amount? I know the examples seem like corner cases, but I actually have a few files that are affected by this (which is why I tried to create simplified examples in the first place).

  8. alexdima commented on Aug 5, 2016

    @alexdima
    Member
  9. changed the title [-]Syntax highlighting broken in JS files with multiple nested functions[/-] [+]Increase rule stack protection limit - Syntax highlighting broken in JS files with multiple nested functions[/+] on Aug 5, 2016
  10. ericfernandez commented on Aug 6, 2016

    @ericfernandez

    Davison Long (@dlong500) This affected one of my projects as well. If you're still looking for the older build of VSCode, they are linked in the updates section of their website 👍

    Here is 1.3.1 that isn't affected by this:
    https://code.visualstudio.com/updates/June_2016

  11. 1 remaining item

  12. dontcryme commented on Aug 10, 2016

    @dontcryme
    • VSCode Version: Code 1.4.0 (6276dcb, 2016-08-04T16:45:31.680Z)
    • OS Version: Windows_NT ia32 6.1.7601

    after vscode update,
    I have a same problem with 'multiple nested functions'.

    • source code highlighting problem pic (all of the sample source code line is 94)

    source1

    if i replace my code
    "connection.rollback(function() {
    console.error("rollback error"); connection.release(); res.json(-1); return; }); "
    with
    "connection.rollback(function() { console.error("rollback error"); connection.release(); res.json(-1); return ; });"
    everything is alright. (remove newline)

    • source code highlighting problem fix pic

    source2

    why this happened to me

  13. alexdima commented on Aug 12, 2016

    @alexdima
    Member

    Sorry about these issues, but due to this limit we now get to find out about cases where grammars are broken (forget to pop out their rule stack). It might take a couple of releases, but this will bring our grammars in a better shape ("correct" is a better word than better) which will lead to reduced memory usage and faster tokenization times on the long term.

  14. dontcryme commented on Aug 17, 2016

    @dontcryme
    • VSCode Version: Code - Insiders 1.5.0-insider (11ffcfc, 2016-08-16T06:07:58.452Z)
    • OS Version: Windows_NT ia32 6.1.7601

    Martin Aeschlimann (@aeschli)
    after vscode insider install,
    i have a same problem, too.(source code highlighting not work. :-( )

    • source code highlighting problem pic(VSCode Insider 1.5.0)
      160817
    • source code highlighting problem fix pic(VSCode Insider 1.5.0)
      160817_1
  15. added
    bug
    tokenization
    on Aug 18, 2016
  16. prezmo commented on Aug 27, 2016

    @prezmo

    This issue touches some of files in my current project. VS Code version: 1.4.0. If you have any concerns with tokenization performance could you at least make this feature customizable in settings?

    Does insider version resolves the issue?

  17. alexdima commented on Aug 29, 2016

    @alexdima
    Member

    Przemek Szewczyk (@prezmo) Tokenization works based on a stack state machine. We interpret the rules the grammars define and transition between states, and push new states on the stack or pop them. We have received hard to reproduce bugs that were leading to out-of-memory crashes, with their root cause being invalid grammars. Think of it like a stack overflow which leads to OOM. We now have the limit of 30 states on the stack, we can increase this limit, but there are grammars that for each line end up pushing a state and forgetting to pop it. This leads to poor user experience and we get bugs in the form "VSCode feels slow... VSCode crashes randomly... etc" and many of them are due to the invalid grammars we ship with. Adding a limit to the stack size is similar to a stack overflow exception that AFAIK all runtimes throw eventually.

  18. alexdima commented on Aug 29, 2016

    @alexdima
    Member

    From #10908 ... looks like the JS grammar pushes +4 rules per embedded function.

  19. alexdima commented on Aug 29, 2016

    @alexdima
    Member

    From #10567 ... The maximum reached depth is 31

  20. dlong500 commented on Aug 30, 2016

    @dlong500
    Author

    Great! It's now fixed as far as I can tell for my projects. I think the increased limit should be more than I would ever need (hopefully).

  21. added
    verified
    on Sep 1, 2016
  22. locked and limited conversation to collaborators on Nov 18, 2017
  23. added a commit that references this issue on Sep 6, 2026
    efb7a4e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugjavascripttokenizationverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions