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

Comments

Projects
None yet
2 participants
@zoffixznet
Copy link
Contributor

zoffixznet commented Oct 17, 2018

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

Merge pull request #2393 from FCO/master
Make .[] cache the Seq. Closes #2383

@zoffixznet zoffixznet reopened this Oct 19, 2018

@FCO FCO closed this Oct 19, 2018

@zoffixznet

This comment has been minimized.

Copy link
Contributor Author

zoffixznet commented Oct 19, 2018

Tests went in in perl6/roast@7d23fbc

zoffixznet added a commit to perl6/doc that referenced this issue Oct 19, 2018

zoffixznet added a commit that referenced this issue Oct 26, 2018

Revert "Make .[] cache the Seq. Closes #2383"
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 perl6/doc that referenced this issue Oct 26, 2018

Fix up ZEN slicing on Seqs
The caching behaviour (R#2383[^1]) was reverted[^2][^3] and
non-caching behaviour propspeced[^4]

[1] rakudo/rakudo#2383
[2] rakudo/rakudo@2efffc2
[3] perl6/roast@5485aff
[4] perl6/roast@f5f9ce0
@zoffixznet

This comment has been minimized.

Copy link
Contributor Author

zoffixznet commented Oct 26, 2018

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
You can’t perform that action at this time.