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

use VERSION MODULE should not be considered legal #13646

Open
p5pRT opened this issue Mar 6, 2014 · 14 comments
Open

use VERSION MODULE should not be considered legal #13646

p5pRT opened this issue Mar 6, 2014 · 14 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 6, 2014

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

Searchable as RT121392$

@p5pRT
Copy link
Author

p5pRT commented Mar 6, 2014

From @kentfredric

While reading toke.c a while back, I stumbled upon an unfortunate accident.

use VERSION MODULE;
use MODULE VERSION;

These forms are equivalent.

And the former form deparses into the latter.

For example​:

---
use 2.000 Moose # is and requires Moose 2.0
---

And
---
use 5.010
Moose;
---

Moose version 5.01 required--this is only version 2.1204

And a grep of CPAN shows that there are a few cases where this might occur.

http​://grep.cpan.me/?q=^\s*use\s%2B[v\d.]%2B\s%2B\w ( Marpa is interestingly testing for that exact syntax )

Specifically, when doing this​:
---
use 5.010
use Moose;
---

Which yields the slightly confusing error​:

---
"use" not allowed in expression at /tmp/moo.pl line 10, at end of line
syntax error at /tmp/moo.pl line 10, near "use 5.010
use Moose"
---

Though thats only failing because it doesn't like you doing this​:

---
use 5.010 use;
---

Which is fine in the alternative form

---
use use 5.010
---

Enabling `strict` here changes things slightly​:

---
use strict;
use 5.010 Moose;
---

But ... the error is weird​:

---
Bareword "Moose.pm" not allowed while "strict subs" in use at /tmp/moo.pl line 9.
---

Fortunately, the odds of triggering a silent bug on a line after a

---
use 5.010
---

Without the trailing semicolon is slim without triggering a subsequent error due to keyword-in-expression.

So the only real risk is people doing

---
use 5.018 featurename
---

Or similar, and erroneously expecting that to be valid syntax, and it loading something else unintended.

For instance

---
use 5.019 subs
---

Giving

---
subs version 5.019 required--this is only version 1.02
---

May invoke confusion.

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl 5.19.9:

Configured by kent at Sat Feb 22 17:58:53 NZDT 2014.

Summary of my perl5 (revision 5 version 19 subversion 9) configuration:
   
  Platform:
    osname=linux, osvers=3.13.0-gentoo-r1, archname=x86_64-linux
    uname='linux katipo2 3.13.0-gentoo-r1 #58 smp tue jan 28 20:17:45 nzdt 2014 x86_64 intel(r) core(tm) i5-2410m cpu @ 2.30ghz genuineintel gnulinux '
    config_args='-de -Dprefix=/home/kent/perl5/perlbrew/perls/perl-5.19.9-fast -Doptimize=-march=native -mtune=native -O3 -pipe -msse -msse2 -mssse3 -msse4.1 -msse4.2 -mavx -mfxsr -mxsave -mxsaveopt -Dusedevel -Aeval:scriptdir=/home/kent/perl5/perlbrew/perls/perl-5.19.9-fast/bin'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-march=native -mtune=native -O3 -pipe -msse -msse2 -mssse3 -msse4.1 -msse4.2 -mavx -mfxsr -mxsave -mxsaveopt',
    cppflags='-fno-strict-aliasing -pipe -fstack-protector'
    ccversion='', gccversion='4.8.2', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -fstack-protector'
    libpth=/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.2/include-fixed /usr/lib /lib/../lib64 /usr/lib/../lib64 /lib /lib64 /usr/lib64
    libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.17.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.17'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -march=native -mtune=native -O3 -pipe -msse -msse2 -mssse3 -msse4.1 -msse4.2 -mavx -mfxsr -mxsave -mxsaveopt -fstack-protector'



@INC for perl 5.19.9:
    /home/kent/perl5/perlbrew/perls/perl-5.19.9-fast/lib/site_perl/5.19.9/x86_64-linux
    /home/kent/perl5/perlbrew/perls/perl-5.19.9-fast/lib/site_perl/5.19.9
    /home/kent/perl5/perlbrew/perls/perl-5.19.9-fast/lib/5.19.9/x86_64-linux
    /home/kent/perl5/perlbrew/perls/perl-5.19.9-fast/lib/5.19.9
    .


Environment for perl 5.19.9:
    HOME=/home/kent
    LANG (unset)
    LANGUAGE (unset)
    LC_CTYPE=en_NZ.UTF8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/kent/perl5/perlbrew/bin:/home/kent/perl5/perlbrew/perls/perl-5.19.9-fast/bin:/home/kent/.perl6/2013.04/bin:/home/kent/.gem/ruby/1.8/bin/:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.8.2:/usr/games/bin
    PERLBREW_BASHRC_VERSION=0.67
    PERLBREW_HOME=/home/kent/.perlbrew
    PERLBREW_MANPATH=/home/kent/perl5/perlbrew/perls/perl-5.19.9-fast/man
    PERLBREW_PATH=/home/kent/perl5/perlbrew/bin:/home/kent/perl5/perlbrew/perls/perl-5.19.9-fast/bin
    PERLBREW_PERL=perl-5.19.9-fast
    PERLBREW_ROOT=/home/kent/perl5/perlbrew
    PERLBREW_VERSION=0.67
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Mar 25, 2014

From jeffreykegler@jeffreykegler.com

I am the author of Marpa, a module which is mentioned in the ticket.

While looking into Perl parsing for Marpa, I ran into this problem, which I called the "reversed use statement". I incorporated some parsing experiments on it into Marpa's test suite. That's why Marpa tests for reversed use statements.

I wrote a blog post on this problem some time ago​: http​://jeffreykegler.github.io/Ocean-of-Awar​eness-blog/individual/2011/10/perl-and-parsi​ng-12-beating-up-on-the-use-statement.html
In it I list some of the variations of the reversed use statement and their behaviors.

I also discuss this section of the Perl code in two other blog posts​: http​://jeffreykegler.github.io/Ocean-of-A​wareness-blog/individual/2011/09/perl-and​-parsing-9-use-and-the-ruby-slippers.html
and
http​://jeffreykegler.github.io/Ocean-of​-Awareness-blog/individual/2011/10/perl​-and-parsing-10-use-the-easier-way.html
These don't mention the bug specifically, but they talk about the code that causes it.

Hope this is helpful. -- jeffrey

On Thu Mar 06 13​:54​:52 2014, kentfredric wrote​:

While reading toke.c a while back, I stumbled upon an unfortunate
accident.

use VERSION MODULE;
use MODULE VERSION;

These forms are equivalent.

And the former form deparses into the latter.

@p5pRT
Copy link
Author

p5pRT commented Mar 25, 2014

From [Unknown Contact. See original ticket]

I am the author of Marpa, a module which is mentioned in the ticket.

While looking into Perl parsing for Marpa, I ran into this problem, which I called the "reversed use statement". I incorporated some parsing experiments on it into Marpa's test suite. That's why Marpa tests for reversed use statements.

I wrote a blog post on this problem some time ago​: http​://jeffreykegler.github.io/Ocean-of-Awar​eness-blog/individual/2011/10/perl-and-parsi​ng-12-beating-up-on-the-use-statement.html
In it I list some of the variations of the reversed use statement and their behaviors.

I also discuss this section of the Perl code in two other blog posts​: http​://jeffreykegler.github.io/Ocean-of-A​wareness-blog/individual/2011/09/perl-and​-parsing-9-use-and-the-ruby-slippers.html
and
http​://jeffreykegler.github.io/Ocean-of​-Awareness-blog/individual/2011/10/perl​-and-parsing-10-use-the-easier-way.html
These don't mention the bug specifically, but they talk about the code that causes it.

Hope this is helpful. -- jeffrey

On Thu Mar 06 13​:54​:52 2014, kentfredric wrote​:

While reading toke.c a while back, I stumbled upon an unfortunate
accident.

use VERSION MODULE;
use MODULE VERSION;

These forms are equivalent.

And the former form deparses into the latter.

@p5pRT
Copy link
Author

p5pRT commented Mar 30, 2014

From @kentfredric

On 26 March 2014 03​:53, Jeffrey Kegler via RT <perlbug-comment@​perl.org>wrote​:

I wrote a blog post on this problem some time ago​:
http​://jeffreykegler.github.io/Ocean-of-Awar
​eness-blog/individual/2011/10/perl-and-parsi​ng-12-beating-up-on-the-use-statement.html
In it I list some of the variations of the reversed use statement and
their behaviors.

I also discuss this section of the Perl code in two other blog posts​:
http​://jeffreykegler.github.io/Ocean-of-A
​wareness-blog/individual/2011/09/perl-and​-parsing-9-use-and-the-ruby-slippers.html
and
http​://jeffreykegler.github.io/Ocean-of
​-Awareness-blog/individual/2011/10/perl​-and-parsing-10-use-the-easier-way.html
These don't mention the bug specifically, but they talk about the code
that causes it.

Just attaching tinyurls of all of the above, because for some reason, each
and every one of them when copy-pasted had a Unicode byte in the middle
somewhere that was decoded/encoded wrong somewhere and messed up the URL

http​://tinyurl.com/krqv2e4 # Beating up on the use statement

http​://tinyurl.com/ma7myyt # Parsing USE

http​://tinyurl.com/klh56nx # Parsing USE the easy way

--
Kent

@p5pRT
Copy link
Author

p5pRT commented Sep 24, 2014

From @jkeenan

On Thu Mar 06 13​:54​:52 2014, kentfredric wrote​:

While reading toke.c a while back, I stumbled upon an unfortunate
accident.

use VERSION MODULE;
use MODULE VERSION;

These forms are equivalent.

And the former form deparses into the latter.

For example​:

---
use 2.000 Moose # is and requires Moose 2.0
---

And
---
use 5.010
Moose;
---

Moose version 5.01 required--this is only version 2.1204

And a grep of CPAN shows that there are a few cases where this might
occur.

http​://grep.cpan.me/?q=^\s*use\s%2B[v\d.]%2B\s%2B\w ( Marpa is
interestingly testing for that exact syntax )

Looking at what's at that link, my impression is that most of the modules on CPAN that display this are Acme​::* modules.

Specifically, when doing this​:
---
use 5.010
use Moose;
---

Which yields the slightly confusing error​:

---
"use" not allowed in expression at /tmp/moo.pl line 10, at end of line
syntax error at /tmp/moo.pl line 10, near "use 5.010
use Moose"
---

Though thats only failing because it doesn't like you doing this​:

---
use 5.010 use;
---

Which is fine in the alternative form

---
use use 5.010
---

Enabling `strict` here changes things slightly​:

---
use strict;
use 5.010 Moose;
---

But ... the error is weird​:

---
Bareword "Moose.pm" not allowed while "strict subs" in use at
/tmp/moo.pl line 9.
---

Fortunately, the odds of triggering a silent bug on a line after a

---
use 5.010
---

Without the trailing semicolon is slim without triggering a subsequent
error due to keyword-in-expression.

So the only real risk is people doing

---
use 5.018 featurename
---

Or similar, and erroneously expecting that to be valid syntax, and it
loading something else unintended.

For instance

---
use 5.019 subs
---

Giving

---
subs version 5.019 required--this is only version 1.02
---

May invoke confusion.

This ticket has not generated any discussion since it was file 6+ months ago. Comments?

Thank you very much.

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Sep 24, 2014

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

@p5pRT
Copy link
Author

p5pRT commented Sep 24, 2014

From @cpansprout

On Tue Sep 23 18​:36​:36 2014, jkeenan wrote​:

This ticket has not generated any discussion since it was file 6+
months ago. Comments?

I’ve known about this ‘feature’ for a long time. It’s kind of fun to use it in JAPHs, but I don’t mind if it goes. I had concluded that I would rip it out if it got in the way of a bug fix, but leave it otherwise. However, if someone else wants to remove it, that’s fine.

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Sep 25, 2014

From @bulk88

On Tue Sep 23 18​:36​:36 2014, jkeenan wrote​:

This ticket has not generated any discussion since it was file 6+
months ago. Comments?

Thank you very much.

I'd keep it since it is DWIM.

--
bulk88 ~ bulk88 at hotmail.com

@p5pRT
Copy link
Author

p5pRT commented Sep 25, 2014

From @rjbs

* bulk88 via RT <perlbug-followup@​perl.org> [2014-09-24T21​:42​:18]

On Tue Sep 23 18​:36​:36 2014, jkeenan wrote​:

This ticket has not generated any discussion since it was file 6+
months ago. Comments?

I'd keep it since it is DWIM.

I'd see it removed for the opposite reason​: I don't think anyone who writes
"use 2.0 Moose" means anything other than "I am confused or trying to confuse."

--
rjbs

@p5pRT
Copy link
Author

p5pRT commented Sep 25, 2014

From @andk

On Wed, 24 Sep 2014 22​:35​:37 -0400, Ricardo Signes <perl.p5p@​rjbs.manxome.org> said​:

rs> * bulk88 via RT <perlbug-followup@​perl.org> [2014-09-24T21​:42​:18]

On Tue Sep 23 18​:36​:36 2014, jkeenan wrote​:

This ticket has not generated any discussion since it was file 6+
months ago. Comments?

I'd keep it since it is DWIM.

rs> I'd see it removed for the opposite reason​: I don't think anyone who writes
rs> "use 2.0 Moose" means anything other than "I am confused or trying to confuse."

+1

--
andreas

@p5pRT
Copy link
Author

p5pRT commented Sep 25, 2014

From @Abigail

On Wed, Sep 24, 2014 at 10​:35​:37PM -0400, Ricardo Signes wrote​:

* bulk88 via RT <perlbug-followup@​perl.org> [2014-09-24T21​:42​:18]

On Tue Sep 23 18​:36​:36 2014, jkeenan wrote​:

This ticket has not generated any discussion since it was file 6+
months ago. Comments?

I'd keep it since it is DWIM.

I'd see it removed for the opposite reason​: I don't think anyone who writes
"use 2.0 Moose" means anything other than "I am confused or trying to confuse."

But what do we gain if we start forbidding it now? No doubt there's
already code out there that does "use VERSION MODULE;", either on
purpose, because the author was confused, or someone made a mistake.

I'm with bulk88 on this one; since it's DWIM, my vote is to keep it.
(And then we may want to add a test, and document it).

Abigail

@p5pRT
Copy link
Author

p5pRT commented Sep 25, 2014

From @ap

* Abigail <abigail@​abigail.be> [2014-09-25 11​:00]​:

But what do we gain if we start forbidding it now? No doubt there's
already code out there that does "use VERSION MODULE;", either on
purpose, because the author was confused, or someone made a mistake.

It does not fix existing code but would improve not-yet-written code.
Which is always the point of tension in such matters.

I'm with bulk88 on this one; since it's DWIM, my vote is to keep it.
(And then we may want to add a test, and document it).

My vote too.

But document it as discouraged, IMO. Not just because it is bad to use
the construct, but also​: while there is no need to break anyone’s code
now, the syntax seems fairly likely to complicate or block new features
for `use`. Should that ever occur, it should not cause huge controversy
at that time to deprecate it. And that requires keeping usage low now.

@p5pRT
Copy link
Author

p5pRT commented Sep 25, 2014

From @jkeenan

On 09/25/2014 05​:40 AM, Aristotle Pagaltzis wrote​:

* Abigail <abigail@​abigail.be> [2014-09-25 11​:00]​:

But what do we gain if we start forbidding it now? No doubt there's
already code out there that does "use VERSION MODULE;", either on
purpose, because the author was confused, or someone made a mistake.

It does not fix existing code but would improve not-yet-written code.
Which is always the point of tension in such matters.

I'm with bulk88 on this one; since it's DWIM, my vote is to keep it.
(And then we may want to add a test, and document it).

My vote too.

But document it as discouraged, IMO. Not just because it is bad to use
the construct, but also​: while there is no need to break anyone’s code
now, the syntax seems fairly likely to complicate or block new features
for `use`. Should that ever occur, it should not cause huge controversy
at that time to deprecate it. And that requires keeping usage low now.

+1 to early containment of the problem!

@p5pRT
Copy link
Author

p5pRT commented Feb 22, 2015

From @rjbs

* Aristotle Pagaltzis <pagaltzis@​gmx.de> [2014-09-25T05​:40​:41]

I'm with bulk88 on this one; since it's DWIM, my vote is to keep it.
(And then we may want to add a test, and document it).

My vote too.

I stand by my earlier reply to this, but...

But document it as discouraged, IMO. Not just because it is bad to use
the construct, but also​: while there is no need to break anyone’s code
now, the syntax seems fairly likely to complicate or block new features
for `use`. Should that ever occur, it should not cause huge controversy
at that time to deprecate it. And that requires keeping usage low now.

Say that in mid-2018 we realize, then, that we want to use this syntax, or that
the current syntax complicates or blocks something, as you suggest. We will
then be able to get the deprecation into the 2019 and 2020 releases, with the
feature removed and/or replaced in 2021.

I agree that we should take the action that you suggest, but I am going on
record that I am emitting a weary sigh as I agree. It may not accomplish
anything, but it makes me feel a little better.

--
rjbs

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