Re: Small grammar, long compilation time

Larry Evans <[email protected]>
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
On 10/26/2017 09:03 AM, Søren Enevoldsen wrote:
> The following program takes about 10s to compile. However, the rule 
> currently used in parenProcess, 'nullProcess' should actually be 
> 'process'. However, when I make the change, compilation does not finish. 
> Instead CPU keeps spinning hot, and memory usage gradually increases. 
> Since it is a rather small grammar, I am guessing I am doing something 
> wrong. How do I make the grammar work then I correct it by changing 
> parenProcess to '(' > process > ')' ?  (Note I cannot reduce the number 
> of rules between process and parenProcess for a smaller example, since 
> then the compile time immediately decreases).
> 
> - Søren
> 
> ====================================================================
> 
> #include <boost/config/warning_disable.hpp>
> #include <boost/spirit/home/x3.hpp>
> #include <boost/spirit/home/x3/support/ast/variant.hpp>
> #include <boost/spirit/include/qi_char_class.hpp>
> #include <boost/fusion/include/adapt_struct.hpp>
[snip]
> x3::rule<struct processRule, AstAnyProcess> process{"process"};
> 
> ///  Here be compile time dragons.
> auto const parenProcess = '(' > nullProcess > ')';
> 
> auto const primitive = rule<AstAnyProcess>("primitive")
>      = parenProcess
>      | nullProcess
>      | constant;
[snip]
With this "convenience" change:

#define USE_PROCESS_IN_PAREN
auto const parenProcess
   = '('
#ifdef USE_PROCESS_IN_PAREN
   ///  Here be compile time dragons.
   > process
#else
   > nullProcess
#endif
   > ')'
   ;

and when compiled, it did take more than 10s (way more)
and I did see my memory use go up and 100% of some of
my cpu's.  However, when the get_rhs branch of a spirit
fork here:

https://github.com/cppljevans/spirit/tree/get_rhs

was -I included in front of the standard boost,
it compiled in a flash.

This problem has been reported before; however, I've
been advised that it needs more documentation before
submitting it as a pull request.  I'm working slowly
on that.

HTH.

-regards,
Larry



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.