[Spirit2X] Terminals -- mixing actors and immediates?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[Spirit2X] Terminals -- mixing actors and immediates?

Francois Barel
I started using Spirit2X and the fact that terminal arguments can
easily be actors (lazy terminals) is really neat :)

The only criticism I have is that for multiple-argument terminals, you
either have to use all immediates (giving a non-lazy terminal) or all
actors (giving a lazy terminal). IOW, you can do
    repeat(4, inf)[ eps ]
or
    repeat(_r1, val(inf))[ eps ]
but unfortunately not
    repeat(_r1, inf)[ eps ]

It's not that big a deal, but isn't there a way this could be done?
(Just an idea, totally untested) In terminal operator() overloads:
- couldn't they be made along the lines of (1 operator() per arity):
    template< typename A0 >
    ... operator()(A0 const& _0) const
      { return ...(as_actor<...>::convert(_0)); }
    template< typename A0, typename A1 >
    ... operator()(A0 const& _0, A0 const& _1) const
      { return ...(as_actor<...>::convert(_0), as_actor<...>::convert(_1)); }
thereby always converting immediates to actors if needed (as if the
user had used phoenix::val(...)) -- if I'm not mistaken going thru
as_actor won't do anything to args which are already actors,
- with a special case (1 additional operator() per arity) if all
arguments are immediate (i.e. no Phoenix actor at all), in which case
a non-lazy terminal is returned (no going thru as_actor in that case)
<== not sure how to do that... some enable_if/disable_if machinery
directly on operator() overloads can probably do it? or by always
passing the result thru a meta-function which discards the laziness if
all arguments match actor< value< ... > >?

That way:
- as long as at least one arg is a Phoenix actor you would get a lazy
terminal (with all immediate args behaving as if they had been wrapped
in phoenix::val(...)),
- otherwise you'll get the non-lazy terminal you'd expect.
What do you think?

Thanks,
François

------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Spirit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-devel
Reply | Threaded
Open this post in threaded view
|

Re: [Spirit2X] Terminals -- mixing actors and immediates?

Joel de Guzman-2
Francois Barel wrote:

> I started using Spirit2X and the fact that terminal arguments can
> easily be actors (lazy terminals) is really neat :)
>
> The only criticism I have is that for multiple-argument terminals, you
> either have to use all immediates (giving a non-lazy terminal) or all
> actors (giving a lazy terminal). IOW, you can do
>     repeat(4, inf)[ eps ]
> or
>     repeat(_r1, val(inf))[ eps ]
> but unfortunately not
>     repeat(_r1, inf)[ eps ]

Right.

> It's not that big a deal, but isn't there a way this could be done?
> (Just an idea, totally untested) In terminal operator() overloads:
> - couldn't they be made along the lines of (1 operator() per arity):
>     template< typename A0 >
>     ... operator()(A0 const& _0) const
>       { return ...(as_actor<...>::convert(_0)); }
>     template< typename A0, typename A1 >
>     ... operator()(A0 const& _0, A0 const& _1) const
>       { return ...(as_actor<...>::convert(_0), as_actor<...>::convert(_1)); }
> thereby always converting immediates to actors if needed (as if the
> user had used phoenix::val(...)) -- if I'm not mistaken going thru
> as_actor won't do anything to args which are already actors,
> - with a special case (1 additional operator() per arity) if all
> arguments are immediate (i.e. no Phoenix actor at all), in which case
> a non-lazy terminal is returned (no going thru as_actor in that case)
> <== not sure how to do that... some enable_if/disable_if machinery
> directly on operator() overloads can probably do it? or by always
> passing the result thru a meta-function which discards the laziness if
> all arguments match actor< value< ... > >?
>
> That way:
> - as long as at least one arg is a Phoenix actor you would get a lazy
> terminal (with all immediate args behaving as if they had been wrapped
> in phoenix::val(...)),
> - otherwise you'll get the non-lazy terminal you'd expect.
> What do you think?

I thought about this too. It can be done. My only concern is compile
time. As you know, one of my goals with 2X is to reduce compile time.
If that means sacrificing some of the bells, well, it's a judgement
call. If you want to give it a hack, be my guest. If we find the
impact negligible, then it is definitely a welcome addition.

Regards,
--
Joel de Guzman
http://www.boostpro.com
http://spirit.sf.net


------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Spirit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-devel
Reply | Threaded
Open this post in threaded view
|

Re: [Spirit2X] Terminals -- mixing actors and immediates?

Francois Barel
Joel de Guzman wrote:
>
> I thought about this too. It can be done. My only concern is compile
> time. As you know, one of my goals with 2X is to reduce compile time.
> If that means sacrificing some of the bells, well, it's a judgement
> call. If you want to give it a hack, be my guest. If we find the
> impact negligible, then it is definitely a welcome addition.
>

Yes, that's what I was afraid of... I'll see what I can do over the
week-end, and let you know.

Regards,
François

------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Spirit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-devel
Reply | Threaded
Open this post in threaded view
|

Re: [Spirit2X] Terminals -- mixing actors and immediates?

Francois Barel
In reply to this post by Joel de Guzman-2
Joel de Guzman wrote:
>
> I thought about this too. It can be done. My only concern is compile
> time. As you know, one of my goals with 2X is to reduce compile time.
> If that means sacrificing some of the bells, well, it's a judgement
> call. If you want to give it a hack, be my guest. If we find the
> impact negligible, then it is definitely a welcome addition.
>

Attached is a small patch, the missing typedef prevented 3-arg lazy
terminals from being used.

Thanks,
François

------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Spirit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-devel

lazy_terminal_3.patch (606 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [Spirit2X] Terminals -- mixing actors and immediates?

Francois Barel
Francois Barel wrote:

> Joel de Guzman wrote:
>>
>> I thought about this too. It can be done. My only concern is compile
>> time. As you know, one of my goals with 2X is to reduce compile time.
>> If that means sacrificing some of the bells, well, it's a judgement
>> call. If you want to give it a hack, be my guest. If we find the
>> impact negligible, then it is definitely a welcome addition.
>>
>
> Attached is a small patch, the missing typedef prevented 3-arg lazy
> terminals from being used.
>
Attached is a patch for support/terminals.hpp (it applies after
lazy_terminal_3.patch included in my previous message). When a
terminal's operator() is used:
- if all args are immediates, the "simple" version of operator() is
used, returning a non-lazy terminal (terminal_ex),
- if any arg is a Phoenix actor, the "lazy" version of operator() is
used, returning a lazy terminal (lazy_terminal),
thanks to enable_if/disable_if on operator() return types.

Note that terminal::result now returns the actual return type of
operator(), which it didn't before -- it always returned the non-lazy
return type (terminal_ex), even when all its args were actors.


I benchmarked compile times (of the attached test.cpp file) between
svn Spirit2X ("before") and the patched version ("after") with the
following variants:
- non-lazy only (i.e. the most common use case, to benchmark how much
this patch slows it down) -- compiled with -DNONLAZYONLY,
- non-lazy + all-lazy (i.e. the cases supported by current Spirit2X)
-- compiled with -DNOCHECKTYPE (because terminal::result was wrong
before in the lazy case, so its type is not checked during
compilation),
- non-lazy + all-lazy + mixed (i.e. the new use case supported by this
patch) -- compiled with -DNEW.
Tests were run on VC9 RTM (Windows) and GCC 4.1.2 (Linux) with no
special flags (i.e. generation of debug info and no optimization,
since that's what matters most during development). Benchmarks were
run 8 times, I'm reporting the averages here.


non-lazy
********
gcc: before: 16.004s, after: 16.022s (delta: 0.11%)
vc9: before: 19.944s, after: 20.063s (delta: 0.56%)

non-lazy + all-lazy
*******************
gcc: before: 30.381s, after: 30.419s (delta: 0.12%)
vc9: before: 37.949s, after: 38.156s (delta: 0.55%)

So hopefully deltas of less than 1% for the current use cases will be
acceptable :p
And FYI (no "before" here since this use case isn't supported without
the patch):

mixed
*****
gcc: after: 77.941s
vc9: after: 84.435s


Note that contains_actor should have been implemented with mpl::or_,
but is implemented "by hand" with || instead to gain a little speed
(deltas were almost two times larger when using mpl::or_).
It also feels somewhat out-of-place in terminals.hpp, but I wasn't
sure where else to put it...

Regards,
François

------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Spirit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-devel

Spirit2x_mixed.patch (9K) Download Attachment
test.cpp (14K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [Spirit2X] Terminals -- mixing actors and immediates?

Joel de Guzman-2
Francois Barel wrote:

> Francois Barel wrote:
>> Joel de Guzman wrote:
>>> I thought about this too. It can be done. My only concern is compile
>>> time. As you know, one of my goals with 2X is to reduce compile time.
>>> If that means sacrificing some of the bells, well, it's a judgement
>>> call. If you want to give it a hack, be my guest. If we find the
>>> impact negligible, then it is definitely a welcome addition.
>>>
>> Attached is a small patch, the missing typedef prevented 3-arg lazy
>> terminals from being used.
>>
[...]
>
> So hopefully deltas of less than 1% for the current use cases will be
> acceptable :p
> And FYI (no "before" here since this use case isn't supported without
> the patch):

Great! Feel free to commit the patch. Do you have write access yet?
If not, I'll give you one if you email me your SF ID.

Best,
--
Joel de Guzman
http://www.boostpro.com
http://spirit.sf.net


------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Spirit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-devel