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

.chop(9999999999999999999999999999999999999999999999999) does not chop #4474

Closed
p6rt opened this issue Aug 15, 2015 · 8 comments
Closed

.chop(9999999999999999999999999999999999999999999999999) does not chop #4474

p6rt opened this issue Aug 15, 2015 · 8 comments

Comments

@p6rt
Copy link

p6rt commented Aug 15, 2015

Migrated from rt.perl.org#125814 (status was 'resolved')

Searchable as RT125814$

@p6rt
Copy link
Author

p6rt commented Aug 15, 2015

From @AlexDaniel

Code​:
say 'xx'.chop(999999999999999999999999999999999999999999999999).perl;
say 'xx'.chop(9999999999999999999999999999999999999999999999999).perl;

Result​:
""
"xx"

@p6rt
Copy link
Author

p6rt commented Jun 19, 2016

From @zoffixznet

FWIW, the behaviour is different now​:

<Zoffix> m​: say 'xx'.chop(999999999999999999).perl;
<camelia> rakudo-moar 1d93ad​: OUTPUT«""␤»
<Zoffix> m​: say 'xx'.chop(9999999999999999999).perl;
<camelia> rakudo-moar 1d93ad​: OUTPUT«"xx"␤»
<Zoffix> m​: say 'xx'.chop(99999999999999999999).perl;
<camelia> rakudo-moar 1d93ad​: OUTPUT«Cannot unbox 67 bit wide bigint into native integer␤ in block <unit> at <tmp> line 1␤␤»

IMHO there's nothing to fix here and the ticket should be rejected. It's attempting to chop over an EXABYTE of data. c'mon :)

@p6rt
Copy link
Author

p6rt commented Jun 19, 2016

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

@p6rt
Copy link
Author

p6rt commented Jun 20, 2016

From @AlexDaniel

On Sun Jun 19 16​:52​:30 2016, cpan@​zoffix.com wrote​:

FWIW, the behaviour is different now​:

<Zoffix> m​: say 'xx'.chop(999999999999999999).perl;
<camelia> rakudo-moar 1d93ad​: OUTPUT«""␤»
<Zoffix> m​: say 'xx'.chop(9999999999999999999).perl;
<camelia> rakudo-moar 1d93ad​: OUTPUT«"xx"␤»
<Zoffix> m​: say 'xx'.chop(99999999999999999999).perl;
<camelia> rakudo-moar 1d93ad​: OUTPUT«Cannot unbox 67 bit wide bigint
into native integer␤ in block <unit> at <tmp> line 1␤␤»

IMHO there's nothing to fix here and the ticket should be rejected.
It's attempting to chop over an EXABYTE of data. c'mon :)

First of all, this ticket is not going anywhere without tests :)

Secondly, you have demonstrated that the erroneous behavior is still there. I may change the title to fit current status, but that's not a big deal. The problem is that with huge numbers the behavior is blatantly wrong.

I hope you are not trying to say that 「say 'xx'.chop(9999999999999999999).perl;」 should print "xx". It doesn't really matter if the number is very high, it should not print nonsense in any case.

@p6rt
Copy link
Author

p6rt commented Jul 8, 2016

From @zoffixznet

I hope you are not trying to say that 「say
'xx'.chop(9999999999999999999).perl;」 should print "xx". It doesn't
really matter if the number is very high, it should not print nonsense
in any case.

I'm saying I don't care what it does in that instance. If you're attempting to chomp an exabyte of data you already have a bug in your code and what Perl 6 does in that case is irrelevant.

The problem with this ticket is it proposes we take a performance hit in *every* use of .chomp just so in a unlikely scenario of someone's buggy code stumbling on this, Perl 6 will Do The Right Thing in already-buggy code.

This ticket proposes we take a performance hit for no other reason than to scratch some OCD itch of purely theoretical usecase.

Even the maximum string length we support is several thousand times smaller than the chomp case described in this ticket​:

m​: my $x = [~] (("a" x 1073741824) xx 2**16); say $x.chars
rakudo-moar 94a31c​: OUTPUT«0␤»

@p6rt
Copy link
Author

p6rt commented Jul 8, 2016

From @zoffixznet

Fixed in rakudo/rakudo@94b52c1

Tests added in​:
Raku/roast@a222a04
and
Raku/roast@1956de4

@p6rt
Copy link
Author

p6rt commented Jul 8, 2016

@zoffixznet - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Jul 8, 2016
@p6rt
Copy link
Author

p6rt commented Jul 9, 2016

From @MasterDuke17

On Fri Jul 08 05​:48​:23 2016, cpan@​zoffix.com wrote​:

I hope you are not trying to say that 「say
'xx'.chop(9999999999999999999).perl;」 should print "xx". It doesn't
really matter if the number is very high, it should not print
nonsense
in any case.

I'm saying I don't care what it does in that instance. If you're
attempting to chomp an exabyte of data you already have a bug in your
code and what Perl 6 does in that case is irrelevant.

The problem with this ticket is it proposes we take a performance hit
in *every* use of .chomp just so in a unlikely scenario of someone's
buggy code stumbling on this, Perl 6 will Do The Right Thing in
already-buggy code.

This ticket proposes we take a performance hit for no other reason
than to scratch some OCD itch of purely theoretical usecase.

Even the maximum string length we support is several thousand times
smaller than the chomp case described in this ticket​:

m​: my $x = [~] (("a" x 1073741824) xx 2**16); say $x.chars
rakudo-moar 94a31c​: OUTPUT«0␤»

FWIW, I agree with the ticket that the old behavior is a bug (and not
just because I submitted the PR). If I want to worry about the size of
a string I'll use C. One of the reasons I love Perl (5/6) is that I
don't have to worry about many of those kinds of things. I love that
Perl 6 gives me the option do something about it if I do care (use native),
but the freedom to not have to.

I did some informal benchmarks of .chop'ping both small and large strings
and there was no *noticeable* difference. These are what I ran for .chop with
int and Int​:

perl6 -e 'my $a = "a" x 2**16;my $n = now;for ^100000 {my $b = $a.chop($_)};say now - $n'
perl6 -e 'my $a = "a" x 16;my $n = now;for ^100000 {my $b = $a.chop($_)};say now - $n'

As an aside, I wouldn't mind if the max allowed size of a string was significantly increased.
I looked for documentation as to the max size and why that value was chosen, but I
couldn't find anything.

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