Re: Horrible compiletimes and memory usage while compiling a parser with X3

Joel de Guzman <[email protected]>
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
On 06/11/2016 10:31 PM, Exagon wrote:
> I tired my best  HERE <https://github.com/bitwalda/Boost_Spirit_Compiletime>
> is my repo with the x3 parser wich will cause the problems.
> This example compiles up to an hour, uses a lot of memory and the resulting
> binarys are HUGE. Its the same in gcc and clang.
> I used clang 3.9.0-1 and gcc 6.2.1-1.
> My machine is an Thinkpad with a Intel(R) Core(TM) i5-5300U CPU @ 2.30GHz
> and 16gb ram.
>

Alright, I got it building, and indeed there seems to be too much recursion going
on here. I'll try to investigate if there's a workaround, from the library's
perspective, but one thing you can do now is to restructure your code into
smaller and more manageable chunks. If a template depth of 512 is not enough,
then you probably have to restructure your grammars.

See calc9 for example (in example/x3/calc). Notice the use of separate
compilation in cpp files.

Take particular note of expression_def.hpp, expression.cpp and expression.hpp.
This trio represents what I consider to be the best practice in how grammars
should be structured in X3. expression_def.hpp is where the grammar is defined
using BOOST_SPIRIT_DEFINE. expression.hpp is where it is declared: note
using BOOST_SPIRIT_DECLARE.

Note how the actual grammar is encapsulated. All users of expression, up
and down the parser hierarchy, sees only expression.hpp (never the actual
definitions). expression.hpp is very small and tight.

expression.cpp is where you actually instantiate an expression given your
iterator and context types (the config.hpp takes care of these application
specific types). Separate compilation also helps in keeping your build times
to a sane level. You build the definition only once.

The more modular you structure your grammars, the better.

Regards,
-- 
Joel de Guzman
http://www.ciere.com
http://boost-spirit.com
http://www.cycfi.com/


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
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.