Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 1268: Fix lazy slicing stopping at the first deleted #1299

Closed
wants to merge 4 commits into from

Conversation

jstuder-gh
Copy link
Contributor

This commit fixes the issue in which using lazy Iterables as Positional
indices will evaluate until the first deleted (undefined) value but not
continue further.

Within the default eagerize routine, it checks the number of reified
elements upon encountering an undefined value to determine whether to
continue.

Addresses Issue #1268

This commit fixes the issue in which using lazy Iterables as Positional
indices will evaluate until the first deleted (undefined) value but not
continue further.

Within the default eagerize routine, it checks the number of reified
elements upon encountering an undefined value to determine whether to
continue.

Addresses [Issue rakudo#1268](rakudo#1268)
@jstuder-gh
Copy link
Contributor Author

Will need to write tests if accepted.

@zoffixznet
Copy link
Contributor

Is there a way we can we do this without adding a public method?

I also don't understand how this fixes anything for Seqs, since reified part will often just contain whatever was already reified:

<Zoffix__> m: with [<a b c d e>] { .[0]:delete; with .Seq { use nqp; nqp::elems( nqp::getattr(.cache, List, '$!reified') ).say } }
<camelia> rakudo-moar 1dbf5f589: OUTPUT: «0␤»

And so, IMO this type of fix just muddles up the conditions where a hole would be stopped at. "Stops at first gap or end of Iterable" is easy to understand. But if you also have to care about the kind of iterable you, as a user, have you now have 4 different cases to consider instead of just 2.

IMO we should either fix this entirely or not fix it at all (and document behaviour as described in the Issue). Doing half-way measures doesn't improve usability or usefulness of the feature.

This addresses the issue of unreified but pending List and Seq elements
causing the check of reified elems to return a correct but misleading
amount the would cause eagerization to halt.

An example of such an issue is below:

    with [<a b c d e>] {
        .[0]:delete;
        with .Seq {
        use nqp;
        nqp::elems( nqp::getattr(.cache, List, '$!reified') ).say }
        }
    }

This would evaluate to 0 unless we were to explicitly reify before
taking the number of elems.

zoffixznet++ for pointing out this type of scenario.
@jstuder-gh
Copy link
Contributor Author

I added a commit that addresses the issue of pending, unreified elements on the List or Seq as showcased in your example by explicitly reifying until lazy if the Reifier indicates that there is more to do.

As for the public methods, I suppose we could encapsulate all of this logic within the eagerize block. I had just figured this was a bit cleaner. But if the number of reified elements is not something we want to be exposing to the user, I can get rid of them.

@zoffixznet
Copy link
Contributor

But if the number of reified elements is not something we want to be exposing to the user

No we shouldn't, especially not if calling the method causes, often complete, reification.


BTW is the Seq handling needed at all? Looking more at it now and it looks like the hole is filled when an Array is converted to Seq/List and this issue only exists with Arrays, since you can't :delete from Seqs/Lists directly:

<Zoffix__> m: my @a2 = 4, 5, 6; @a2[1]:delete; say @a2.Seq[lazy 0, 1, 2, 3, 4, 5, 6, 7]
<camelia> rakudo-moar 1dbf5f589: OUTPUT: «(4 (Any) 6)␤»

<Zoffix__> m: my @a2 = 4, 5, 6; @a2[1]:delete; say @a2.List[lazy 0, 1, 2, 3, 4, 5, 6, 7]
<camelia> rakudo-moar 1dbf5f589: OUTPUT: «(4 Nil 6)␤»

@jstuder-gh
Copy link
Contributor Author

No we shouldn't, especially not if calling the method causes, often complete, reification.

Good point. I'll remove the methods and incorporate the logic into the eagerizer in the next iteration. I'll also try removing the Seq handling as well.

Remove the public NUM-REIFIED methods so as not to expose them (and
their reification side-effects). Incorporated that logic into the
default eagerize block in POSITIONS.
@jstuder-gh
Copy link
Contributor Author

As discussed, I've removed the public methods and incorporated the logic into the default "eagerize" block for POSITIONS. It also passes the spectest.

Update lazy positions comment to reflect current behavior.
@zoffixznet
Copy link
Contributor

zoffixznet commented Dec 11, 2017

I don't see anyone else commenting, but I'm still against this sort of piece-meal fixes. All it's doing is making the behaviour hard to predict.

(the latest version of this PR assumes anything that isn't a Seq is a List, which I'm guessing will make this codepath explode for userland Positionals)

@jstuder-gh
Copy link
Contributor Author

I'm closing this PR as it's clear now that this was not the right path to take in order to fix this problem. There is still discussion at Issue 1268 about another approach. If that proves to be the right way forward, I will open another PR at a later date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants