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

Larry Evans <[email protected]>
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
On 11/07/2016 02:44 AM, Peter Gerell wrote:
 > On 07/11/2016 12:38 PM , Joel de Guzman wrote:
 >> On 07/11/2016 1:26 AM, Mikael Asplund wrote:
 >>> This is the reason we're still on 1.60 (with a small
 >>> const-patch from 1.61), since later version have link problems 
which are just too hard
 >>> to debug.
 >
 >> It would be great if you post a test file that exhibits this problem 
you mention.
 >> This linking problem doesn't look good and must be fixed.
 >
 > Hi Joel.
 > This is the problem Mikael is referring to.
 > http://melpon.org/wandbox/permlink/X8Awj4wIZ2JqMWIw
 >
 > If KEEP_CHAR is defined the code builds with both boost 1.60 and 1.61.
 > Without KEEP_CHAR it fails with 1.61.
 >
 > The following commit introduced the problem.
 > 
https://github.com/boostorg/spirit/commit/a8e391bd99dddb3f9ece84bdb1bb9236b0a37cf7
 >
 > The problem seems to be that the attribute types are short-circuited 
for sequences of one
 > even though we explicitly request a specific binding using 
FUSION_DEFINE_FOR_STRUCT(ast::Start, count);

Wow!  Very impressive bug detecting!

 > In this short example we could easily work around this issue by not 
omitting the result of the
 >  char_ parser in the start rule or by changing the attribute types to 
what boost 1.61+ expects
 > In our full code it is not as simple as we rely on the types being 
unique when traversing the
 > ast using variant visitors.

Could you work around this "types being unique" problem if the visitor 
dispatched on the which value instead of the type?  IOW, given the 
following variant:

   using variant_t=boost::variant< int, std::string >;

then, instead of:

   class times_two_visitor
       : public boost::static_visitor<>
   {
   public:

       void operator()(int & i) const
       {
           i *= 2;
       }

       void operator()(std::string & str) const
       {
           str += str;
       }

   };

a sort of "indexed" visitor is used:

   template< int I>
   using index=std::integral_constant<int,I>;

   class times_two_indexed_visitor
       : public boost::static_indexed_visitor<>
   {
   private:
       variant_t& v;
   public:
       times_two_indexed_visitor(variant_t& v):v(v){}

       void operator()(index<0>) const
       {
           get<0>(v) *= 2;
       }

       void operator()(index<1>) const
       {
           get<1>(v) += str;
       }

   };

Then it wouldn't matter if the types were duplicated.

If boost::variant does not have a get by index, it would be
easy, AFAICT, to add one.

Would that work?
 >
 > /Peter
 >



------------------------------------------------------------------------------
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.