develooper Front page | perl.perl5.porters | Postings from July 2018

[perl #133368] index() optimisation in when clause fails

Thread Next
From:
Joshua
Date:
July 13, 2018 03:30
Subject:
[perl #133368] index() optimisation in when clause fails
Message ID:
rt-4.0.24-4145-1531452267-430.133368-75-0@perl.org
# New Ticket Created by  Joshua 
# Please include the string:  [perl #133368]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=133368 >


Perl 5.28 introduced a index() optimisation when comparing to -1 (or
indirectly, eg. >= 0).

When this optimisation is triggered in a `when` clause, it warns, eg.

    use v5.28;
    use warnings;
    no warnings 'experimental::smartmatch';

    my $s ='foo';

    given ($s) {
        when ( index($s, 'f') > -1 ) { say "Contains 'f'" }
    }

This gives the warning: Argument "foo" isn't numeric in smart match. Due to
the failure it never enters the block. The same problem does not trigger
inside an if clause.

Current work-around is to force numeric evaluation, ie.

    when ( 0 + index($s, 'f') > -1 ) { ... }

This is a regression, issue does not occur under 5.26.

-----------------------------------------------------------------
---
Flags:
    category=core
    severity=low
---
Site configuration information for perl 5.28.0:

Configured by joshua at Tue Jul 10 10:15:19 AEST 2018.

Summary of my perl5 (revision 5 version 28 subversion 0) configuration:

  Platform:
    osname=linux
    osvers=2.6.32-696.23.1.el6.x86_64
    archname=x86_64-linux-multi
    uname='linux spawn 2.6.32-696.23.1.el6.x86_64 #1 smp tue mar 13
22:44:18 utc 2018 x86_64 x86_64 x86_64 gnulinux '
    config_args='-Dprefix=/usr/tools/plenv/versions/5.28.0 -de
-Dversiononly -Duseshrplib -Dusemultiplicity
-Dotherlibdirs=/usr/tools/lib/perl5
-A'eval:scriptdir=/usr/tools/plenv/versions/5.28.0/bin''
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=define
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='cc'
    ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
-D_FORTIFY_SOURCE=2'
    optimize='-O2'
    cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector
-I/usr/local/include'
    ccversion=''
    gccversion='4.4.7 20120313 (Red Hat 4.4.7-18)'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    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 -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib /lib/../lib64 /usr/lib/../lib64 /lib
/lib64 /usr/lib64 /usr/local/lib64
    libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.12.so
    so=so
    useshrplib=true
    libperl=libperl.so
    gnulibc_version='2.12'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E
-Wl,-rpath,/usr/tools/plenv/versions/5.28.0/lib/perl5/5.28.0/x86_64-linux-multi/CORE'
    cccdlflags='-fPIC'
    lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector'

Locally applied patches:
    Devel::PatchPerl 1.52

---
@INC for perl 5.28.0:
    /usr/tools/lib/perl5

/usr/tools/plenv/versions/5.28.0/lib/perl5/site_perl/5.28.0/x86_64-linux-multi
    /usr/tools/plenv/versions/5.28.0/lib/perl5/site_perl/5.28.0
    /usr/tools/plenv/versions/5.28.0/lib/perl5/5.28.0/x86_64-linux-multi
    /usr/tools/plenv/versions/5.28.0/lib/perl5/5.28.0
    /usr/tools/lib/perl5

---
Environment for perl 5.28.0:
    HOME=/home/joshua
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/usr/local/lib
    LOGDIR (unset)

PATH=/usr/tools/plenv/versions/5.28.0/bin:/usr/tools/plenv/libexec:/usr/tools/plenv/plugins/perl-build/bin:/usr/tools/plenv/plugins/plenv-update/bin:/usr/tools/luaenv/shims:/usr/tools/luaenv/bin:/usr/tools/rbenv/shims:/usr/tools/rbenv/bin:/usr/tools/pyenv/shims:/usr/tools/pyenv/bin:/usr/tools/plenv/shims:/usr/tools/plenv/bin:/usr/tools/perl6/bin:/usr/tools/perl6/share/perl6/site/bin:/usr/tools/smalltalk/bin:/usr/tools/postgres/bin:/usr/tools/tmux/bin:/usr/tools/nim/bin:/usr/tools/vim/bin:/usr/tools/bin:/usr/local/bin:/bin:/usr/bin:/home/joshua/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/joshua/bin
    PERL5LIB=/usr/tools/lib/perl5
    PERLDOC_PAGER=less -+C -E
    PERL_BADLANG (unset)
    SHELL=/bin/zsh


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About