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

B::Deparse changes 1 == 1 to 1 in when #10401

Open
p5pRT opened this issue May 23, 2010 · 5 comments
Open

B::Deparse changes 1 == 1 to 1 in when #10401

p5pRT opened this issue May 23, 2010 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented May 23, 2010

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

Searchable as RT75288$

@p5pRT
Copy link
Author

p5pRT commented May 23, 2010

From @briandfoy

Created by brian@mac-pro.local

I found a case where B​::Deparse does the wrong thing. In this foreach-when,
the 1 == 1 is always true and that block always runs. This is the
documented behavior, and there is an output line for every input number​:

  use 5.010;
 
  my $a = 1;
  foreach( 1 .. 10 )
  {
  when( 1 == 1 ) {
  print "Always true. \$_ is $_\n";
  }
  }

This is the result of deparsing on both 5.10.1 through 5.13.1. The 1 == 1 comes
back as just 1, so now a smart match takes place. Only the first input
number triggers the when()​:

  sub BEGIN {
  require 5.01;
  }
  BEGIN {
  $^H{'feature_say'} = q(1);
  $^H{'feature_state'} = q(1);
  $^H{'feature_switch'} = q(1);
  }
  my $a = 1;
  foreach $_ (1 .. 10) {
  when (1) {
  print "Always true. \$_ is $_\n";
  }
  }

Perl Info

Flags:
    category=library
    severity=low
    module=B::Deparse

Site configuration information for perl 5.10.1:

Configured by brian at Sat Dec  5 14:57:53 CST 2009.

Summary of my perl5 (revision 5 version 10 subversion 1) configuration:

  Platform:
    osname=darwin, osvers=10.2.0, archname=darwin-2level
    uname='darwin mac-pro.local 10.2.0 darwin kernel version 10.2.0:
tue nov 3 23:08:29 pst 2009; root:xnu-1486.2.11~3release_i386 i386
i386 '
    config_args='-des -Dprefix=/usr/local/perls/perl-5.10.1'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-common -DPERL_DARWIN -no-cpp-precomp
-fno-strict-aliasing -pipe -fstack-protector',
    optimize='-O3',
    cppflags='-no-cpp-precomp -fno-common -DPERL_DARWIN
-no-cpp-precomp -fno-strict-aliasing -pipe -fstack-protector'
    ccversion='', gccversion='4.2.1 (Apple Inc. build 5646)', 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='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -fstack-protector'
    libpth=/usr/lib
    libs=-ldbm -ldl -lm -lutil -lc
    perllibs=-ldl -lm -lutil -lc
    libc=/usr/lib/libc.dylib, so=dylib, useshrplib=false, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup
-fstack-protector'

Locally applied patches:



@INC for perl 5.10.1:
    /usr/local/perls/perl-5.10.1/lib/5.10.1/darwin-2level
    /usr/local/perls/perl-5.10.1/lib/5.10.1
    /usr/local/perls/perl-5.10.1/lib/site_perl/5.10.1/darwin-2level
    /usr/local/perls/perl-5.10.1/lib/site_perl/5.10.1
    .


Environment for perl 5.10.1:
    DYLD_LIBRARY_PATH (unset)
    HOME=/Users/brian
    LANG=en_US
    LANGUAGE (unset)
    LC_ALL=C
    LC_COLLATE=en_US.utf-8
    LC_CTYPE=en_US.utf-8
    LC_MESSAGES=en_US.utf-8
    LC_MONETARY=en_US.utf-8
    LC_NUMERIC=en_US.utf-8
    LC_TIME=en_US.utf-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/Users/brian/bin:/usr/local/bin:/opt/local/bin:/Users/brian/TPR/scripts:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/mysql/bin:/usr/X11R6/bin:/usr/local/teTeX/bin/powerpc-apple-darwin-current:/usr/local/pgsql/bin:/usr/local/gcj/bin:/Library/Frameworks/Python.framework/Versions/Current/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented May 25, 2010

From @rgarcia

On 23 May 2010 09​:04, brian d foy <perlbug-followup@​perl.org> wrote​:

I found a case where B​::Deparse does the wrong thing. In this foreach-when,
the 1 == 1 is always true and that block always runs. This is the
documented behavior, and there is an output line for every input number​:

       use 5.010;

       my $a = 1;
       foreach( 1 .. 10 )
               {
               when( 1 == 1 ) {
                       print "Always true. \$_ is $_\n";
                       }
               }

This is the result of deparsing on both 5.10.1 through 5.13.1. The 1 == 1 comes
back as just 1, so now a smart match takes place. Only the first input
number triggers the when()​:

       sub BEGIN {
               require 5.01;
       }
       BEGIN {
               $^H{'feature_say'} = q(1);
               $^H{'feature_state'} = q(1);
               $^H{'feature_switch'} = q(1);
       }
       my $a = 1;
       foreach $_ (1 .. 10) {
               when (1) {
                       print "Always true. \$_ is $_\n";
               }
       }

The easiest way to fix that (and also the correct one, given what
B​::Deparse is intended to do) is maybe to always explicitly deparse
the smart match : that is, when ($_~~1) instead of when(1); and for
other cases for non-smartmatch-triggerring syntaxes.

@p5pRT
Copy link
Author

p5pRT commented May 25, 2010

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

@p5pRT
Copy link
Author

p5pRT commented May 25, 2010

From zefram@fysh.org

Rafael Garcia-Suarez wrote​:

The easiest way to fix that (and also the correct one, given what
B​::Deparse is intended to do) is maybe to always explicitly deparse
the smart match

That's exactly what *won't* help here. In this case there is no
smartmatch, and the difficulty is to deparse in a way that won't
incorrectly imply a smartmatch.

-zefram

@p5pRT
Copy link
Author

p5pRT commented May 25, 2010

From @rgarcia

On 25 May 2010 12​:02, Zefram <zefram@​fysh.org> wrote​:

Rafael Garcia-Suarez wrote​:

The easiest way to fix that (and also the correct one, given what
B​::Deparse is intended to do) is maybe to always explicitly deparse
the smart match

That's exactly what *won't* help here.  In this case there is no
smartmatch, and the difficulty is to deparse in a way that won't
incorrectly imply a smartmatch.

Yes, it appears that the second half of my sentence was not deparseable either :

and for other cases for non-smartmatch-triggerring syntaxes.

I meant "for other cases" (that is, when there is no ~~ in the op
tree) *output* non-smartmatch-trigerring syntaxes. (which should be
easy, since technically only constant-foldable expressions will cause
a problem)

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