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

Whatever on the left side of array subscript range may cause hangs (@a[*-2..*]:exists) #5880

Open
p6rt opened this issue Dec 12, 2016 · 6 comments

Comments

@p6rt
Copy link

p6rt commented Dec 12, 2016

Migrated from rt.perl.org#130330 (status was 'open')

Searchable as RT130330$

@p6rt
Copy link
Author

p6rt commented Dec 12, 2016

From @AlexDaniel

To understand the issue, let's take a look at examples that *do* work.

Code​:
my @​a = <a b c d e>; say @​a[2..*]

Result​:
(c d e)

Code​:
my @​a = <a b c d e>; say @​a[2..*]​:exists

Result​:
(True True True)

Code​:
my @​a = <a b c d e>; say @​a[*-2..*]

Result​:
(d e)

Alright? Now with “​:exists”​:

Code​:
my @​a = <a b c d e>; say @​a[*-2..*]​:exists

Result​:
(hangs forever, *-2..* is being reified)

@p6rt
Copy link
Author

p6rt commented Dec 13, 2016

From @zoffixznet

On Mon, 12 Dec 2016 11​:25​:01 -0800, alex.jakimenko@​gmail.com wrote​:

To understand the issue, let's take a look at examples that *do* work.

Code​:
my @​a = <a b c d e>; say @​a[2..*]

Result​:
(c d e)

Code​:
my @​a = <a b c d e>; say @​a[2..*]​:exists

Result​:
(True True True)

Code​:
my @​a = <a b c d e>; say @​a[*-2..*]

Result​:
(d e)

Alright? Now with “​:exists”​:

Code​:
my @​a = <a b c d e>; say @​a[*-2..*]​:exists

Result​:
(hangs forever, *-2..* is being reified)

Here are some comments from jnthn​: https://irclog.perlgeek.de/perl6/2016-12-12#i_13729493

FWIW, I'm not seeing a problem. You've contorted a piece of code into trying to reify an infinite number of elements...

@p6rt
Copy link
Author

p6rt commented Dec 13, 2016

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Dec 13, 2016

From @AlexDaniel

Sooo… Are you saying that the behavior in provided examples is consistent?

On 2016-12-13 09​:25​:36, cpan@​zoffix.com wrote​:

On Mon, 12 Dec 2016 11​:25​:01 -0800, alex.jakimenko@​gmail.com wrote​:

To understand the issue, let's take a look at examples that *do*
work.

Code​:
my @​a = <a b c d e>; say @​a[2..*]

Result​:
(c d e)

Code​:
my @​a = <a b c d e>; say @​a[2..*]​:exists

Result​:
(True True True)

Code​:
my @​a = <a b c d e>; say @​a[*-2..*]

Result​:
(d e)

Alright? Now with “​:exists”​:

Code​:
my @​a = <a b c d e>; say @​a[*-2..*]​:exists

Result​:
(hangs forever, *-2..* is being reified)

Here are some comments from jnthn​:
https://irclog.perlgeek.de/perl6/2016-12-12#i_13729493

FWIW, I'm not seeing a problem. You've contorted a piece of code into
trying to reify an infinite number of elements...

@p6rt
Copy link
Author

p6rt commented Dec 14, 2016

From @zoffixznet

On Tue, 13 Dec 2016 11​:10​:38 -0800, alex.jakimenko@​gmail.com wrote​:

Sooo… Are you saying that the behavior in provided examples is consistent?

As far as I can see, yes. The first two are lazy Ranges. The second two are non-lazy WhateverCodes. And as jnthn++ pointed out "The array subscripter decides whether to auto-viv for not based on .is-lazy".

The reason it does so is so things like `my @​a; @​a[3..5] = 1 xx *; say @​a` autovivicate, while still letting you do stuff like `@​a[2..*]` to get a truncated result.

In the example you point out as problematic, you're exploiting the autovivication feature to create an infinite loop, hence the hang.

Is there still an issue on this ticket not covered by those explanations?

@p6rt
Copy link
Author

p6rt commented Dec 14, 2016

From @AlexDaniel

Yes. Why the behavior with and without :exists is different? Why does it have to be different?

On 2016-12-14 08​:02​:48, cpan@​zoffix.com wrote​:

On Tue, 13 Dec 2016 11​:10​:38 -0800, alex.jakimenko@​gmail.com wrote​:

Sooo… Are you saying that the behavior in provided examples is
consistent?

As far as I can see, yes. The first two are lazy Ranges. The second
two are non-lazy WhateverCodes. And as jnthn++ pointed out "The array
subscripter decides whether to auto-viv for not based on .is-lazy".

The reason it does so is so things like `my @​a; @​a[3..5] = 1 xx *; say
@​a` autovivicate, while still letting you do stuff like `@​a[2..*]` to
get a truncated result.

In the example you point out as problematic, you're exploiting the
autovivication feature to create an infinite loop, hence the hang.

Is there still an issue on this ticket not covered by those
explanations?

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

No branches or pull requests

1 participant