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

"duplicate definition of symbol grammar" using Grammar::Tracer in .pm6 file #4971

Closed
p6rt opened this issue Dec 31, 2015 · 8 comments
Closed

Comments

@p6rt
Copy link

p6rt commented Dec 31, 2015

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

Searchable as RT127107$

@p6rt
Copy link
Author

p6rt commented Dec 31, 2015

From @ShimmerFairy

$ cat Foo.pm6
use Grammar​::Tracer;
$ perl6 -I. -e 'use Foo'
===SORRY!===
P6M Merging GLOBAL symbols failed​: duplicate definition of symbol grammar

It appears that, for whatever reason, using Grammar​::Tracer from within a module file causes that strange low-level error. Note that attempting 'use Grammar​::Tracer' in a non-module file or directly in one-liners doesn't seem to be an issue​:

$ perl6 Foo.pm6
$ perl6 -e 'use Grammar​::Tracer'
$

@p6rt
Copy link
Author

p6rt commented Dec 31, 2015

From @MARTIMM

On 12/31/2015 01​:47 PM, Faye (via RT) wrote​:

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

$ cat Foo.pm6
use Grammar​::Tracer;
$ perl6 -I. -e 'use Foo'
===SORRY!===
P6M Merging GLOBAL symbols failed​: duplicate definition of symbol grammar

It appears that, for whatever reason, using Grammar​::Tracer from within a module file causes that strange low-level error. Note that attempting 'use Grammar​::Tracer' in a non-module file or directly in one-liners doesn't seem to be an issue​:

$ perl6 Foo.pm6
$ perl6 -e 'use Grammar​::Tracer'
$
See also messages with subject 'lack of info in error message' from
mt1957@​gmail.com

summarized here... (p.s. the test file is from my own project and the
symbol is defined by using constant)

I get the following error;

perl6 t/070-run-command.t
===SORRY!===
P6M Merging GLOBAL symbols failed​: duplicate definition of symbol C-MD5-SIZE

Searching for the symbol gave me exactly one location where it was
defined. So the error should be more explicit in where it was first
found and where the second throws the error. In the mean time I found
that ordering of use statements make a difference after which the error
disappears.

@p6rt
Copy link
Author

p6rt commented Dec 31, 2015

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

@p6rt
Copy link
Author

p6rt commented Jan 2, 2016

From @lizmat

On 31 Dec 2015, at 13​:47, Faye (via RT) <perl6-bugs-followup@​perl.org> wrote​:

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

$ cat Foo.pm6
use Grammar​::Tracer;
$ perl6 -I. -e 'use Foo'
===SORRY!===
P6M Merging GLOBAL symbols failed​: duplicate definition of symbol grammar

It appears that, for whatever reason, using Grammar​::Tracer from within a module file causes that strange low-level error. Note that attempting 'use Grammar​::Tracer' in a non-module file or directly in one-liners doesn't seem to be an issue​:

$ perl6 Foo.pm6
$ perl6 -e 'use Grammar​::Tracer'
$

This appears to be happening *inside* an nqp​::loadbytecode of CompUnit​::Loader.load-precompilation-file . Which would lead me to think that some dynamic variable is not set up correctly.

Liz

@p6rt
Copy link
Author

p6rt commented Jan 8, 2016

From @niner

Reverting commit b384d8f777f6169052c25e5cc37353f01b8f5f1a is "fixing" this so the bug is in Perl6​::ModuleLoader. Before that commit, resolve_reposession_conflicts was utterly broken (and has been so since at least summer) causing for example failures when precompiling (even manually) HTTP​::UserAgent. The fix simply re-used the same logic for merging globals that we also use during compilation for fixing up conflicts when loading precomp files.

And that's where it becomes really puzzling. If it works during compilation, it ought to work after loading a precompiled version, as it's the same code for the same job. The difference between Grammar​::Tracer and more mundane modules is EXPORTHOW instead of EXPORT. So maybe merge_globals is just missing some HOW handling.

The smalles test case is this​:

nine@​sphinx​:~/test/lib> cat Demo.pm
use Grammar​::Tracer;
nine@​sphinx​:~/test/lib> perl6 -e 'use Test; use lib "."; use Demo;' # prevent precompilation
nine@​sphinx​:~/test/lib> perl6 -I. -e 'use Demo;' # with precompilation
===SORRY!===
P6M Merging GLOBAL symbols failed​: duplicate definition of symbol grammar

@p6rt
Copy link
Author

p6rt commented Jan 8, 2016

From @niner

Adding some debug output to merge_globals makes this riddle even more puzzling​:

nine@​sphinx​:~/test/lib> perl6 --ll-exception -I. -e 'use Demo;' # with precompilation
Checking symbol Terminal value Terminal objid 52848424 existing NQPMu objid 13038968
unknown!
Checking symbol Terminal value Terminal objid 79152672 existing NQPMu objid 39359864
unknown!
Known symbol grammar
Checking symbol grammar value TracedGrammarHOW objid 47679944 existing TracedGrammarHOW objid 47679944
conflict!
source_is_stub​: 0 Perl6​::Metamodel​::ClassHOW
target_is_stub​: 0 Perl6​::Metamodel​::ClassHOW
P6M Merging GLOBAL symbols failed​: duplicate definition of symbol grammar

After "Checking symbol" there's this comparison​:
elsif ($target){$sym} =​:= $_.value {
which evaluates to 0, so we land in the "conflict!" branch. But the objectids of the existing and the to be merge d symbol are identical!?

@p6rt
Copy link
Author

p6rt commented Jan 8, 2016

From @niner

Fixed in rakudo commit 2d91f08585bcd75aabcd2513103a7eb985df5689

When an EXPORT or EXPORTHOW routine assigns a symbol as in​:
EXPORTHOW​::<grammar> = TracedGrammarHOW;
instead of binding it, the test in Perl6​::ModuleLoader​::merge_symbols for
equivalence of source and destination symbols fails because it compares
the containers of those symbols instead of the symbols themselves.
 
Fixed by always decont'ing before comparison.
 
Many, many thanks again to FROGGS++ for finding the final piece of this puzzle!

@p6rt
Copy link
Author

p6rt commented Jan 8, 2016

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

@p6rt p6rt closed this as completed Jan 8, 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