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

Infinite loop in dispatch in many Cool methods #6113

Closed
p6rt opened this issue Mar 6, 2017 · 5 comments
Closed

Infinite loop in dispatch in many Cool methods #6113

p6rt opened this issue Mar 6, 2017 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Mar 6, 2017

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

Searchable as RT130940$

@p6rt
Copy link
Author

p6rt commented Mar 6, 2017

From tim.bollman@live.com

If you pass an undefined value into starts-with, it loops forever because the Cool class has a wrapper method that casts the parameters to Str then invokes that. The Str class, however, defines the method as only taking a defined string. So it matches the Cool method again. Repeat.

Changing the cool variant to only take a defined value causes it to die with an error message which is infinitely better​: multi method starts-with(Cool​:D​: Str(Cool​:D) $needle). Or you could make a Str variant that returns some stock value. I don't really know nor care what the intended behavior is as long as it doesn't loop infinitely. From what I've seen in languages I have installed, the majority give an exception or otherwise crash and perl5 obviously treats it as the empty string.

I presume there's a whole category of these in the Cool class that need the same treatment (like ends-with and contains).

@p6rt
Copy link
Author

p6rt commented Mar 6, 2017

From @zoffixznet

On Mon, 06 Mar 2017 12​:51​:12 -0800, TimTom wrote​:

If you pass an undefined value into starts-with, it loops forever
because the Cool class has a wrapper method that casts the parameters
to Str then invokes that. The Str class, however, defines the method
as only taking a defined string. So it matches the Cool method again.
Repeat.

Changing the cool variant to only take a defined value causes it to
die with an error message which is infinitely better​: multi method
starts-with(Cool​:D​: Str(Cool​:D) $needle). Or you could make a Str
variant that returns some stock value. I don't really know nor care
what the intended behavior is as long as it doesn't loop infinitely.
From what I've seen in languages I have installed, the majority give
an exception or otherwise crash and perl5 obviously treats it as the
empty string.

I presume there's a whole category of these in the Cool class that
need the same treatment (like ends-with and contains).

yes, there's a whole ton of them. All of these hang​:
42.starts-with​: Str
42.rindex​: Str
42.indices​: Str
42.contains​: Str
42.ends-with​: Str
42.index​: Str
($ = 42).subst-mutate​: Str

I see a bunch more too and this isn't the first time we're fixing a Cool dispatch hang,
so as part of fixing this, we should go through each method and ensure it doesn't hang.

For methods that just coerce to another type and forward the args, the fix is moving the
proto, and making the Cool candidate an only method that just takes a Capture and passes
that Capture along. This way we also don't duplicate the candidate lists in multiple types,
making us vulnerable to bugs where Cool candidate is missing some args (also fixed several
times already)

@p6rt
Copy link
Author

p6rt commented Mar 6, 2017

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

@p6rt
Copy link
Author

p6rt commented Mar 18, 2017

From @zoffixznet

On Mon, 06 Mar 2017 12​:51​:12 -0800, TimTom wrote​:

If you pass an undefined value into starts-with, it loops forever
because the Cool class has a wrapper method that casts the parameters
to Str then invokes that. The Str class, however, defines the method
as only taking a defined string. So it matches the Cool method again.
Repeat.

Changing the cool variant to only take a defined value causes it to
die with an error message which is infinitely better​: multi method
starts-with(Cool​:D​: Str(Cool​:D) $needle). Or you could make a Str
variant that returns some stock value. I don't really know nor care
what the intended behavior is as long as it doesn't loop infinitely.
From what I've seen in languages I have installed, the majority give
an exception or otherwise crash and perl5 obviously treats it as the
empty string.

I presume there's a whole category of these in the Cool class that
need the same treatment (like ends-with and contains).

Thank you for the report. This is now fixed.

Fix​: rakudo/rakudo@bfbe4298a7
Tests​: Raku/roast@0a39902ba1

@p6rt p6rt closed this as completed Mar 18, 2017
@p6rt
Copy link
Author

p6rt commented Mar 18, 2017

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

@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant