Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.96k stars 555 forks source link

B::Deparse and constant folding #8080

Closed p5pRT closed 19 years ago

p5pRT commented 19 years ago

Migrated from rt.perl.org#36960 (status was 'rejected')

Searchable as RT36960$

p5pRT commented 19 years ago

From cmeyer@helvella.org

Created by cmeyer@helvella.org

(Sorry if this ends up as a duplicate. I sent it from a machine that is behind a firewall. I got a cc​: copy\, but several hours later\, it is not yet listed in rt.perl.org. I am resending it.)

While playing with constant folding and compiler optimizations\, I noticed something funny about B​::Deparse.

It seems to strip the conditionals off of some statements\, implying that they will always be run. However\, they do not get run.

Here's my test files​:

A.pm​:   package A;   use constant DEBUG => 1;   1;

B.pm​:   package B;   use constant DEBUG => 0;   1;

test.pl​:   #!/usr/local/bin/perl  
  $\="\n";   use lib '.';   use A; # DEBUG == 1   use B; # DEBUG == 0  
  use constant AorB => A​::DEBUG | B​::DEBUG; # 1   use constant AandB => A​::DEBUG & B​::DEBUG; # 0  
  print "A" if A​::DEBUG;   print "B" if B​::DEBUG;   if ( B​::DEBUG ) { print "B" }  
  print "AorB" if AorB;   print "AandB" if AandB;

perl test.pl​:   A   AorB

perl -MO=Deparse test.pl​:

  test syntax OK   $\ = "\n";   use lib ('.');   use A;   use B;   use constant ('AorB'\, 1 | 0);   use constant ('AandB'\, 1 & 0);   print 'A';   print 'B';   do {   print 'B'   };   print 'AorB';   '???';

Thanks for any help\, -Colin.

Perl Info ``` Flags: category=library severity=medium Site configuration information for perl v5.8.7: Configured by cmeyer at Thu Jul 28 15:52:04 PDT 2005. Summary of my perl5 (revision 5 version 8 subversion 7) configuration: Platform: osname=linux, osvers=2.4.21-20.el.c0smp, archname=i686-linux uname='linux dasdev0 2.4.21-20.el.c0smp #1 smp thu sep 9 01:53:25 edt 2004 i686 i686 i386 gnulinux ' config_args='-Dcc=gcc -Dprefix=/opt/perl/5.8.7-mp1 -des' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='gcc', ccflags ='-fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2', cppflags='-fno-strict-aliasing -pipe -I/usr/local/include' ccversion='', gccversion='3.2.3 20030502 (Red Hat Linux 3.2.3-52)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=4, prototype=define Linker and Libraries: ld='gcc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lnsl -ldl -lm -lcrypt -lutil -lc perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc libc=/lib/libc-2.3.2.so, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='2.3.2' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib' Locally applied patches: @INC for perl v5.8.7: /home/cmeyer/perl5lib /home/cmeyer/da/common/lib /home/cmeyer/da/das2/lib /opt/perl/5.8.7-mp1/lib/5.8.7/i686-linux /opt/perl/5.8.7-mp1/lib/5.8.7 /opt/perl/5.8.7-mp1/lib/site_perl/5.8.7/i686-linux /opt/perl/5.8.7-mp1/lib/site_perl/5.8.7 /opt/perl/5.8.7-mp1/lib/site_perl . Environment for perl v5.8.7: HOME=/home/cmeyer LANG=en_US LANGUAGE (unset) LANGVAR=en_US.UTF-8 LD_LIBRARY_PATH=:/opt/oracle/product/9.2.0/lib LOGDIR (unset) PATH=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/sbin:/usr/sbin:/home/cmeyer/bin:/opt/oracle/product/9.2.0/bin:/home/cmeyer/bin PERL=/opt/perl/5.8.7-mp1/bin/perl PERL5LIB=/home/cmeyer/perl5lib:/home/cmeyer/da/common/lib:/home/cmeyer/da/das2/lib PERL_BADLANG (unset) SHELL=/bin/bash ```
p5pRT commented 19 years ago

From rick@bort.ca

On Fri\, Aug 19\, 2005 at 02​:06​:25PM -0700\, Colin Meyer wrote​:

While playing with constant folding and compiler optimizations\, I noticed something funny about B​::Deparse.

It seems to strip the conditionals off of some statements\, implying that they will always be run. However\, they do not get run.

Here's my test files​:

A.pm​: package A; use constant DEBUG => 1; 1;

B.pm​: package B; use constant DEBUG => 0; 1;

This is the problem here. When you run it with -MO=Deparse\, Deparse loads the core B.pm so your B.pm is never loaded. If you change the package name to "J"\, everything works fine.

test.pl​: #!/usr/local/bin/perl

$\="\n"; use lib '.'; use A; # DEBUG == 1 use B; # DEBUG == 0

Try both ways with this addition​:

  BEGIN { warn "B loaded from $INC{'B.pm'}" }

use constant AorB => A​::DEBUG | B​::DEBUG; # 1 use constant AandB => A​::DEBUG & B​::DEBUG; # 0

print "A" if A​::DEBUG; print "B" if B​::DEBUG; if ( B​::DEBUG ) { print "B" }

print "AorB" if AorB; print "AandB" if AandB;

perl test.pl​: A AorB

perl -MO=Deparse test.pl​:

test syntax OK $\ = "\n"; use lib ('.'); use A; use B; use constant ('AorB'\, 1 | 0); use constant ('AandB'\, 1 & 0); print 'A'; print 'B'; do { print 'B' }; print 'AorB'; '???';

-- Rick Delaney rick@​bort.ca

p5pRT commented 19 years ago

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

p5pRT commented 19 years ago

From cmeyer@helvella.org

Thanks for pointing out my silly oversight.

-Colin.

On Sun\, Aug 21\, 2005 at 04​:09​:51PM -0400\, Rick Delaney wrote​:

On Fri\, Aug 19\, 2005 at 02​:06​:25PM -0700\, Colin Meyer wrote​:

While playing with constant folding and compiler optimizations\, I noticed something funny about B​::Deparse.

It seems to strip the conditionals off of some statements\, implying that they will always be run. However\, they do not get run.

Here's my test files​:

A.pm​: package A; use constant DEBUG => 1; 1;

B.pm​: package B; use constant DEBUG => 0; 1;

This is the problem here. When you run it with -MO=Deparse\, Deparse loads the core B.pm so your B.pm is never loaded. If you change the package name to "J"\, everything works fine.

p5pRT commented 19 years ago

From rick@bort.ca

Not a bug\, just an oversight.

p5pRT commented 19 years ago

rick@bort.ca - Status changed from 'open' to 'rejected'