Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hangs forever on simple YAML file when re-building SyntaxSet #219

Closed
sharkdp opened this issue Oct 15, 2018 · 8 comments
Closed

Hangs forever on simple YAML file when re-building SyntaxSet #219

sharkdp opened this issue Oct 15, 2018 · 8 comments
Labels

Comments

@sharkdp
Copy link
Contributor

sharkdp commented Oct 15, 2018

How to reproduce?

From the syntect root folder, perform these steps:

  1. Create a simple YAML file:
    echo "# test" > test.yml
  2. Run syncat on this file. Everything works as expected:
    ▶ cargo run --example=syncat -- test.yml
        Finished dev [unoptimized + debuginfo] target(s) in 0.08s
         Running `target/debug/examples/syncat test.yml`
    # test
    
  3. Create an empty folder
    mkdir empty
    
  4. Run syncat again with --extra-sntaxes set to the empty folder
    ▶ cargo run --example=syncat -- test.yml --extra-syntaxes empty
        Finished dev [unoptimized + debuginfo] target(s) in 0.08s
         Running `target/debug/examples/syncat test.yml --extra-syntaxes empty`
    
    This seems to hang forever.

Additional remarks

  • This bug only appears if the YAML file contains a line that begins with a comment
  • I could not reproduce this behavior with another syntax.
@sharkdp
Copy link
Contributor Author

sharkdp commented Oct 15, 2018

Apparently, it loops endlessly here:

while self.parse_next_token(
line,
syntax_set,
&mut match_start,
&mut search_cache,
&mut regions,
&mut non_consuming_push_at,
&mut res
) {}

with this state:

line = "# test\n"
match_start = 0
regions = Region { raw: OnigRegion { allocated: 10, num_regs: 1, beg: 0x7f6bc34f0a90, end: 0x7f6bc34f0ac0, history_root: 0x0 } }
non_consuming_push_at = (0, 14532)
res = [(0, Push(<source.yaml>))]

The second number in non_consuming_push_at keeps getting incremented. Everything else seems to stay the same.

@keith-hall
Copy link
Collaborator

Commenting out this line:

context.prototype = Some(prototype_id.clone());

seems to fix it, so maybe it's a problem with how prototypes are handled on syntax sets that get turned into builders and back again? Interestingly, the YAML syntax definition's comment context is the last one that gets loaded (due to it being the last context in the YAML.sublime-syntax file), in case that makes any difference.

@keith-hall
Copy link
Collaborator

Actually, more precisely, the problem seems to be that the YAML syntax includes the comment context in it's prototype, and it is not being correctly ignored / marked as "no prototype" when rebuilding the syntax set, which is why the stack size is growing constantly.

@keith-hall
Copy link
Collaborator

I tried adding:

Pattern::Include(ContextReference::Direct(ref s)) => {
    Self::recursively_mark_no_prototype(syntax, s.index(), contexts, no_prototype);
}

at

, but it still hangs forever - maybe the indexes are different when rebuilding so the direct references are no longer valid?

@robinst
Copy link
Collaborator

robinst commented Oct 16, 2018

Thanks for investigating! Sounds like my bad, I'll have a look tomorrow.

@keith-hall keith-hall added the bug label Oct 16, 2018
robinst added a commit that referenced this issue Oct 18, 2018
After a SyntaxSet is built once, all the references are replaced by
direct references (via index).

When it's converted back to a builder and then built again, the code
that marks prototypes needs to handle those references too, otherwise
some contexts include the prototype when they should not.

Fixes #219.
@robinst
Copy link
Collaborator

robinst commented Oct 18, 2018

Raised a PR with a fix: #221

@robinst
Copy link
Collaborator

robinst commented Oct 18, 2018

@keith-hall: I think all your fix was missing was doing the same thing for references in Pattern::Match :).

@keith-hall
Copy link
Collaborator

heh I was so close, thanks for taking over the investigation and fixing the problem @robinst - your test coverage is awesome, I could think of no suggestions for improvement ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants