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

Shaped arrays can't have zero size #6469

Open
p6rt opened this issue Aug 26, 2017 · 9 comments
Open

Shaped arrays can't have zero size #6469

p6rt opened this issue Aug 26, 2017 · 9 comments

Comments

@p6rt
Copy link

p6rt commented Aug 26, 2017

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

Searchable as RT131965$

@p6rt
Copy link
Author

p6rt commented Aug 26, 2017

From @dwarring

This is OK​:

% perl6 -e'my $size = 2; my @​xref[$size,3] = ([1,2,3], [4,5,6]); say @​xref'

[[1 2 3] [4 5 6]]

But this isn't​:

% perl6 -e'my $size = 0; my @​xref[$size,3] = (); say @​xref'

Illegal dimension in shape​: 0. All dimensions must be integers bigger than
0
in block <unit> at -e line 1

% perl6 -v
This is Rakudo version 2017.08 built on MoarVM version 2017.08.1
implementing Perl 6.c.

Just seems an unreasonable restriction that the major shape size of an
array can't be zero.

@p6rt
Copy link
Author

p6rt commented Aug 27, 2017

From @AlexDaniel

Indeed. The limit was introduced as a response to this ticket​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=126800
The check is probably too aggressive, and indeed, maybe there's nothing wrong with 0 sized arrays. I wonder what was the justification for making the check inclusive.
On 2017-08-26 16​:15​:33, david.warring wrote​:

This is OK​:

% perl6 -e'my $size = 2; my @​xref[$size,3] = ([1,2,3], [4,5,6]); say @​xref'

[[1 2 3] [4 5 6]]

But this isn't​:

% perl6 -e'my $size = 0; my @​xref[$size,3] = (); say @​xref'

Illegal dimension in shape​: 0. All dimensions must be integers bigger than
0
in block <unit> at -e line 1

% perl6 -v
This is Rakudo version 2017.08 built on MoarVM version 2017.08.1
implementing Perl 6.c.

Just seems an unreasonable restriction that the major shape size of an
array can't be zero.

@p6rt
Copy link
Author

p6rt commented Aug 27, 2017

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

@p6rt
Copy link
Author

p6rt commented Aug 27, 2017

From @geekosaur

How exactly do you index such an array?

On Sat, Aug 26, 2017 at 8​:11 PM, Aleks-Daniel Jakimenko-Aleksejev via RT <
perl6-bugs-followup@​perl.org> wrote​:

Indeed. The limit was introduced as a response to this ticket​:
https://rt-archive.perl.org/perl6/Ticket/Display.html?id=126800
The check is probably too aggressive, and indeed, maybe there's nothing
wrong
with 0 sized arrays. I wonder what was the justification for making the
check
inclusive.
On 2017-08-26 16​:15​:33, david.warring wrote​:

This is OK​:

% perl6 -e'my $size = 2; my @​xref[$size,3] = ([1,2,3], [4,5,6]); say
@​xref'

[[1 2 3] [4 5 6]]

But this isn't​:

% perl6 -e'my $size = 0; my @​xref[$size,3] = (); say @​xref'

Illegal dimension in shape​: 0. All dimensions must be integers bigger
than
0
in block <unit> at -e line 1

% perl6 -v
This is Rakudo version 2017.08 built on MoarVM version 2017.08.1
implementing Perl 6.c.

Just seems an unreasonable restriction that the major shape size of an
array can't be zero.

--
brandon s allbery kf8nh sine nomine associates
allbery.b@​gmail.com ballbery@​sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

@p6rt
Copy link
Author

p6rt commented Aug 27, 2017

From @AlexDaniel

Well, what do you mean? Of course you can't put anything into it, and any attempt to index it will throw. It may seem useless, however, if you can have an empty array, why can't you have a shaped empty array?
On 2017-08-26 17​:13​:02, allbery.b@​gmail.com wrote​:

How exactly do you index such an array?

On Sat, Aug 26, 2017 at 8​:11 PM, Aleks-Daniel Jakimenko-Aleksejev via RT <
perl6-bugs-followup@​perl.org> wrote​:

Indeed. The limit was introduced as a response to this ticket​:
https://rt-archive.perl.org/perl6/Ticket/Display.html?id=126800
The check is probably too aggressive, and indeed, maybe there's nothing
wrong
with 0 sized arrays. I wonder what was the justification for making the
check
inclusive.
On 2017-08-26 16​:15​:33, david.warring wrote​:

This is OK​:

% perl6 -e'my $size = 2; my @​xref[$size,3] = ([1,2,3], [4,5,6]); say
@​xref'

[[1 2 3] [4 5 6]]

But this isn't​:

% perl6 -e'my $size = 0; my @​xref[$size,3] = (); say @​xref'

Illegal dimension in shape​: 0. All dimensions must be integers bigger
than
0
in block <unit> at -e line 1

% perl6 -v
This is Rakudo version 2017.08 built on MoarVM version 2017.08.1
implementing Perl 6.c.

Just seems an unreasonable restriction that the major shape size of an
array can't be zero.

@p6rt
Copy link
Author

p6rt commented Aug 27, 2017

From @geekosaur

Well, what do you mean? Of course you can't put anything into it, and any
attempt to index it will throw. It may seem useless, however, if you can
have
an empty array, why can't you have a shaped empty array?

Only if all dimensions are unindexable. Otherwise you have something with
inaccessible slots (and, potentially thereby, not truly leaked but
unusable, memory).

And an empty unshaped array, in addition to being usable as such
(degenerate case of all shaped dimensions being size 0), can be made
non-empty. Shaped arrays cannot.

@p6rt
Copy link
Author

p6rt commented Aug 28, 2017

From @dwarring

Attached is my use case which is parsing of PDF cross reference indices.
There are normally three numeric entries per line. e.g.

xref
0 8
0000000000 65535 f
0000000009 00000 n
0000000074 00000 n
0000000120 00000 n

Which populates nicely into an array of 'n' lines of shape 3.

There's the rare, but possible case of an xref section with zero entries

xref
0 0

(I've encountered real-world PDF's like this).

The attached grammar/actions attempted to handle it as an array of shape
[0;3],
but wont work on current Rakudo.

Just my preferred solution for the above case.
- David

On Sun, Aug 27, 2017 at 12​:38 PM, Brandon Allbery via RT <
perl6-bugs-followup@​perl.org> wrote​:

Well, what do you mean? Of course you can't put anything into it, and any
attempt to index it will throw. It may seem useless, however, if you can
have
an empty array, why can't you have a shaped empty array?

Only if all dimensions are unindexable. Otherwise you have something with
inaccessible slots (and, potentially thereby, not truly leaked but
unusable, memory).

And an empty unshaped array, in addition to being usable as such
(degenerate case of all shaped dimensions being size 0), can be made
non-empty. Shaped arrays cannot.

@p6rt
Copy link
Author

p6rt commented Aug 28, 2017

From @dwarring

Xref.pm

@dwarring
Copy link

dwarring commented Oct 7, 2020

LTA in some cases anyway:
$ raku -e'my uint8 @b[0;42]'
Results in:

Illegal dimension in shape: 0. All dimensions must be integers bigger than 0
  in block <unit> at -e line 1

But:
$ raku -e'my uint8 @b[0]'
Dies with:

MoarVM oops: MVM_fixed_size_alloc request for 0 bytes
   at SETTING::src/core.c/Rakudo/Internals.pm6:439  (/home/david/git/rakudo/install/share/perl6/runtime/CORE.c.setting.moarvm:SHAPED-ARRAY-STORAGE)
 from SETTING::src/core.c/native_array.pm6:3211  (/home/david/git/rakudo/install/share/perl6/runtime/CORE.c.setting.moarvm:shaped)
 from SETTING::src/core.c/native_array.pm6:21  (/home/david/git/rakudo/install/share/perl6/runtime/CORE.c.setting.moarvm:create-ws)
 from SETTING::src/core.c/native_array.pm6:11  (/home/david/git/rakudo/install/share/perl6/runtime/CORE.c.setting.moarvm:new)
 from SETTING::src/core.c/Mu.pm6:115  (/home/david/git/rakudo/install/share/perl6/runtime/CORE.c.setting.moarvm:new)
 from -e:1  (<ephemeral file>:<unit>)
 from -e:1  (<ephemeral file>:<unit-outer>)
 from gen/moar/stage2/NQPHLL.nqp:1945  (/home/david/git/rakudo/install/share/nqp/lib/NQPHLL.moarvm:eval)
 from gen/moar/stage2/NQPHLL.nqp:2055  (/home/david/git/rakudo/install/share/nqp/lib/NQPHLL.moarvm:)
 from gen/moar/stage2/NQPHLL.nqp:2054  (/home/david/git/rakudo/install/share/nqp/lib/NQPHLL.moarvm:command_eval)
 from gen/moar/Compiler.nqp:64  (/home/david/git/rakudo/install/share/perl6/lib/Perl6/Compiler.moarvm:command_eval)
 from gen/moar/stage2/NQPHLL.nqp:2035  (/home/david/git/rakudo/install/share/nqp/lib/NQPHLL.moarvm:command_line)
 from gen/moar/rakudo.nqp:127  (/home/david/git/rakudo/install/share/perl6/runtime/perl6.moarvm:MAIN)
 from gen/moar/rakudo.nqp:1  (/home/david/git/rakudo/install/share/perl6/runtime/perl6.moarvm:<mainline>)
 from <unknown>:1  (/home/david/git/rakudo/install/share/perl6/runtime/perl6.moarvm:<main>)
 from <unknown>:1  (/home/david/git/rakudo/install/share/perl6/runtime/perl6.moarvm:<entry>)

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

2 participants