Re: Infinite loop when parsing simple C snippet.

Bastian Beischer <[email protected]> Sun, 14 Feb 2016 17:45:03 +0100
Newsgroups gmane.emacs.semantic
Message-ID <CAK9AuB8yjBEsKDS7HGu-=wurN0yO3=MvaiUp8McGz++SEmbQRg@mail.gmail.com>
Hello Eric,

thanks a lot for your help. The patch you provided indeed fixes the issue,
should it be commited to cedet / semantic? I have a few more questions:

1) Do you know why there is such a large difference in runtime between
emacs 24 and emacs 25?
2) I assume the bison (wisent) C/C++ parser is not yet included in cedet /
semantic? If it is, can I try it out?

Cheers
Bastian

On Sun, Feb 14, 2016 at 3:45 PM, Eric Ludlam <[email protected]> wrote:

> Hi
>
> I tried your example using emacs 24 w/ the latest from CEDET git and had
> no problems.
>
> I pulled the latest emacs 25 from git (I'm not that familiar with git SHA
> numbers to know if it is a match) and it also worked with no problems.
>
> With both versions however, what should take a small fraction of a second
> took longer.  E24 took 1.1 seconds, and E25 took 2.3 seconds.  If I add
> several more +(A)s, it takes several more seconds, or multiple minutes for
> E25 so it really feels like a hang.
>
> Looking at how expressions are parsed, I can see why it may be a problem.
> Folks have clearly been adding random bits to it for a while where the poor
> parser is cycling and parsing the same thing over and over recursively
> trying to get through the different options.   This is a side effect of the
> way that parser generator works, and is one of the reasons I'd like to
> upgrade the C/C++ parser to the wisent (bison) version.  Maybe someday.
>
> I poked at it to do by hand what bison would do for us and in Emacs 24
> went from 1.1 seconds to .04 seconds on the same code snippet.  The speed
> stays the same even after adding 10 more +(A)s.
>
> The observant on the list will note a strange (- end 1) in the patch. I'm
> not sure why that is yet, but without it the ";" keeps getting stuck on the
> end of the expression even though it isn't being parsed there.
>
> Whatever.
>
> Anyway, this should help a lot.
>
> Eric
>
>
>
> On 02/11/2016 08:49 AM, Bastian Beischer wrote:
>
>> Dear all,
>>
>> I'm trying to debug a problem with the semantic parser which enters an
>> infinite loop when parsing the following code:
>>
>> int A = 1;
>> int B = 1;
>> int C = 1;
>> int D = 1;
>> int T = (A)+
>>    (B)+
>>    (C)+
>>    (D);
>>
>> The problem goes away if the parentheses are removed. It also goes away
>> when the "int D = 1" and the corresponding summand below are removed.
>>
>> This is my output of "M-x cedet-version"
>>
>> CEDET Version:2.0
>> RequestedFileLoaded
>>    PackageVersionVersionVersion
>>    ----------------------------------------------------------
>>    cedet:2.0nilok
>>    eieio:1.4nilok
>>    semantic:2.2nilok
>>    srecode:1.2nilok
>>    ede:1.2nil2.0
>>
>>
>> C-h f cedet-version RET
>>    for details on output format.
>>
>>
>> You can reproduce the issue as follows.
>>
>> 1a) Use cedet shipped with emacs from "emacs-25" branch, the exact SHA1
>> I used is edc39c92a798821a931f282236f7f4a79c2b25a1
>> 1b) I also tried with the same emacs build, but using cedet from cedet
>> git's master branch, commit f6639c6ad2ab1a59ffda2b8952d6b31d9ddaf83c
>> 2) run emacs -Q
>> 3) evaluate (require 'cedet), (require 'semantic)
>> 4) open the buffer with the above contents
>> 5) run (semantic-force-refresh)
>>
>> The backtrace in the emacs lisp debugger seems to be this:
>>
>> Debugger entered--Lisp error: (quit)
>>    semantic-c-lexer(67 70 1 nil)
>>    semantic-lex(67 70 1 nil)
>>    #[(vals start end) " @@ @A\306\307\211     \310\311
>> \f\n\206 \312$ \"A\242-\207" [vals length depth nonterm end start
>>
>> type-cast-list nil semantic-parse-stream semantic-lex 1] 6](((67 . 70))
>> 67 70)
>>    semantic-parse-stream-default(((INT 45 . 48) (symbol 49 . 50)
>> (punctuation 51 . 52) (semantic-list 53 . 56) (punctuation 56 . 57)
>> (semantic-list 60 . 63) (punctuation 63 . 64) (semantic-list 67 . 70)
>> (punctuation 70 . 71) (semantic-list 74 . 77) (punctuation 77 . 78)) nil)
>>    semantic-parse-stream(((INT 45 . 48) (symbol 49 . 50) (punctuation 51
>> . 52) (semantic-list 53 . 56) (punctuation 56 . 57) (semantic-list 60 .
>> 63) (punctuation 63 . 64) (semantic-list 67 . 70) (punctuation 70 . 71)
>> (semantic-list 74 . 77) (punctuation 77 . 78)) nil)
>>    semantic-repeat-parse-whole-stream(((INT 1 . 4) (symbol 5 . 6)
>> (punctuation 7 . 8) (number 9 . 10) (punctuation 10 . 11) (INT 12 . 15)
>> (symbol 16 . 17) (punctuation 18 . 19) (number 20 . 21) (punctuation 21
>> . 22) (INT 23 . 26) (symbol 27 . 28) (punctuation 29 . 30) (number 31 .
>> 32) (punctuation 32 . 33) (INT 34 . 37) (symbol 38 . 39) (punctuation 40
>> . 41) (number 42 . 43) (punctuation 43 . 44) (INT 45 . 48) (symbol 49 .
>> 50) (punctuation 51 . 52) (semantic-list 53 . 56) (punctuation 56 . 57)
>> (semantic-list 60 . 63) (punctuation 63 . 64) (semantic-list 67 . 70)
>> (punctuation 70 . 71) (semantic-list 74 . 77) (punctuation 77 . 78)) nil
>> nil)
>>    semantic-parse-region-default(1 79 nil nil nil)
>>    semantic-parse-region-c-mode(1 79 nil nil nil)
>>    semantic-parse-region(1 79)
>>    semantic-fetch-tags()
>>    semantic-force-refresh()
>>
>> Which doesn't tell me much without digging into the internals of
>> semantic. ​Any help in debugging this ​would be appreciated!
>>
>> Best regards
>> Bastian
>>
>> --
>> Bastian Beischer
>> RWTH Aachen University of Technology
>>
>> @RWTH Aachen
>> Office: 28 C 203
>> Phone: +49-241-80-27205
>> E-mail: [email protected]
>> <mailto:[email protected]>
>> Address: I. Physikalisches Institut B, Sommerfeldstr. 14, D-52074 Aachen
>>
>> @CERN
>> Office: Bdg 32-4-B12
>> Phone: +41-22-76-75750
>> E-mail: [email protected] <mailto:[email protected]>
>> Address: CERN, CH-1211 Geneve 23
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Site24x7 APM Insight: Get Deep Visibility into Application Performance
>> APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
>> Monitor end-to-end web transactions and take corrective actions now
>> Troubleshoot faster and improve end-user experience. Signup Now!
>> http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
>>
>>
>>
>> _______________________________________________
>> cedet-semantic mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/cedet-semantic
>>
>>


-- 
Bastian Beischer
RWTH Aachen University of Technology

@RWTH Aachen
Office: 28 C 203
Phone: +49-241-80-27205
E-mail: [email protected]
Address: I. Physikalisches Institut B, Sommerfeldstr. 14, D-52074 Aachen

@CERN
Office: Bdg 32-4-B12
Phone: +41-22-76-75750
E-mail: [email protected]
Address: CERN, CH-1211 Geneve 23

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140

_______________________________________________
cedet-semantic mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cedet-semantic