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

sub EXPORT loaded inside precompiled module doesn't seem to be run #1371

Closed
zoffixznet opened this issue Jan 6, 2018 · 3 comments
Closed

Comments

@zoffixznet
Copy link
Contributor

zoffixznet commented Jan 6, 2018

This looks very related to #1369

I modify a lexical in sub EXPORT:

$ cat Foo.pm6 
my $meow;
sub EXPORT ($conf = 'config.json') {
    dd $conf;
    $meow = $conf;
    { '&jconf' => &jconf }
}
sub jconf { say $meow }

And I load this module inside another module and export another routine that calls the routine from the first module that prints that lexical:

$ cat Bar.pm6 
use Foo 'bar.json';
sub meows is export { jconf }

I then load both modules, with the 'Bar.pm6' loaded second, yet when I use the routines to dump the lexical, I get only the value from the module that got loaded first and the dd that Bar.pm6 would've run doesn't get run:

$ perl6 -I. -MFoo -MBar -e 'jconf; meows'
Str $conf = "config.json"
config.json
config.json

But, if I stick no precompilation into Bar.pm6, then it works fine and the routines dump the value set by Bar.pm6's loading:

$ perl6 -I. -MFoo -MBar -e 'jconf; meows'
Str $conf = "config.json"
Str $conf = "bar.json"
bar.json
bar.json
$ perl6 -v
This is Rakudo version 2017.12-11-g2a8287c built on MoarVM version 2017.12-1-g912f967
implementing Perl 6.c.
@zoffixznet zoffixznet changed the title Lexical modified in sub EXPORT has wrong value sub EXPORT loaded inside precompiled module doesn't seem to be run Jan 6, 2018
@zoffixznet
Copy link
Contributor Author

EDIT: just now noticed the dd doesn't get run the second time in the precompiled version, so looks like sub EXPORT doesn't even get run at all

@jnthn
Copy link
Member

jnthn commented Jan 6, 2018

This is correct behavior. A use (also import, which use uses) is a compile-time operation. When the using module is precompiled, then the results of the import are serialized, so that the import, symbol table merging, etc. do not need to be repeated every single load time. Thus there is no import per module load and, as such, no IMPORT sub call per module load either.

@zoffixznet
Copy link
Contributor Author

Thanks.

zoffixznet added a commit to Raku/doc that referenced this issue Jan 6, 2018
- Toss example of evil hack as it won't work right with precomp
- Document the precompilation caveat and how to deal with it per
  rakudo/rakudo#1371 (comment)
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

2 participants