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

Visitor Pattern requires too much CPU and causes the compile error #5342

Closed
p6rt opened this issue May 28, 2016 · 10 comments
Closed

Visitor Pattern requires too much CPU and causes the compile error #5342

p6rt opened this issue May 28, 2016 · 10 comments

Comments

@p6rt
Copy link

p6rt commented May 28, 2016

Migrated from rt.perl.org#128275 (status was 'rejected')

Searchable as RT128275$

@p6rt
Copy link
Author

p6rt commented May 28, 2016

From @titsuki

Hi.
See the following results.

--

$ git clone https://github.com/titsuki/p6-Bug-VIsitor.git
$ cd p6-Bug-VIsitor
$ mi6 test -v
==> Set PERL6LIB=/home/itoyota/Programs/p6-Bug-Visitor/lib
==> prove -e /home/itoyota/.rakudobrew/bin/../moar-nom/install/bin/perl6 -r t
t/01-basic.t .. Dubious, test returned 1 (wstat 256, 0x100)
No subtests run

Test Summary Report


t/01-basic.t (Wstat​: 256 Tests​: 0 Failed​: 0)
  Non-zero exit status​: 1
  Parse errors​: No plan found in TAP output
Files=1, Tests=0, 96 wallclock secs ( 0.07 usr 0.02 sys + 51.41 cusr 7.50 csys = 59.00 CPU)
Result​: FAIL

$ perl6 --version
This is Rakudo version 2016.05-4-g7a4ca4d built on MoarVM version 2016.05
implementing Perl 6.c.

--

@p6rt
Copy link
Author

p6rt commented May 28, 2016

From @titsuki

I have attached the source code.

On 2016-5月-28 土 03​:34​:25, cookbook_000@​yahoo.co.jp wrote​:

Hi.
See the following results.

--

$ git clone https://github.com/titsuki/p6-Bug-VIsitor.git
$ cd p6-Bug-VIsitor
$ mi6 test -v
==> Set PERL6LIB=/home/itoyota/Programs/p6-Bug-Visitor/lib
==> prove -e /home/itoyota/.rakudobrew/bin/../moar-
nom/install/bin/perl6 -r t
t/01-basic.t .. Dubious, test returned 1 (wstat 256, 0x100)
No subtests run

Test Summary Report
-------------------
t/01-basic.t (Wstat​: 256 Tests​: 0 Failed​: 0)
Non-zero exit status​: 1
Parse errors​: No plan found in TAP output
Files=1, Tests=0, 96 wallclock secs ( 0.07 usr 0.02 sys + 51.41 cusr
7.50 csys = 59.00 CPU)
Result​: FAIL

$ perl6 --version
This is Rakudo version 2016.05-4-g7a4ca4d built on MoarVM version
2016.05
implementing Perl 6.c.

--

@p6rt
Copy link
Author

p6rt commented May 28, 2016

From @titsuki

p6-Bug-VIsitor-master.zip

@p6rt
Copy link
Author

p6rt commented May 28, 2016

From @smls

You have circular dependency between your two modules. That's not allowed.

In Bug/Acceptor.pm, instead of doing `use Bug​::Visitor;`, predeclare it instead using `class Bug​::Visitor {...}`. (Yes, those are three literal dots in the source code.)


I'm leaving the ticket open for now, because I don't know if the cyclic dependency should be detected by the compiler. Currently, it just keeps eating more and more RAM until the kernel kills the program.

Minimalist test case to reproduce the problem​:

  ➜ echo "use B;" > A.pm
  ➜ echo "use A;" > B.pm
  ➜ perl6 -I. -e 'use A'

@p6rt
Copy link
Author

p6rt commented May 28, 2016

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

@p6rt
Copy link
Author

p6rt commented May 28, 2016

From @smls

Relevant info from IRC discussion​:

  psch​: we did have circular module loading detection at some point... probably got clobbered with all the CUR work though :/
  lizmat​: before, the detection lived in the nqp code, if I recall
  lizmat​: now, it is the responsibility of the CUR to detect circularities
  lizmat​: a start would be writing a test :-)

@p6rt
Copy link
Author

p6rt commented May 29, 2016

From @titsuki

Thanks for the reply !
However redeclaration of the visitor class doesn't seem to work.
Is there another way to use visitor pattern ?

A.pm
--
use v6;
class B {...};
class A {
  has $.payload = "Perl6";
  method accept(B $b) {
  $b.visit(self);
  }
}
--

B.pm
--
use v6;
use A;

class B {
  method visit(A $a) {
  $a.payload;
  }
}
--

--
$ perl6 -I. -e 'use A'
===SORRY!=== Error while compiling /home/itoyota/Programs/p6-test/circle/A.pm (A)
The following packages were stubbed but not defined​:
  B
at /home/itoyota/Programs/p6-test/circle/A.pm (A)​:9
------> <BOL>?<EOL>
  expecting any of​:
  statement end
--

On 2016-5月-28 土 09​:01​:57, smls75@​gmail.com wrote​:

You have circular dependency between your two modules. That's not
allowed.

In Bug/Acceptor.pm, instead of doing `use Bug​::Visitor;`, predeclare
it instead using `class Bug​::Visitor {...}`. (Yes, those are three
literal dots in the source code.)

---

I'm leaving the ticket open for now, because I don't know if the
cyclic dependency should be detected by the compiler. Currently, it
just keeps eating more and more RAM until the kernel kills the
program.

Minimalist test case to reproduce the problem​:

➜ echo "use B;" > A.pm
➜ echo "use A;" > B.pm
➜ perl6 -I. -e 'use A'

@p6rt
Copy link
Author

p6rt commented May 29, 2016

From @titsuki

*predeclaration

On 2016-5月-28 土 18​:53​:10, cookbook_000@​yahoo.co.jp wrote​:

Thanks for the reply !
However redeclaration of the visitor class doesn't seem to work.
Is there another way to use visitor pattern ?

A.pm
--
use v6;
class B {...};
class A {
has $.payload = "Perl6";
method accept(B $b) {
$b.visit(self);
}
}
--

B.pm
--
use v6;
use A;

class B {
method visit(A $a) {
$a.payload;
}
}
--

--
$ perl6 -I. -e 'use A'
===SORRY!=== Error while compiling /home/itoyota/Programs/p6-
test/circle/A.pm (A)
The following packages were stubbed but not defined​:
B
at /home/itoyota/Programs/p6-test/circle/A.pm (A)​:9
------> <BOL>?<EOL>
expecting any of​:
statement end
--

On 2016-5月-28 土 09​:01​:57, smls75@​gmail.com wrote​:

You have circular dependency between your two modules. That's not
allowed.

In Bug/Acceptor.pm, instead of doing `use Bug​::Visitor;`, predeclare
it instead using `class Bug​::Visitor {...}`. (Yes, those are three
literal dots in the source code.)

---

I'm leaving the ticket open for now, because I don't know if the
cyclic dependency should be detected by the compiler. Currently, it
just keeps eating more and more RAM until the kernel kills the
program.

Minimalist test case to reproduce the problem​:

➜ echo "use B;" > A.pm
➜ echo "use A;" > B.pm
➜ perl6 -I. -e 'use A'

@p6rt
Copy link
Author

p6rt commented May 29, 2016

From @smls

Hm you're right, predeclaration doesn't seem to be the correct solution to your problem after all.

But this bug tracker is not the right place for Perl 6 user support, it should be reserved for collecting info on actual Rakudo bugs.
You should ask on the #perl6 IRC channel instead, I'm sure someone there can help you solve your programming problem.

As for the issue of Rakudo failing to detect the cyclic dependency and printing an appropriate error message for it, I've submitted a new ticket for that to keep it clean​: [perl #​128285]
I'm renaming this ticket here back to its original title, and I'm closing it.

@p6rt
Copy link
Author

p6rt commented May 29, 2016

@smls - Status changed from 'open' to 'rejected'

@p6rt p6rt closed this as completed May 29, 2016
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