Skip Menu |
Report information
Id: 131134
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: eigil [at] skjaeve.land
Cc:
AdminCc:

Severity: (no value)
Tag: Bug
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Date: Tue, 11 Apr 2017 14:35:23 +0200
From: Eigil Skjæveland <eigil [...] skjaeve.land>
Subject: [BUG] Native array[int] accepts junction with negative index
To: rakudobug [...] perl.org
Download (untitled) / with headers
text/plain 452b
Show quoted text
> my Int @a = 1, 2; > my int @b = 1, 2; > say so @a[-1 ^ 0];
True Show quoted text
> say so @b[-1 ^ 0];
False Show quoted text
> say @a[-1 ^ 0];
Index out of range. Is: -1, should be in 0..^Inf in block <unit> at <unknown file> line 1 Show quoted text
> say @b[-1 ^ 0];
one(2, 1) It seems the native int array treats negative indices in a junction as relative to the end of the array. This is Rakudo version 2017.01-58-gd06d7c16b built on MoarVM version 2017.01-13-g4aab5064 implementing Perl 6.c.
Subject: Re: [perl #131134] [BUG] Native array[int] accepts junction with negative index
From: Elizabeth Mattijsen <liz [...] dijkmat.nl>
To: perl6-compiler [...] perl.org
Date: Fri, 14 Apr 2017 10:26:40 +0200
Download (untitled) / with headers
text/plain 882b
Show quoted text
> On 11 Apr 2017, at 14:44, Eigil Skjæveland (via RT) <perl6-bugs-followup@perl.org> wrote: > > # New Ticket Created by Eigil Skjæveland > # Please include the string: [perl #131134] > # in the subject line of all future correspondence about this issue. > # <URL: https://rt.perl.org/Ticket/Display.html?id=131134 > > >
>> my Int @a = 1, 2; >> my int @b = 1, 2; >> say so @a[-1 ^ 0];
> True
>> say so @b[-1 ^ 0];
> False
>> say @a[-1 ^ 0];
> Index out of range. Is: -1, should be in 0..^Inf > in block <unit> at <unknown file> line 1 >
>> say @b[-1 ^ 0];
> one(2, 1) > > It seems the native int array treats negative indices in a junction as > relative to the end of the array.
Any expression resulting in a negative value at runtime, exposes this behaviour: $ 6 'my int @a = ^10; my $a = 0; dd @a[$a-1]’ 9 At the moment, this happens because the AT-POS candidate
Date: Fri, 14 Apr 2017 10:29:44 +0200
From: Elizabeth Mattijsen <liz [...] dijkmat.nl>
Subject: Re: [perl #131134] [BUG] Native array[int] accepts junction with negative index
To: "Eigil Skjæveland (via RT)" <perl6-bugs-followup [...] perl.org>
Download (untitled) / with headers
text/plain 1.1k
Show quoted text
> On 11 Apr 2017, at 14:44, Eigil Skjæveland (via RT) <perl6-bugs-followup@perl.org> wrote: > > # New Ticket Created by Eigil Skjæveland > # Please include the string: [perl #131134] > # in the subject line of all future correspondence about this issue. > # <URL: https://rt.perl.org/Ticket/Display.html?id=131134 > > >
>> my Int @a = 1, 2; >> my int @b = 1, 2; >> say so @a[-1 ^ 0];
> True
>> say so @b[-1 ^ 0];
> False
>> say @a[-1 ^ 0];
> Index out of range. Is: -1, should be in 0..^Inf > in block <unit> at <unknown file> line 1 >
>> say @b[-1 ^ 0];
> one(2, 1) > > It seems the native int array treats negative indices in a junction as > relative to the end of the array.
Any expression resulting in a negative value at runtime, exposes this behaviour: $ 6 'my int @a = ^10; my $a = 0; dd @a[$a-1]’ 9 At the moment, this happens because the AT-POS candidate directly uses nqp::atposref_i for performance reasons. Exactly for that reason, I don’t think we should fix this at the Perl 6 level, because we would lose a *lot* of performance if we did. So, *if* we consider this to be a bug (and personally, I think it is), the index checking should happen at the VM level, rather than at the Perl 6 level.
Date: Fri, 14 Apr 2017 13:58:20 +0200
From: Elizabeth Mattijsen <liz [...] dijkmat.nl>
Subject: Re: [perl #131134] [BUG] Native array[int] accepts junction with negative index
To: "Eigil Skjæveland (via RT)" <perl6-bugs-followup [...] perl.org>
Download (untitled) / with headers
text/plain 1.2k
Show quoted text
> On 14 Apr 2017, at 10:29, Elizabeth Mattijsen <liz@dijkmat.nl> wrote:
>> On 11 Apr 2017, at 14:44, Eigil Skjæveland (via RT) <perl6-bugs-followup@perl.org> wrote: >> >> # New Ticket Created by Eigil Skjæveland >> # Please include the string: [perl #131134] >> # in the subject line of all future correspondence about this issue. >> # <URL: https://rt.perl.org/Ticket/Display.html?id=131134 > >> >>
>>> my Int @a = 1, 2; >>> my int @b = 1, 2; >>> say so @a[-1 ^ 0];
>> True
>>> say so @b[-1 ^ 0];
>> False
>>> say @a[-1 ^ 0];
>> Index out of range. Is: -1, should be in 0..^Inf >> in block <unit> at <unknown file> line 1 >>
>>> say @b[-1 ^ 0];
>> one(2, 1) >> >> It seems the native int array treats negative indices in a junction as >> relative to the end of the array.
> > Any expression resulting in a negative value at runtime, exposes this behaviour: > > $ 6 'my int @a = ^10; my $a = 0; dd @a[$a-1]’ > 9 > > At the moment, this happens because the AT-POS candidate directly uses nqp::atposref_i for performance reasons. > > Exactly for that reason, I don’t think we should fix this at the Perl 6 level, because we would lose a *lot* of performance if we did.
Hmmm… the loss in performance appears to be in the 10% range, so maybe not as bad as I anticipated. Liz


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org