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

Double call with --doc #2588

Open
finanalyst opened this issue Jan 7, 2019 · 3 comments
Open

Double call with --doc #2588

finanalyst opened this issue Jan 7, 2019 · 3 comments
Labels
CLI perl6 executable and user programs command-line interface POD6

Comments

@finanalyst
Copy link

The Problem

Developing a new module to interface with the --doc option of perl6 CLI calls render twice.

This is an issue because processing pod to html can be quite time-consuming. Since render is called twice, the processing is done twice.

Expected Behavior

Given a simple module Pod::To::HTML2 containing

unit class Pod::To::HTML2;

method render( $pod-tree ) is export {
    say "At $?LINE tree is ", $pod-tree.perl;
}

and a test file simple.p6 containing

say "Hello World"
=begin pod
   this is some text
=end pod

I would expect the pod-block structure to be output once.

Actual Behavior

$ perl6 -Ip6-pod-render/lib --doc=HTML2 simple.p6
At 4 tree is $[Pod::Block::Named.new(name => "pod", config => {}, contents => [Pod::Block::Code.new(allowed => [], config => {}, contents => ["this is some text"])])]
At 4 tree is $[Pod::Block::Named.new(name => "pod", config => {}, contents => [Pod::Block::Code.new(allowed => [], config => {}, contents => ["this is some text"])])]
True

Steps to Reproduce

Nothing more to add

Environment

  • Operating system: uname -a
    Linux merlin 4.18.0-13-generic Io additions #14~18.04.1-Ubuntu SMP Thu Dec 6 14:09:52 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

  • Compiler version (perl6 -v): perl6 -v
    This is Rakudo Star version 2018.10 built on MoarVM version 2018.10
    implementing Perl 6.c.

@lucasbuchala lucasbuchala added POD6 CLI perl6 executable and user programs command-line interface labels Mar 14, 2019
@Altai-man
Copy link
Member

The likely reason is that https://github.com/rakudo/rakudo/blob/master/src/Perl6/Actions.nqp#L1416 <- does not check if the phaser is already installed.
It is an always matching rule in https://github.com/rakudo/rakudo/blob/master/src/Perl6/Grammar.nqp#L833 and I am not sure how much is it matched, but given that the render is called twice...

Any ideas on how to neatly add a check to the method?

@Altai-man
Copy link
Member

AST for perl6 --target=ast --doc=Text a.pm6 having the same two calls in a single place makes the phaser hypothesis more reliable:

            - QAST::Block(:cuid(3))  :outer<?> :in_stmt_mod<?> :code_object<?>
              - QAST::Stmts  
              - QAST::Op(if) 
                - QAST::Op(callmethod render)  
                  - QAST::Op(call &INDIRECT_NAME_LOOKUP) 
                    - QAST::Op(callmethod new) 
                      - QAST::WVal(PseudoStash) 
                    - QAST::Want 
                      - QAST::WVal(Str) 
                      - Ss
                      - QAST::SVal(Pod::To::Text) 
                  - QAST::Var(lexical $=pod)  
                - QAST::Op(call &say)  
                  - QAST::Op(callmethod render)  
                    - QAST::Op(call &INDIRECT_NAME_LOOKUP) 
                      - QAST::Op(callmethod new) 
                        - QAST::WVal(PseudoStash) 
                      - QAST::Want 
                        - QAST::WVal(Str) 
                        - Ss
                        - QAST::SVal(Pod::To::Text) 
                    - QAST::Var(lexical $=pod)  
              - QAST::Op(call &exit)  
            - QAST::Op(callmethod BIND-KEY) 
              - QAST::Var(lexical !INIT_VALUES) 
              - QAST::SVal(3) 
              - QAST::Op(call) 
                - QAST::WVal(Block) 
            - QAST::Var(lexical $=pod :decl(static)) 

@tbrowder
Copy link
Member

tbrowder commented May 31, 2020

Does that have anything to do with the optimizer? I think the source code gets a second parse pass and I've just noticed surprisingly some debug code in src/Perl6/Grammar.nqp outputs twice during a run.

UPDATE The ast stage is before optimization so we should look at the optimize stage.

I've also tried commenting out the always-matched line for my project and didn't see any difference. I know a little more now than when Richard first posted this, and the issue may have an intersection with my problems. (But looking at QAST causes my eyes to glaze over. Ah well, in with a penny, in with a pound.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI perl6 executable and user programs command-line interface POD6
Projects
None yet
Development

No branches or pull requests

4 participants