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

arg list constant folding #10889

Open
p5pRT opened this issue Dec 10, 2010 · 5 comments
Open

arg list constant folding #10889

p5pRT opened this issue Dec 10, 2010 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Dec 10, 2010

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

Searchable as RT80524$

@p5pRT
Copy link
Author

p5pRT commented Dec 10, 2010

From zefram@fysh.org

Created by zefram@fysh.org

$ perl -lwe '$a=1; print sqrt($a or 4,9)'
Useless use of a constant (4) in void context at -e line 1.
1
$ perl -lwe '$a=0; print sqrt($a or 4,9)'
Useless use of a constant (4) in void context at -e line 1.
3
$ perl -lwe 'print sqrt(1 or 4,9)'
1
$ perl -lwe 'print sqrt(0 or 4,9)'
Too many arguments for sqrt at -e line 1, near "9)
"
Execution of -e aborted due to compilation errors.

Same happens for a user-defined sub with ($) prototype. I was a bit
surprised to find that lower-prec-than-comma operators are allowed at the
top level of an argument list at all. It rather screws up the concept
of the argument list, when it's being processed by a prototype.

Given that these operators are permitted in this location, the behaviour
in the first two cases (with $a) is reasonably understandable. In the
third case, apparently constant folding suppresses a "useless use of
a constant" warning. What's really interesting, though, is the fourth
case, where constant folding turns the syntactially one-item argument list
into a two-item list, to which the prototype objects. Constant folding
shouldn't be changing the effective syntax of the language.

Bonus test cases​: constant folding, and thus effective syntax, can depend
on warning flags​:

$ perl -lwe 'print sqrt(__PACKAGE__*0 or 1,2)'
Argument "main" isn't numeric in multiplication (*) at -e line 1.
1.41421356237309505
$ perl -le 'print sqrt(__PACKAGE__*0 or 1,2)'
Too many arguments for sqrt at -e line 1, near "2)
"
Execution of -e aborted due to compilation errors.

I'm inclined to propose that the <expr> references in the various
relevant productions should be changed to <argexpr>, thus disallowing the
low-prec-logic operators and insisting that the top level of the argument
list be a list, fit for prototype processing. (Constant folding won't
damage the list structure.) This would require a deprecation cycle,
of course.

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl 5.12.2:

Configured by root at Thu Nov 11 16:27:39 UTC 2010.

Summary of my perl5 (revision 5 version 12 subversion 2) configuration:
   
  Platform:
    osname=linux, osvers=2.6.26-2-686, archname=i686-linux-64int-ld
    uname='linux ukmcwzefram.photobox.priv 2.6.26-2-686 #1 smp thu sep 16 19:35:51 utc 2010 i686 gnulinux '
    config_args='-des -Duseshrplib -Duse64bitint -Duselongdouble -Uusethreads -Uusemultiplicity -Dprefix=/opt/perl-5.12.2 -Dsiteprefix=/opt/perl-5.12.2 -Dvendorprefix=/opt/perl-5.12.2/vendor -Dcccdlflags=-fPIC -O2 -pipe'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=undef, uselongdouble=define
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.3.3', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long long', ivsize=8, nvtype='long double', nvsize=12, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /lib64 /usr/lib64
    libs=-lnsl -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.7.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.7'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/opt/perl-5.12.2/lib/5.12.2/i686-linux-64int-ld/CORE'
    cccdlflags='-fPIC -O2 -pipe', lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector'

Locally applied patches:
    


@INC for perl 5.12.2:
    /opt/perl-5.12.2/lib/site_perl/5.12.2/i686-linux-64int-ld
    /opt/perl-5.12.2/lib/site_perl/5.12.2
    /opt/perl-5.12.2/vendor/lib/vendor_perl/5.12.2/i686-linux-64int-ld
    /opt/perl-5.12.2/vendor/lib/vendor_perl/5.12.2
    /opt/perl-5.12.2/lib/5.12.2/i686-linux-64int-ld
    /opt/perl-5.12.2/lib/5.12.2
    .


Environment for perl 5.12.2:
    HOME=/home/zefram
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/zefram/pub/i686-pc-linux-gnu/bin:/home/zefram/pub/common/bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/local/bin:/usr/games
    PERL_BADLANG (unset)
    SHELL=/usr/bin/zsh

@p5pRT
Copy link
Author

p5pRT commented Dec 11, 2010

From @demerphq

On 10 December 2010 12​:40, Zefram <perlbug-followup@​perl.org> wrote​:

I'm inclined to propose that the <expr> references in the various
relevant productions should be changed to <argexpr>, thus disallowing the
low-prec-logic operators and insisting that the top level of the argument
list be a list, fit for prototype processing.  (Constant folding won't
damage the list structure.)  This would require a deprecation cycle,
of course.

Can you explain the implications of this in more generic terms?

Yves

--
perl -Mre=debug -e "/just|another|perl|hacker/"

@p5pRT
Copy link
Author

p5pRT commented Dec 11, 2010

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

@p5pRT
Copy link
Author

p5pRT commented Dec 11, 2010

From zefram@fysh.org

demerphq wrote​:

Can you explain the implications of this in more generic terms?

Not clear what you mean by "more generic" here. Nor of what you want
to know about the implications.

The deprecation that I propose would forbid the use of "and", "or",
and "xor" at the top level of an argument list, as in "sqrt($a or
do_something(), 9)". One would have to either reexpress it using
lower-precedence operators ("sqrt($a || (do_something(), 9))") or put
parens around it ("sqrt(($a or do_something(), 9))").

-zefram

@p5pRT
Copy link
Author

p5pRT commented Dec 12, 2010

From @druud62

On 2010-12-10 12​:40, Zefram wrote​:

$ perl -lwe '$a=1; print sqrt($a or 4,9)'
Useless use of a constant (4) in void context at -e line 1.
1
$ perl -lwe '$a=0; print sqrt($a or 4,9)'
Useless use of a constant (4) in void context at -e line 1.
3
$ perl -lwe 'print sqrt(1 or 4,9)'
1
$ perl -lwe 'print sqrt(0 or 4,9)'
Too many arguments for sqrt at -e line 1, near "9)
"
Execution of -e aborted due to compilation errors.

For this issue class, I propose the name Wittgenbug.

--
Ruud

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