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

over-eager multi dispatcher optimization #2874

Open
p6rt opened this issue Aug 28, 2012 · 5 comments
Open

over-eager multi dispatcher optimization #2874

p6rt opened this issue Aug 28, 2012 · 5 comments

Comments

@p6rt
Copy link

p6rt commented Aug 28, 2012

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

Searchable as RT114634$

@p6rt
Copy link
Author

p6rt commented Aug 28, 2012

From @moritz

"Just because it's an A doesn't mean it can't be a B"

Consider

{
  my class A {};
  my class B { };
  my class C is B is A {};
  multi f(A) { "A" };
  multi f(B) { "B" };
  sub g(A $x) { say f($x) }; # type A
  g(C.new);
}

# prints A

{
  my class A {};
  my class B { };
  my class C is B is A {};
  multi f(A) { "A" };
  multi f(B) { "B" };
  sub g(A $x) { say f($x) }; # type A
  g(C.new);
}

# prints B

and with the optimizer turned off, both print

Ambiguous call to 'f'; these signatures all match​:
:(A )
:(B )

Found by sorear++

@p6rt
Copy link
Author

p6rt commented Aug 28, 2012

From not.com@gmail.com

I'm a little confused by this report. The two code snippets are
exactly the same- I checked with "diff". Does the same code have
different results with different runs, or is there a copy/paste error?
Also is the space between the brackets in "class B{ }" significant
(the other two empty bracket pairs have no space)?

-y

On Tue, Aug 28, 2012 at 2​:43 AM, Moritz Lenz <perl6-bugs-followup@​perl.org>
wrote​:

# New Ticket Created by Moritz Lenz
# Please include the string​: [perl #​114634]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=114634 >

"Just because it's an A doesn't mean it can't be a B"

Consider

{
my class A {};
my class B { };
my class C is B is A {};
multi f(A) { "A" };
multi f(B) { "B" };
sub g(A $x) { say f($x) }; # type A
g(C.new);
}

# prints A

{
my class A {};
my class B { };
my class C is B is A {};
multi f(A) { "A" };
multi f(B) { "B" };
sub g(A $x) { say f($x) }; # type A
g(C.new);
}

# prints B

and with the optimizer turned off, both print

Ambiguous call to 'f'; these signatures all match​:
:(A )
:(B )

Found by sorear++

@p6rt
Copy link
Author

p6rt commented Aug 28, 2012

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

@p6rt
Copy link
Author

p6rt commented Aug 28, 2012

From @sorear

On Tue, Aug 28, 2012 at 09​:15​:41AM -0400, yary wrote​:

I'm a little confused by this report. The two code snippets are
exactly the same- I checked with "diff". Does the same code have
different results with different runs, or is there a copy/paste error?
Also is the space between the brackets in "class B{ }" significant
(the other two empty bracket pairs have no space)?

There is in fact a copy-paste error. Here's the original, notice the changing
signature of &g​:

sorear$ ./install/bin/perl6

{ my class A {}; my class B { }; my class C is B is A {}; multi f(A) { "A" }; multi f(B) { "B" }; sub g(A $x) { say f($x) }; g(C.new); }
A
{ my class A {}; my class B { }; my class C is B is A {}; multi f(A) { "A" }; multi f(B) { "B" }; sub g(B $x) { say f($x) }; g(C.new); }
B

-Stefan

@p6rt p6rt added the Bug label Jan 5, 2020
@usev6
Copy link

usev6 commented Feb 4, 2023

This works now as expected:

$ ./rakudo-m -e 'my class A {}; my class B {}; my class C is B is A {}; multi f(A) { "A" }; multi f(B) { "B" }; sub g(A $x) { say f($x) }; g(C.new)'
Ambiguous call to 'f(C)'; these signatures all match:
  (A $)
  (B $)
  in sub g at -e line 1
  in block <unit> at -e line 1
$ ./rakudo-m -e 'my class A {}; my class B {}; my class C is B is A {}; multi f(A) { "A" }; multi f(B) { "B" }; sub g(B $x) { say f($x) }; g(C.new)'
Ambiguous call to 'f(C)'; these signatures all match:
  (A $)
  (B $)
  in sub g at -e line 1
  in block <unit> at -e line 1

According to bisectable6 (https://colabti.org/irclogger/irclogger_log/raku-dev?date=2023-02-04#l166) this has been fixed back in 2017 with rakudo/rakudo@f8b3469439.

On the JVM backend the problem still exists:

$ ./rakudo-j -e 'my class A {}; my class B {}; my class C is B is A {}; multi f(A) { "A" }; multi f(B) { "B" }; sub g(A $x) { say f($x) }; g(C.new)'
A
$ ./rakudo-j -e 'my class A {}; my class B {}; my class C is B is A {}; multi f(A) { "A" }; multi f(B) { "B" }; sub g(B $x) { say f($x) }; g(C.new)'
B

Tagging as "tests needed".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants