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

lvalue return broken in signature #16161

Closed
p5pRT opened this issue Sep 21, 2017 · 5 comments
Closed

lvalue return broken in signature #16161

p5pRT opened this issue Sep 21, 2017 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Sep 21, 2017

Migrated from rt.perl.org#132141 (status was 'resolved')

Searchable as RT132141$

@p5pRT
Copy link
Author

p5pRT commented Sep 21, 2017

From zefram@fysh.org

Created by zefram@fysh.org

Mixing signatures with lvalue subs​:

$ perl5.26.0 -Mexperimental=signatures -lwe 'our @​a = qw(wibble wobble wabble); sub foo ($i = return substr($a[0], -1, 1)) :lvalue { return substr($a[$i], 1, 1); } print "@​a"; foo(2) = "u"; print "@​a"; foo() = "y"; print "@​a"'
wibble wobble wabble
wibble wobble wubble
Can't return a temporary from lvalue subroutine at -e line 1.

Observe that returning a substr() lvalue works fine in the main block of
the subroutine body, but it fails when done from a default expression
in the signature. Returning from inside the signature is legal, and
works fine for non-lvalue subs.

The cause is that the substr op gets a flag set at compile time to
indicate whether it needs to yield an lvalue, and when it's the child of
a return op that flag gets set depending on the CvLVALUE flag, and with
attributes being in their present grammatical location that flag doesn't
get set early enough to affect compilation of code in the signature.
The equivalent code works just fine on the original version of signatures​:

$ perl5.20.0 -Mexperimental=signatures -lwe 'our @​a = qw(wibble wobble wabble); sub foo :lvalue ($i = return substr($a[0], -1, 1)) { return substr($a[$i], 1, 1); } print "@​a"; foo(2) = "u"; print "@​a"; foo() = "y"; print "@​a"'
wibble wobble wabble
wibble wobble wubble
wibbly wobble wubble

There are also other ops affected by lvalueness, which will be broken
in much the same way. At a quick look, I think the other built-in
attributes don't affect anything in this manner, but I'm not entirely
sure. Non-built-in attributes aren't applied to a sub early enough for
this ordering issue to matter. Of some relevance, last year when we were
discussing the possibilities for suppressing @​_ where arguments are being
accessed in better ways, I suggested using an attribute to control it
and processing attributes earlier to let @​_ uses be compile-time errors,
but then observed that the grammatical swap breaks that plan. See
<https://www.nntp.perl.org/group/perl.perl5.porters/2016/04/msg235925.html>.

Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl 5.26.0:

Configured by zefram at Thu Jun  1 13:52:05 BST 2017.

Summary of my perl5 (revision 5 version 26 subversion 0) configuration:
   
  Platform:
    osname=linux
    osvers=3.16.0-4-amd64
    archname=x86_64-linux-thread-multi
    uname='linux barba.rous.org 3.16.0-4-amd64 #1 smp debian 3.16.7-ckt11-1+deb8u6 (2015-11-09) x86_64 gnulinux '
    config_args='-des -Dprefix=/home/zefram/usr/perl/perl_install/perl-5.26.0-i64-f52 -Duselargefiles -Dusethreads -Uafs -Ud_csh -Uusesfio -Uusenm -Duseshrplib -Dusedevel -Uversiononly -Ui_db'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=define
    usemultiplicity=define
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='cc'
    ccflags ='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2'
    optimize='-O2'
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='4.9.2'
    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-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/4.9/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib
    libs=-lpthread -lnsl -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.19.so
    so=so
    useshrplib=true
    libperl=libperl.so
    gnulibc_version='2.19'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E -Wl,-rpath,/home/zefram/usr/perl/perl_install/perl-5.26.0-i64-f52/lib/5.26.0/x86_64-linux-thread-multi/CORE'
    cccdlflags='-fPIC'
    lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector-strong'



@INC for perl 5.26.0:
    /home/zefram/usr/perl/perl_install/perl-5.26.0-i64-f52/lib/site_perl/5.26.0/x86_64-linux-thread-multi
    /home/zefram/usr/perl/perl_install/perl-5.26.0-i64-f52/lib/site_perl/5.26.0
    /home/zefram/usr/perl/perl_install/perl-5.26.0-i64-f52/lib/5.26.0/x86_64-linux-thread-multi
    /home/zefram/usr/perl/perl_install/perl-5.26.0-i64-f52/lib/5.26.0


Environment for perl 5.26.0:
    HOME=/home/zefram
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/zefram/usr/perl/perl_install/perl-5.26.0-i64-f52/bin:/home/zefram/usr/perl/util:/home/zefram/pub/x86_64-unknown-linux-gnu/bin:/home/zefram/pub/common/bin:/usr/bin:/bin:/usr/local/bin:/usr/games
    PERLDOC=-oman
    PERL_BADLANG (unset)
    SHELL=/usr/bin/zsh

@p5pRT
Copy link
Author

p5pRT commented Jun 5, 2018

@iabyn - Status changed from 'new' to 'resolved'

@p5pRT p5pRT closed this as completed Jun 5, 2018
@p5pRT
Copy link
Author

p5pRT commented Jun 5, 2018

From @iabyn

On Thu, Sep 21, 2017 at 01​:38​:17PM -0700, Zefram wrote​:

Mixing signatures with lvalue subs​:

$ perl5.26.0 -Mexperimental=signatures -lwe 'our @​a = qw(wibble wobble wabble); sub foo ($i = return substr($a[0], -1, 1)) :lvalue { return substr($a[$i], 1, 1); } print "@​a"; foo(2) = "u"; print "@​a"; foo() = "y"; print "@​a"'
wibble wobble wabble
wibble wobble wubble
Can't return a temporary from lvalue subroutine at -e line 1.

Fixed in 5.27.8. Resolving.

--
The Enterprise successfully ferries an alien VIP from one place to another
without serious incident.
  -- Things That Never Happen in "Star Trek" #7

@alanrocker
Copy link

Then the question is "why are they still 'experimental' in 5,30?" Is there anything needed to help with resolution, so that they can become mainstream in 5.32?

@iabyn
Copy link
Contributor

iabyn commented Dec 25, 2019

See the current a big discussion on the p5p mailing list entitled "Jumbo Signatures extensions discussion".

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

3 participants