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

Aliasing does not work with closures #15750

Open
p5pRT opened this issue Dec 5, 2016 · 6 comments
Open

Aliasing does not work with closures #15750

p5pRT opened this issue Dec 5, 2016 · 6 comments

Comments

@p5pRT
Copy link

p5pRT commented Dec 5, 2016

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

Searchable as RT130263$

@p5pRT
Copy link
Author

p5pRT commented Dec 5, 2016

From @cpansprout

perlref says​:

B<CAVEAT​:> Aliasing does not work correctly with closures. If you try to
alias lexical variables from an inner subroutine or C<eval>, the aliasing
will only be visible within that inner sub, and will not affect the outer
subroutine where the variables are declared. This bizarre behavior is
subject to change.

Fixing this may require the behaviour to change incompatibly, so it really should block the end of the feature’s experimental parole.


Flags​:
  category=core
  severity=low


Site configuration information for perl 5.25.5​:

Configured by sprout at Sun Sep 4 14​:05​:06 PDT 2016.

Summary of my perl5 (revision 5 version 25 subversion 5) configuration​:
  Derived from​: 63b4aac7809db0ef4bfda7d78ee6f3ff9a210238
  Platform​:
  osname=darwin
  osvers=12.5.0
  archname=darwin-2level
  uname='darwin pint.local 12.5.0 darwin kernel version 12.5.0​: sun sep 29 13​:33​:47 pdt 2013; root​:xnu-2050.48.12~1release_x86_64 x86_64 '
  config_args='-DDEBUGGING -de -Accflags=-DPERL_BOOL_AS_CHAR -Dusedevel -Aoptimize=-O0'
  hint=recommended
  useposix=true
  d_sigaction=define
  useithreads=undef
  usemultiplicity=undef
  use64bitint=define
  use64bitall=define
  uselongdouble=undef
  usemymalloc=n
  bincompat5005=undef
  Compiler​:
  cc='cc'
  ccflags ='-fno-common -DPERL_DARWIN -mmacosx-version-min=10.8 -DPERL_BOOL_AS_CHAR -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -DPERL_USE_SAFE_PUTENV'
  optimize='-O3 -O0 -g'
  cppflags='-fno-common -DPERL_DARWIN -mmacosx-version-min=10.8 -DPERL_BOOL_AS_CHAR -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
  ccversion=''
  gccversion='4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.27)'
  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 =' -mmacosx-version-min=10.8 -fstack-protector -L/usr/local/lib'
  libpth=/usr/local/lib /usr/bin/../lib/clang/4.2/lib /usr/lib
  libs=-lpthread -ldbm -ldl -lm -lutil -lc
  perllibs=-lpthread -ldl -lm -lutil -lc
  libc=
  so=dylib
  useshrplib=false
  libperl=libperl.a
  gnulibc_version=''
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs
  dlext=bundle
  d_dlsymun=undef
  ccdlflags=' '
  cccdlflags=' '
  lddlflags=' -mmacosx-version-min=10.8 -bundle -undefined dynamic_lookup -L/usr/local/lib -fstack-protector'

Locally applied patches​:
  uncommitted-changes


@​INC for perl 5.25.5​:
  lib
  /usr/local/lib/perl5/site_perl/5.25.5/darwin-2level
  /usr/local/lib/perl5/site_perl/5.25.5
  /usr/local/lib/perl5/5.25.5/darwin-2level
  /usr/local/lib/perl5/5.25.5
  /usr/local/lib/perl5/site_perl


Environment for perl 5.25.5​:
  DYLD_LIBRARY_PATH (unset)
  HOME=/Users/sprout
  LANG=en_US.UTF-8
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=/usr/bin​:/bin​:/usr/sbin​:/sbin​:/usr/local/bin​:/usr/local/bin
  PERL_BADLANG (unset)
  SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Dec 6, 2016

From @davidnicol

On Sun, Dec 4, 2016 at 7​:16 PM, Father Chrysostomos
<perlbug-followup@​perl.org> wrote​:

perlref says​:

B<CAVEAT​:> Aliasing does not work correctly with closures. If you try to
alias lexical variables from an inner subroutine or C<eval>, the aliasing
will only be visible within that inner sub, and will not affect the outer
subroutine where the variables are declared. This bizarre behavior is
subject to change.

Fixing this may require the behaviour to change incompatibly, so it really should block the end of the feature’s experimental parole.

Is there no workaround like the local named subroutine workaround
suggested in that page?

$ perl -lE 'use feature 'refaliasing';my $x=33;my $y=44; sub A{ \$y =
\$x; print $y } A; print $y'
Aliasing via reference is experimental at -e line 1.
33
44

What would it break if this was to get fixed? $y is not declared
within A, but it gets its own dictionary of lexical variable names --
if inner scopes used the outer dictionaries, but only when aliasing,
would that be possible? What all would break if Perl's treatment of
inner lexicals was more like Javascript's, and no pad entry -- or some
kind of "passthrough" pad entry -- was made when lexical variable
names get declared?

--
"Teaching radical novelties is our main safeguard against
dictatorships" -- Edsger W. Dijkstra

@p5pRT
Copy link
Author

p5pRT commented Dec 6, 2016

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

@p5pRT
Copy link
Author

p5pRT commented Dec 13, 2017

From @djerius

Created by @djerius

A reference alias is not visible in a lexical subroutine defined
in the same scope.

Here's some sample code​:

use 5.010;

use strict;
use warnings;

use feature 'refaliasing';
use feature 'lexical_subs';
use Data​::Dumper;

sub foo {
  \my @​a = [ 1, 2, 3, 4 ];
  say Dumper \@​a;

  # this works as expected
  sub { say Dumper \@​a }->();

  # this doesn't work as expected
  my sub foo2 { say Dumper \@​a };
  foo2;
}

foo;

And the output​:

Aliasing via reference is experimental at tt.pl line 11.
$VAR1 = [
  1,
  2,
  3,
  4
  ];

$VAR1 = [
  1,
  2,
  3,
  4
  ];

$VAR1 = [];

Thanks!
Diab

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl 5.26.1:

Configured by dj at Mon Sep 25 11:01:28 EDT 2017.

Summary of my perl5 (revision 5 version 26 subversion 1) configuration:
   
  Platform:
    osname=linux
    osvers=4.9.0-3-amd64
    archname=x86_64-linux
    uname='linux macabre 4.9.0-3-amd64 #1 smp debian 4.9.30-2+deb9u3 (2017-08-06) x86_64 gnulinux '
    config_args='-Dprefix=/home/dj/.plenv/versions/5.26.1-x86_64-linux_debian-9 -de -Dusedevel -A'eval:scriptdir=/home/dj/.plenv/versions/5.26.1-x86_64-linux_debian-9/bin''
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    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-strong -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-strong -I/usr/local/include'
    ccversion=''
    gccversion='6.3.0 20170516'
    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/6/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 -lgdbm -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.24.so
    so=so
    useshrplib=false
    libperl=libperl.a
    gnulibc_version='2.24'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector-strong'

Locally applied patches:
    Devel::PatchPerl 1.40


@INC for perl 5.26.1:
    /proj/axaf/simul/lib/perl5
    /home/dj/lib/perl5
    /home/dj/research/lib/perl5
    /home/dj/.plenv/versions/5.26.1-x86_64-linux_debian-9/lib/perl5/site_perl/5.26.1/x86_64-linux
    /home/dj/.plenv/versions/5.26.1-x86_64-linux_debian-9/lib/perl5/site_perl/5.26.1
    /home/dj/.plenv/versions/5.26.1-x86_64-linux_debian-9/lib/perl5/5.26.1/x86_64-linux
    /home/dj/.plenv/versions/5.26.1-x86_64-linux_debian-9/lib/perl5/5.26.1


Environment for perl 5.26.1:
    HOME=/home/dj
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/soft/SYBASE15.7/DataAccess64/ODBC/lib:/soft/SYBASE15.7/DataAccess/ODBC/lib:/soft/SYBASE15.7/OCS-15_0/lib:/soft/SYBASE15.7/OCS-15_0/lib3p64:/soft/SYBASE15.7/OCS-15_0/lib3p:
    LOGDIR (unset)
    PATH=/home/dj/.plenv/versions/5.26.1-x86_64-linux_debian-9/bin:/home/dj/.plenv/libexec:/home/dj/.plenv/plugins/link-axaf/bin:/home/dj/.plenv/plugins/perl-build/bin:/home/dj/.plenv/plugins/plenv-contrib/bin:/soft/SYBASE15.7/OCS-15_0/bin:/home/dj/.rbenv/shims:/home/dj/.rbenv/bin:/home/dj/.pyenv/plugins/pyenv-virtualenv/shims:/home/dj/.pyenv/shims:/home/dj/.pyenv/bin:/home/dj/.plenv/shims:/home/dj/.plenv/bin:/home/dj/root/bin:/home/dj/root/bin/hosts:/home/dj/research/bin:/proj/axaf/ots/pkgs/perl-5.22/x86_64-linux_debian-9/bin:/proj/axaf/bin:/proj/axaf/simul/bin:/proj/axaf/simul/x86_64-linux_debian-9/bin:/proj/axaf/ots/x86_64-linux_debian-9/bin:/proj/axaf/ots/bin:/usr/local/bin:/usr/sbin:/bin:/usr/bin:/soft/saord/bin
    PERL5LIB=/proj/axaf/simul/lib/perl5:/home/dj/lib/perl5:/home/dj/research/lib/perl5
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Dec 13, 2017

From zefram@fysh.org

Diab Jerius wrote​:

A reference alias is not visible in a lexical subroutine defined
in the same scope.

That's true, and this is a duplicate of [perl #130263].

-zefram

@p5pRT
Copy link
Author

p5pRT commented Dec 13, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants