On Sat Aug 25 14:47:26 2012, sprout wrote: > On Sat Aug 25 14:47:01 2012, sprout wrote: > > On Sat Aug 25 08:39:29 2012, demerphq wrote: > > > On 25 August 2012 16:03, Father Chrysostomos via RT > > > <perlbug-followup@perl.org> wrote: > > > > On Sat Aug 25 02:08:34 2012, demerphq wrote: > > > >> On 25 August 2012 09:31, Father Chrysostomos via RT > > > >> <perlbug-followup@perl.org> wrote: > > > >> > ‘if’ and ‘unless’ are implemented in terms of && and ||, so the > > > >> > optimisation applies to those, too, unless they are called in non- > > > >> void > > > >> > context (or context that cannot be discerned at compile time, such > > > >> as > > > >> > the last statement of a subroutine). > > > >> > > > > >> > The examples above will show that if(%hash) is faster than keys, if > > > >> an > > > >> > extra ‘return’ is added after the if block. > > > >> > > > >> Rereading this I wonder about something, doesn't this indicate a > > > >> problem propagating context? > > > >> > > > >> The sub is called in in void context. Shouldn't that propagate to the > > > >> if()? > > > >> > > > >> Why does the user have to stick a raw return in? > > > >> > > > >> Are there technical reasons why in this case we cant check the > context > > > >> the sub is called in? > > > > > > > > The boolkeys optimisation happens at compile time. Am I missing > > > > something obvious? > > > > > > Well there were cases where you said we couldn't do boolkeys because > > > it wasn't in void context because of the missing return. > > > > > > My point was if we could determine if we were called in void context > > > then we could still do the boolkeys optimization. > > > > > > Or is it me that is missing something obvious? > > > > Thank you for persisting, because you have made me realising I was > > concentrating too much on boolkeys and missing the forest for the trees. > > This is what I was going to write: > > > > In > > > > sub { > > if (%hash) { } > > } > > ->(); > > > > the void context cannot be detected until run time, at which point it is > > too late to add an boolkeys op to the op tree. > > > > But then I realised that %hash itself should be detecting void context, > > in which case in %hash || $foo, where it is flagged as scalar context at > > compile time, it would also have to be flagged if the || is in void > > context, so it will know to call block_gimme() to find out whether it > > can act as a ‘true boolean’. > > > > See commit 6ea72b3a1069e. > > > > Now I’m wondering whether we even need the boolkeys op. I’m disabled it with commit c8fe3bdf72b0df and moved the optimisation into pp_rv2av/pp_padhv. I did not remove the boolkeys op type. Can op types be removed, or does that cause problems elsewhere? -- Father ChrysostomosThread Next