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

.[] doesn't cache a Seq #2383

Closed
zoffixznet opened this issue Oct 17, 2018 · 2 comments
Closed

.[] doesn't cache a Seq #2383

zoffixznet opened this issue Oct 17, 2018 · 2 comments
Labels
consistency tests needed Issue is generally resolved but tests were not written yet

Comments

@zoffixznet
Copy link
Contributor

Positional access on a Seq caches it. However, there's an edgecase where .[] doesn't cache it.

On List, .[] is a no-op and doesn't reify the List. I feel that the latter part can still apply to Seqs, but .[] should .cache, same as all other positional access would.

$ perl6 -e 'Nil for my $s := "abc".comb[*]; say $s'
(a b c)

$ perl6 -e 'Nil for my $s := "abc".comb[]; say $s'
The iterator of this Seq is already in use/consumed by another Seq
(you might solve this by adding .cache on usages of the Seq, or
by assigning the Seq into an array)
  in block <unit> at -e line 1

$ perl6 -v
This is Rakudo version 2018.06-146-g1b3dd35 built on MoarVM version 2018.06-141-gcae4731
implementing Perl 6.c.
zoffixznet added a commit that referenced this issue Oct 19, 2018
Make .[] cache the Seq. Closes #2383
@zoffixznet zoffixznet reopened this Oct 19, 2018
@zoffixznet zoffixznet added the tests needed Issue is generally resolved but tests were not written yet label Oct 19, 2018
@FCO FCO closed this as completed Oct 19, 2018
@zoffixznet
Copy link
Contributor Author

Tests went in in Raku/roast@7d23fbc

zoffixznet added a commit to Raku/doc that referenced this issue Oct 19, 2018
zoffixznet added a commit that referenced this issue Oct 26, 2018
This reverts commit 1954121.

This attempt at fixing an inconsistency introes another inconsistency
in that `[]` caches but `<>` doesn't and both and especially the
latter are likely used as a "decont operator"
zoffixznet added a commit to Raku/doc that referenced this issue Oct 26, 2018
The caching behaviour (R#2383[^1]) was reverted[^2][^3] and
non-caching behaviour propspeced[^4]

[1] rakudo/rakudo#2383
[2] rakudo/rakudo@2efffc2b43
[3] Raku/roast@5485affa47
[4] Raku/roast@f5f9ce0083
@zoffixznet
Copy link
Contributor Author

Turns out fixing this Issue introduced a different inconsistency: [] caches, but <> doesn't. Since <> (and possibly [] too) are a common way to perform a decont operation and accidentally cached Seqs might be a hard memory-leak bugs to detect, I decided to revert the fix for this Issue and to spec that ZEN slicing does NOT cache Seqs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consistency tests needed Issue is generally resolved but tests were not written yet
Projects
None yet
Development

No branches or pull requests

2 participants